@@ -51,7 +51,7 @@ pub fn targets(manifest: &TomlManifest,
51
51
) ;
52
52
53
53
targets. extend (
54
- clean_benches ( manifest. bench . as_ref ( ) , package_root) ?
54
+ clean_benches ( manifest. bench . as_ref ( ) , package_root, warnings ) ?
55
55
) ;
56
56
57
57
// processing the custom build script
@@ -175,26 +175,23 @@ fn clean_bins(toml_bins: Option<&Vec<TomlBinTarget>>,
175
175
176
176
let mut result = Vec :: new ( ) ;
177
177
for bin in bins. iter ( ) {
178
- let path = match target_path ( bin, & inferred, "bin" , package_root) {
179
- Ok ( path) => path,
180
- Err ( e) => {
181
- if let Some ( legacy_path) = legacy_bin_path ( package_root, & bin. name ( ) , has_lib) {
182
- {
183
- let short_path = without_prefix ( & legacy_path, package_root)
184
- . unwrap_or ( & legacy_path) ;
185
-
186
- warnings. push ( format ! (
187
- "path `{}` was erroneously implicitly accepted for binary {},\n \
188
- please set bin.path in Cargo.toml",
189
- short_path. display( ) , bin. name( )
190
- ) ) ;
191
- }
192
- legacy_path
193
- } else {
194
- return Err ( e) ;
178
+ let path = target_path ( bin, & inferred, "bin" , package_root, & mut |_| {
179
+ if let Some ( legacy_path) = legacy_bin_path ( package_root, & bin. name ( ) , has_lib) {
180
+ {
181
+ let short_path = without_prefix ( & legacy_path, package_root)
182
+ . unwrap_or ( & legacy_path) ;
183
+
184
+ warnings. push ( format ! (
185
+ "path `{}` was erroneously implicitly accepted for binary {},\n \
186
+ please set bin.path in Cargo.toml",
187
+ short_path. display( ) , bin. name( )
188
+ ) ) ;
195
189
}
190
+ Some ( legacy_path)
191
+ } else {
192
+ None
196
193
}
197
- } ;
194
+ } ) ? ;
198
195
199
196
let mut target = Target :: bin_target ( & bin. name ( ) , path,
200
197
bin. required_features . clone ( ) ) ;
@@ -263,10 +260,30 @@ fn clean_tests(toml_tests: Option<&Vec<TomlTestTarget>>,
263
260
}
264
261
265
262
fn clean_benches ( toml_benches : Option < & Vec < TomlBenchTarget > > ,
266
- package_root : & Path ) -> CargoResult < Vec < Target > > {
267
- let targets = clean_targets ( "benchmark" , "bench" ,
268
- toml_benches, inferred_benches ( package_root) ,
269
- package_root) ?;
263
+ package_root : & Path ,
264
+ warnings : & mut Vec < String > ) -> CargoResult < Vec < Target > > {
265
+ let mut legacy_bench_path = |bench : & TomlTarget | {
266
+ let legacy_path = package_root. join ( "src" ) . join ( "bench.rs" ) ;
267
+ if !( bench. name ( ) == "bench" && legacy_path. exists ( ) ) {
268
+ return None ;
269
+ }
270
+ {
271
+ let short_path = without_prefix ( & legacy_path, package_root)
272
+ . unwrap_or ( & legacy_path) ;
273
+
274
+ warnings. push ( format ! (
275
+ "path `{}` was erroneously implicitly accepted for benchmark {},\n \
276
+ please set bench.path in Cargo.toml",
277
+ short_path. display( ) , bench. name( )
278
+ ) ) ;
279
+ }
280
+ Some ( legacy_path)
281
+ } ;
282
+
283
+ let targets = clean_targets_with_legacy_path ( "benchmark" , "bench" ,
284
+ toml_benches, inferred_benches ( package_root) ,
285
+ package_root,
286
+ & mut legacy_bench_path) ?;
270
287
271
288
let mut result = Vec :: new ( ) ;
272
289
for ( path, toml) in targets {
@@ -284,6 +301,19 @@ fn clean_targets(target_kind_human: &str, target_kind: &str,
284
301
inferred : Vec < ( String , PathBuf ) > ,
285
302
package_root : & Path )
286
303
-> CargoResult < Vec < ( PathBuf , TomlTarget ) > > {
304
+ clean_targets_with_legacy_path ( target_kind_human, target_kind,
305
+ toml_targets,
306
+ inferred,
307
+ package_root,
308
+ & mut |_| None )
309
+ }
310
+
311
+ fn clean_targets_with_legacy_path ( target_kind_human : & str , target_kind : & str ,
312
+ toml_targets : Option < & Vec < TomlTarget > > ,
313
+ inferred : Vec < ( String , PathBuf ) > ,
314
+ package_root : & Path ,
315
+ legacy_path : & mut FnMut ( & TomlTarget ) -> Option < PathBuf > )
316
+ -> CargoResult < Vec < ( PathBuf , TomlTarget ) > > {
287
317
let toml_targets = match toml_targets {
288
318
Some ( targets) => targets. clone ( ) ,
289
319
None => inferred. iter ( ) . map ( |& ( ref name, ref path) | {
@@ -302,7 +332,7 @@ fn clean_targets(target_kind_human: &str, target_kind: &str,
302
332
validate_unique_names ( & toml_targets, target_kind) ?;
303
333
let mut result = Vec :: new ( ) ;
304
334
for target in toml_targets {
305
- let path = target_path ( & target, & inferred, target_kind, package_root) ?;
335
+ let path = target_path ( & target, & inferred, target_kind, package_root, legacy_path ) ?;
306
336
result. push ( ( path, target) ) ;
307
337
}
308
338
Ok ( result)
@@ -428,7 +458,8 @@ fn configure(toml: &TomlTarget, target: &mut Target) {
428
458
fn target_path ( target : & TomlTarget ,
429
459
inferred : & [ ( String , PathBuf ) ] ,
430
460
target_kind : & str ,
431
- package_root : & Path ) -> CargoResult < PathBuf > {
461
+ package_root : & Path ,
462
+ legacy_path : & mut FnMut ( & TomlTarget ) -> Option < PathBuf > ) -> CargoResult < PathBuf > {
432
463
if let Some ( ref path) = target. path {
433
464
// Should we verify that this path exists here?
434
465
return Ok ( package_root. join ( & path. 0 ) ) ;
@@ -444,6 +475,10 @@ fn target_path(target: &TomlTarget,
444
475
match ( first, second) {
445
476
( Some ( path) , None ) => Ok ( path) ,
446
477
( None , None ) | ( Some ( _) , Some ( _) ) => {
478
+ if let Some ( path) = legacy_path ( target) {
479
+ return Ok ( path) ;
480
+ }
481
+
447
482
bail ! ( "can't find `{name}` {target_kind}, specify {target_kind}.path" ,
448
483
name = name, target_kind = target_kind)
449
484
}
0 commit comments