@@ -205,6 +205,46 @@ fn clean_specs(
205205 let dir = layout. build_dir ( ) . build_unit ( & pkg. name ( ) ) ;
206206 clean_ctx. rm_rf_glob ( & dir) ?;
207207 }
208+
209+ for target in pkg. targets ( ) {
210+ if target. is_custom_build ( ) {
211+ continue ;
212+ }
213+ for & mode in & [
214+ CompileMode :: Build ,
215+ CompileMode :: Test ,
216+ CompileMode :: Check { test : false } ,
217+ ] {
218+ for ( compile_kind, layout) in & layouts {
219+ let triple = target_data. short_name ( compile_kind) ;
220+ let ( file_types, _unsupported) = target_data
221+ . info ( * compile_kind)
222+ . rustc_outputs ( mode, target. kind ( ) , triple, clean_ctx. gctx ) ?;
223+ let artifact_dir = layout
224+ . artifact_dir ( )
225+ . expect ( "artifact-dir was not locked during clean" ) ;
226+ let uplift_dir = match target. kind ( ) {
227+ TargetKind :: ExampleBin | TargetKind :: ExampleLib ( ..) => {
228+ Some ( artifact_dir. examples ( ) )
229+ }
230+ // Tests/benchmarks are never uplifted.
231+ TargetKind :: Test | TargetKind :: Bench => None ,
232+ _ => Some ( artifact_dir. dest ( ) ) ,
233+ } ;
234+ // Remove the uplifted copy.
235+ if let Some ( uplift_dir) = uplift_dir {
236+ for file_type in file_types {
237+ let uplifted_path =
238+ uplift_dir. join ( file_type. uplift_filename ( target) ) ;
239+ clean_ctx. rm_rf ( & uplifted_path) ?;
240+ // Dep-info generated by Cargo itself.
241+ let dep_info = uplifted_path. with_extension ( "d" ) ;
242+ clean_ctx. rm_rf ( & dep_info) ?;
243+ }
244+ }
245+ }
246+ }
247+ }
208248 continue ;
209249 }
210250
0 commit comments