@@ -958,18 +958,12 @@ fn target_path_not_found_error_message(
958
958
match ( kind, commonly_wrong) {
959
959
// commonly wrong paths
960
960
( "test" | "bench" | "example" , true ) => target_path. push ( kind) ,
961
- ( "bin" , true ) => {
962
- target_path. push ( "src" ) ;
963
- target_path. push ( "bins" ) ;
964
- }
961
+ ( "bin" , true ) => target_path. extend ( [ "src" , "bins" ] ) ,
965
962
// default inferred paths
966
963
( "test" , false ) => target_path. push ( DEFAULT_TEST_DIR_NAME ) ,
967
964
( "bench" , false ) => target_path. push ( DEFAULT_BENCH_DIR_NAME ) ,
968
965
( "example" , false ) => target_path. push ( DEFAULT_EXAMPLE_DIR_NAME ) ,
969
- ( "bin" , false ) => {
970
- target_path. push ( "src" ) ;
971
- target_path. push ( "bin" ) ;
972
- }
966
+ ( "bin" , false ) => target_path. extend ( [ "src" , "bin" ] ) ,
973
967
_ => unreachable ! ( "invalid target kind: {}" , kind) ,
974
968
}
975
969
@@ -988,36 +982,26 @@ fn target_path_not_found_error_message(
988
982
let target_name = name_or_panic ( target) ;
989
983
let commonly_wrong_paths = possible_target_paths ( & target_name, target_kind, true ) ;
990
984
let possible_paths = possible_target_paths ( & target_name, target_kind, false ) ;
991
- let existing_wrong_path_index = match (
992
- package_root. join ( & commonly_wrong_paths[ 0 ] ) . exists ( ) ,
993
- package_root. join ( & commonly_wrong_paths[ 1 ] ) . exists ( ) ,
994
- ) {
995
- ( true , _) => Some ( 0 ) ,
996
- ( _, true ) => Some ( 1 ) ,
997
- _ => None ,
998
- } ;
999
985
1000
- if let Some ( i) = existing_wrong_path_index {
1001
- return format ! (
1002
- "\
1003
- can't find `{name}` {kind} at default paths, but found a file at `{wrong_path}`.
1004
- Perhaps rename the file to `{possible_path}` for target auto-discovery, \
1005
- or specify {kind}.path if you want to use a non-default path.",
1006
- name = target_name,
1007
- kind = target_kind,
1008
- wrong_path = commonly_wrong_paths[ i] . display( ) ,
1009
- possible_path = possible_paths[ i] . display( ) ,
1010
- ) ;
986
+ if let Some ( ( wrong_path, possible_path) ) = commonly_wrong_paths
987
+ . iter ( )
988
+ . zip ( possible_paths. iter ( ) )
989
+ . filter ( |( wp, _) | package_root. join ( wp) . exists ( ) )
990
+ . next ( )
991
+ {
992
+ let [ wrong_path, possible_path] = [ wrong_path, possible_path] . map ( |p| p. display ( ) ) ;
993
+ format ! (
994
+ "can't find `{target_name}` {target_kind} at default paths, but found a file at `{wrong_path}`.\n \
995
+ Perhaps rename the file to `{possible_path}` for target auto-discovery, \
996
+ or specify {target_kind}.path if you want to use a non-default path."
997
+ )
998
+ } else {
999
+ let [ path_file, path_dir] = possible_paths. each_ref ( ) . map ( |p| p. display ( ) ) ;
1000
+ format ! (
1001
+ "can't find `{target_name}` {target_kind} at `{path_file}` or `{path_dir}`. \
1002
+ Please specify {target_kind}.path if you want to use a non-default path."
1003
+ )
1011
1004
}
1012
-
1013
- format ! (
1014
- "can't find `{name}` {kind} at `{path_file}` or `{path_dir}`. \
1015
- Please specify {kind}.path if you want to use a non-default path.",
1016
- name = target_name,
1017
- kind = target_kind,
1018
- path_file = possible_paths[ 0 ] . display( ) ,
1019
- path_dir = possible_paths[ 1 ] . display( ) ,
1020
- )
1021
1005
}
1022
1006
1023
1007
fn target_path (
0 commit comments