@@ -10,6 +10,7 @@ use git2::Config as GitConfig;
1010use term:: color:: BLACK ;
1111
1212use core:: Workspace ;
13+ use ops:: is_bad_artifact_name;
1314use util:: { GitRepo , HgRepo , PijulRepo , CargoResult , human, ChainError , internal} ;
1415use util:: { Config , paths} ;
1516
@@ -115,7 +116,7 @@ fn get_name<'a>(path: &'a Path, opts: &'a NewOptions, config: &Config) -> CargoR
115116 }
116117}
117118
118- fn check_name ( name : & str ) -> CargoResult < ( ) > {
119+ fn check_name ( name : & str , is_bin : bool ) -> CargoResult < ( ) > {
119120
120121 // Ban keywords + test list found at
121122 // https://doc.rust-lang.org/grammar.html#keywords
@@ -130,7 +131,7 @@ fn check_name(name: &str) -> CargoResult<()> {
130131 "super" , "test" , "trait" , "true" , "type" , "typeof" ,
131132 "unsafe" , "unsized" , "use" , "virtual" , "where" ,
132133 "while" , "yield" ] ;
133- if blacklist. contains ( & name) {
134+ if blacklist. contains ( & name) || ( is_bin && is_bad_artifact_name ( name ) ) {
134135 bail ! ( "The name `{}` cannot be used as a crate name\n \
135136 use --name to override crate name",
136137 name)
@@ -274,7 +275,7 @@ pub fn new(opts: NewOptions, config: &Config) -> CargoResult<()> {
274275 }
275276
276277 let name = get_name ( & path, & opts, config) ?;
277- check_name ( name) ?;
278+ check_name ( name, opts . bin ) ?;
278279
279280 let mkopts = MkOptions {
280281 version_control : opts. version_control ,
@@ -303,7 +304,7 @@ pub fn init(opts: NewOptions, config: &Config) -> CargoResult<()> {
303304 }
304305
305306 let name = get_name ( & path, & opts, config) ?;
306- check_name ( name) ?;
307+ check_name ( name, opts . bin ) ?;
307308
308309 let mut src_paths_types = vec ! [ ] ;
309310
0 commit comments