@@ -20,6 +20,7 @@ use toml;
20
20
#[ derive( Clone , Copy , Debug , PartialEq ) ]
21
21
pub enum VersionControl { Git , Hg , Pijul , Fossil , NoVcs }
22
22
23
+ #[ derive( Debug ) ]
23
24
pub struct NewOptions < ' a > {
24
25
pub version_control : Option < VersionControl > ,
25
26
pub bin : bool ,
@@ -118,7 +119,14 @@ fn get_name<'a>(path: &'a Path, opts: &'a NewOptions, config: &Config) -> CargoR
118
119
}
119
120
}
120
121
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
+ } ;
122
130
123
131
// Ban keywords + test list found at
124
132
// https://doc.rust-lang.org/grammar.html#keywords
@@ -133,25 +141,26 @@ fn check_name(name: &str, is_bin: bool) -> CargoResult<()> {
133
141
"super" , "test" , "trait" , "true" , "type" , "typeof" ,
134
142
"unsafe" , "unsized" , "use" , "virtual" , "where" ,
135
143
"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 )
140
148
}
141
149
142
150
if let Some ( ref c) = name. chars ( ) . nth ( 0 ) {
143
151
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 )
146
154
}
147
155
}
148
156
149
157
for c in name. chars ( ) {
150
158
if c. is_alphanumeric ( ) { continue }
151
159
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)
155
164
}
156
165
Ok ( ( ) )
157
166
}
@@ -279,7 +288,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
279
288
}
280
289
281
290
let name = get_name ( & path, opts, config) ?;
282
- check_name ( name, opts. bin ) ?;
291
+ check_name ( name, opts) ?;
283
292
284
293
let mkopts = MkOptions {
285
294
version_control : opts. version_control ,
@@ -309,7 +318,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> {
309
318
}
310
319
311
320
let name = get_name ( & path, opts, config) ?;
312
- check_name ( name, opts. bin ) ?;
321
+ check_name ( name, opts) ?;
313
322
314
323
let mut src_paths_types = vec ! [ ] ;
315
324
0 commit comments