@@ -20,6 +20,7 @@ use toml;
2020#[ derive( Clone , Copy , Debug , PartialEq ) ]
2121pub enum VersionControl { Git , Hg , Pijul , Fossil , NoVcs }
2222
23+ #[ derive( Debug ) ]
2324pub struct NewOptions < ' a > {
2425 pub version_control : Option < VersionControl > ,
2526 pub bin : bool ,
@@ -118,7 +119,14 @@ fn get_name<'a>(path: &'a Path, opts: &'a NewOptions, config: &Config) -> CargoR
118119 }
119120}
120121
121- fn check_name ( name : & str , is_bin : bool ) -> CargoResult < ( ) > {
122+ fn check_name ( name : & str , opts : & NewOptions ) -> CargoResult < ( ) > {
123+
124+ // If --name is already used to override, no point in suggesting it
125+ // again as a fix.
126+ let name_help = match opts. name {
127+ Some ( _) => "" ,
128+ None => "\n use --name to override crate name" ,
129+ } ;
122130
123131 // Ban keywords + test list found at
124132 // https://doc.rust-lang.org/grammar.html#keywords
@@ -133,25 +141,26 @@ fn check_name(name: &str, is_bin: bool) -> CargoResult<()> {
133141 "super" , "test" , "trait" , "true" , "type" , "typeof" ,
134142 "unsafe" , "unsized" , "use" , "virtual" , "where" ,
135143 "while" , "yield" ] ;
136- if blacklist. contains ( & name) || ( is_bin && is_bad_artifact_name ( name) ) {
137- bail ! ( "The name `{}` cannot be used as a crate name\n \
138- use -- name to override crate name" ,
139- name )
144+ if blacklist. contains ( & name) || ( opts . bin && is_bad_artifact_name ( name) ) {
145+ bail ! ( "The name `{}` cannot be used as a crate name{}" ,
146+ name,
147+ name_help )
140148 }
141149
142150 if let Some ( ref c) = name. chars ( ) . nth ( 0 ) {
143151 if c. is_digit ( 10 ) {
144- bail ! ( "Package names starting with a digit cannot be used as a crate name\n \
145- use --name to override crate name" )
152+ bail ! ( "Package names starting with a digit cannot be used as a crate name{}" ,
153+ name_help )
146154 }
147155 }
148156
149157 for c in name. chars ( ) {
150158 if c. is_alphanumeric ( ) { continue }
151159 if c == '_' || c == '-' { continue }
152- bail ! ( "Invalid character `{}` in crate name: `{}`\n \
153- use --name to override crate name",
154- c, name)
160+ bail ! ( "Invalid character `{}` in crate name: `{}`{}" ,
161+ c,
162+ name,
163+ name_help)
155164 }
156165 Ok ( ( ) )
157166}
@@ -279,7 +288,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
279288 }
280289
281290 let name = get_name ( & path, opts, config) ?;
282- check_name ( name, opts. bin ) ?;
291+ check_name ( name, opts) ?;
283292
284293 let mkopts = MkOptions {
285294 version_control : opts. version_control ,
@@ -309,7 +318,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> {
309318 }
310319
311320 let name = get_name ( & path, opts, config) ?;
312- check_name ( name, opts. bin ) ?;
321+ check_name ( name, opts) ?;
313322
314323 let mut src_paths_types = vec ! [ ] ;
315324
0 commit comments