1
1
use crate :: core:: compiler:: { CompileKind , CompileMode , Layout , RustcTargetData } ;
2
2
use crate :: core:: profiles:: Profiles ;
3
- use crate :: core:: { InternedString , PackageIdSpec , Workspace } ;
3
+ use crate :: core:: { InternedString , PackageIdSpec , TargetKind , Workspace } ;
4
4
use crate :: ops;
5
5
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
6
6
use crate :: util:: paths;
@@ -147,10 +147,13 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
147
147
let ( file_types, _unsupported) = target_data
148
148
. info ( * compile_kind)
149
149
. rustc_outputs ( mode, target. kind ( ) , triple) ?;
150
- let ( dir, uplift_dir) = if target. is_example ( ) {
151
- ( layout. examples ( ) , layout. examples ( ) )
152
- } else {
153
- ( layout. deps ( ) , layout. dest ( ) )
150
+ let ( dir, uplift_dir) = match target. kind ( ) {
151
+ TargetKind :: ExampleBin | TargetKind :: ExampleLib ( ..) => {
152
+ ( layout. examples ( ) , Some ( layout. examples ( ) ) )
153
+ }
154
+ // Tests/benchmarks are never uplifted.
155
+ TargetKind :: Test | TargetKind :: Bench => ( layout. deps ( ) , None ) ,
156
+ _ => ( layout. deps ( ) , Some ( layout. dest ( ) ) ) ,
154
157
} ;
155
158
for file_type in file_types {
156
159
// Some files include a hash in the filename, some don't.
@@ -166,11 +169,13 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
166
169
rm_rf ( & unhashed_dep_info, config) ?;
167
170
168
171
// Remove the uplifted copy.
169
- let uplifted_path = uplift_dir. join ( file_type. uplift_filename ( target) ) ;
170
- rm_rf ( & uplifted_path, config) ?;
171
- // Dep-info generated by Cargo itself.
172
- let dep_info = uplifted_path. with_extension ( "d" ) ;
173
- rm_rf ( & dep_info, config) ?;
172
+ if let Some ( uplift_dir) = uplift_dir {
173
+ let uplifted_path = uplift_dir. join ( file_type. uplift_filename ( target) ) ;
174
+ rm_rf ( & uplifted_path, config) ?;
175
+ // Dep-info generated by Cargo itself.
176
+ let dep_info = uplifted_path. with_extension ( "d" ) ;
177
+ rm_rf ( & dep_info, config) ?;
178
+ }
174
179
}
175
180
// TODO: what to do about build_script_build?
176
181
let incremental = layout. incremental ( ) . join ( format ! ( "{}-*" , crate_name) ) ;
0 commit comments