@@ -50,7 +50,7 @@ use std::env;
50
50
use std:: fmt;
51
51
use std:: str:: FromStr ;
52
52
53
- use failure:: Error ;
53
+ use failure:: { bail , Error } ;
54
54
use serde:: { Deserialize , Serialize } ;
55
55
56
56
use crate :: util:: errors:: CargoResult ;
@@ -82,7 +82,7 @@ impl FromStr for Edition {
82
82
match s {
83
83
"2015" => Ok ( Edition :: Edition2015 ) ,
84
84
"2018" => Ok ( Edition :: Edition2018 ) ,
85
- s => failure :: bail!(
85
+ s => bail ! (
86
86
"supported edition values are `2015` or `2018`, but `{}` \
87
87
is unknown",
88
88
s
@@ -227,11 +227,11 @@ impl Features {
227
227
fn add ( & mut self , feature : & str , warnings : & mut Vec < String > ) -> CargoResult < ( ) > {
228
228
let ( slot, status) = match self . status ( feature) {
229
229
Some ( p) => p,
230
- None => failure :: bail!( "unknown cargo feature `{}`" , feature) ,
230
+ None => bail ! ( "unknown cargo feature `{}`" , feature) ,
231
231
} ;
232
232
233
233
if * slot {
234
- failure :: bail!( "the cargo feature `{}` has already been activated" , feature) ;
234
+ bail ! ( "the cargo feature `{}` has already been activated" , feature) ;
235
235
}
236
236
237
237
match status {
@@ -244,7 +244,7 @@ impl Features {
244
244
) ;
245
245
warnings. push ( warning) ;
246
246
}
247
- Status :: Unstable if !nightly_features_allowed ( ) => failure :: bail!(
247
+ Status :: Unstable if !nightly_features_allowed ( ) => bail ! (
248
248
"the cargo feature `{}` requires a nightly version of \
249
249
Cargo, but this is the `{}` channel\n \
250
250
{}",
@@ -288,7 +288,7 @@ impl Features {
288
288
) ;
289
289
msg. push_str ( & s) ;
290
290
}
291
- failure :: bail!( "{}" , msg) ;
291
+ bail ! ( "{}" , msg) ;
292
292
}
293
293
}
294
294
@@ -346,7 +346,7 @@ pub struct CliUnstable {
346
346
impl CliUnstable {
347
347
pub fn parse ( & mut self , flags : & [ String ] ) -> CargoResult < ( ) > {
348
348
if !flags. is_empty ( ) && !nightly_features_allowed ( ) {
349
- failure :: bail!(
349
+ bail ! (
350
350
"the `-Z` flag is only accepted on the nightly channel of Cargo, \
351
351
but this is the `{}` channel\n \
352
352
{}",
@@ -365,11 +365,11 @@ impl CliUnstable {
365
365
let k = parts. next ( ) . unwrap ( ) ;
366
366
let v = parts. next ( ) ;
367
367
368
- fn parse_bool ( value : Option < & str > ) -> CargoResult < bool > {
368
+ fn parse_bool ( key : & str , value : Option < & str > ) -> CargoResult < bool > {
369
369
match value {
370
370
None | Some ( "yes" ) => Ok ( true ) ,
371
371
Some ( "no" ) => Ok ( false ) ,
372
- Some ( s) => failure :: bail!( "expected `no` or `yes`, found: {}" , s) ,
372
+ Some ( s) => bail ! ( "flag -Z{} expected `no` or `yes`, found: `{}`" , key , s) ,
373
373
}
374
374
}
375
375
@@ -380,28 +380,36 @@ impl CliUnstable {
380
380
}
381
381
}
382
382
383
+ // Asserts that there is no argument to the flag.
384
+ fn parse_empty ( key : & str , value : Option < & str > ) -> CargoResult < bool > {
385
+ if let Some ( v) = value {
386
+ bail ! ( "flag -Z{} does not take a value, found: `{}`" , key, v) ;
387
+ }
388
+ Ok ( true )
389
+ } ;
390
+
383
391
match k {
384
- "print-im-a-teapot" => self . print_im_a_teapot = parse_bool ( v) ?,
385
- "unstable-options" => self . unstable_options = true ,
386
- "no-index-update" => self . no_index_update = true ,
387
- "avoid-dev-deps" => self . avoid_dev_deps = true ,
388
- "minimal-versions" => self . minimal_versions = true ,
389
- "package-features" => self . package_features = true ,
390
- "advanced-env" => self . advanced_env = true ,
391
- "config-profile" => self . config_profile = true ,
392
- "dual-proc-macros" => self . dual_proc_macros = true ,
392
+ "print-im-a-teapot" => self . print_im_a_teapot = parse_bool ( k , v) ?,
393
+ "unstable-options" => self . unstable_options = parse_empty ( k , v ) ? ,
394
+ "no-index-update" => self . no_index_update = parse_empty ( k , v ) ? ,
395
+ "avoid-dev-deps" => self . avoid_dev_deps = parse_empty ( k , v ) ? ,
396
+ "minimal-versions" => self . minimal_versions = parse_empty ( k , v ) ? ,
397
+ "package-features" => self . package_features = parse_empty ( k , v ) ? ,
398
+ "advanced-env" => self . advanced_env = parse_empty ( k , v ) ? ,
399
+ "config-profile" => self . config_profile = parse_empty ( k , v ) ? ,
400
+ "dual-proc-macros" => self . dual_proc_macros = parse_empty ( k , v ) ? ,
393
401
// can also be set in .cargo/config or with and ENV
394
- "mtime-on-use" => self . mtime_on_use = true ,
395
- "install-upgrade" => self . install_upgrade = true ,
396
- "named-profiles" => self . named_profiles = true ,
397
- "binary-dep-depinfo" => self . binary_dep_depinfo = true ,
402
+ "mtime-on-use" => self . mtime_on_use = parse_empty ( k , v ) ? ,
403
+ "install-upgrade" => self . install_upgrade = parse_empty ( k , v ) ? ,
404
+ "named-profiles" => self . named_profiles = parse_empty ( k , v ) ? ,
405
+ "binary-dep-depinfo" => self . binary_dep_depinfo = parse_empty ( k , v ) ? ,
398
406
"build-std" => {
399
407
self . build_std = Some ( crate :: core:: compiler:: standard_lib:: parse_unstable_flag ( v) )
400
408
}
401
409
"timings" => self . timings = Some ( parse_timings ( v) ) ,
402
- "doctest-xcompile" => self . doctest_xcompile = true ,
403
- "panic-abort-tests" => self . panic_abort_tests = true ,
404
- _ => failure :: bail!( "unknown `-Z` flag specified: {}" , k) ,
410
+ "doctest-xcompile" => self . doctest_xcompile = parse_empty ( k , v ) ? ,
411
+ "panic-abort-tests" => self . panic_abort_tests = parse_empty ( k , v ) ? ,
412
+ _ => bail ! ( "unknown `-Z` flag specified: {}" , k) ,
405
413
}
406
414
407
415
Ok ( ( ) )
@@ -418,14 +426,14 @@ impl CliUnstable {
418
426
issue, flag
419
427
) ;
420
428
if nightly_features_allowed ( ) {
421
- failure :: bail!(
429
+ bail ! (
422
430
"the `{}` flag is unstable, pass `-Z unstable-options` to enable it\n \
423
431
{}",
424
432
flag,
425
433
see
426
434
) ;
427
435
} else {
428
- failure :: bail!(
436
+ bail ! (
429
437
"the `{}` flag is unstable, and only available on the nightly channel \
430
438
of Cargo, but this is the `{}` channel\n \
431
439
{}\n \
0 commit comments