From 54c42142517cfe5b29e8d155fa40a6525d0abd54 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 12 Dec 2018 21:20:44 +0000 Subject: [PATCH] Remove trailing extern crate usage --- src/bin/cargo/commands/bench.rs | 2 +- src/bin/cargo/commands/build.rs | 2 +- src/bin/cargo/commands/check.rs | 2 +- src/bin/cargo/commands/fix.rs | 2 +- src/bin/cargo/commands/locate_project.rs | 2 +- src/bin/cargo/commands/login.rs | 2 +- src/bin/cargo/commands/rustc.rs | 2 +- src/bin/cargo/commands/test.rs | 4 +- src/bin/cargo/main.rs | 7 +-- src/cargo/core/compiler/build_config.rs | 12 ++-- src/cargo/core/compiler/build_context/mod.rs | 2 +- .../compiler/build_context/target_info.rs | 6 +- src/cargo/core/compiler/build_plan.rs | 6 +- src/cargo/core/compiler/compilation.rs | 2 +- .../compiler/context/compilation_files.rs | 4 +- src/cargo/core/compiler/context/mod.rs | 6 +- src/cargo/core/compiler/custom_build.rs | 12 ++-- src/cargo/core/compiler/fingerprint.rs | 30 +++++----- src/cargo/core/compiler/job_queue.rs | 2 +- src/cargo/core/compiler/layout.rs | 2 +- src/cargo/core/dependency.rs | 7 +-- src/cargo/core/features.rs | 16 ++--- src/cargo/core/manifest.rs | 4 +- src/cargo/core/package.rs | 4 +- src/cargo/core/package_id_spec.rs | 14 ++--- src/cargo/core/profiles.rs | 8 ++- src/cargo/core/registry.rs | 20 +++---- src/cargo/core/resolver/context.rs | 14 +++-- src/cargo/core/resolver/encode.rs | 4 +- src/cargo/core/resolver/errors.rs | 4 +- src/cargo/core/resolver/mod.rs | 4 +- src/cargo/core/resolver/resolve.rs | 8 +-- src/cargo/core/resolver/types.rs | 6 +- src/cargo/core/shell.rs | 4 +- src/cargo/core/source/source_id.rs | 7 ++- src/cargo/core/summary.rs | 22 +++---- src/cargo/core/workspace.rs | 32 +++++----- src/cargo/lib.rs | 6 +- src/cargo/ops/cargo_clean.rs | 5 +- src/cargo/ops/cargo_compile.rs | 28 +++++---- src/cargo/ops/cargo_doc.rs | 6 +- src/cargo/ops/cargo_generate_lockfile.rs | 6 +- src/cargo/ops/cargo_install.rs | 59 +++++++++--------- src/cargo/ops/cargo_new.rs | 30 +++++----- src/cargo/ops/cargo_output_metadata.rs | 2 +- src/cargo/ops/cargo_package.rs | 16 ++--- src/cargo/ops/cargo_pkgid.rs | 2 +- src/cargo/ops/cargo_read_manifest.rs | 4 +- src/cargo/ops/cargo_run.rs | 10 ++-- src/cargo/ops/fix.rs | 4 +- src/cargo/ops/lockfile.rs | 4 +- src/cargo/ops/registry.rs | 26 ++++---- src/cargo/ops/resolve.rs | 4 +- src/cargo/sources/config.rs | 12 ++-- src/cargo/sources/directory.rs | 6 +- src/cargo/sources/git/source.rs | 4 +- src/cargo/sources/git/utils.rs | 6 +- src/cargo/sources/path.rs | 12 ++-- src/cargo/sources/registry/index.rs | 2 +- src/cargo/sources/registry/local.rs | 6 +- src/cargo/sources/registry/mod.rs | 2 +- src/cargo/sources/registry/remote.rs | 4 +- src/cargo/util/cfg.rs | 24 ++++---- src/cargo/util/command_prelude.rs | 8 +-- src/cargo/util/config.rs | 32 +++++----- src/cargo/util/errors.rs | 2 +- src/cargo/util/important_paths.rs | 4 +- src/cargo/util/paths.rs | 18 ++++-- src/cargo/util/process_builder.rs | 4 +- src/cargo/util/rustc.rs | 2 +- src/cargo/util/sha256.rs | 2 +- src/cargo/util/to_semver.rs | 2 +- src/cargo/util/to_url.rs | 5 +- src/cargo/util/toml/mod.rs | 60 +++++++++---------- src/cargo/util/toml/targets.rs | 26 ++++---- src/crates-io/Cargo.toml | 2 +- src/crates-io/lib.rs | 10 +--- tests/testsuite/support/mod.rs | 2 +- 78 files changed, 389 insertions(+), 367 deletions(-) diff --git a/src/bin/cargo/commands/bench.rs b/src/bin/cargo/commands/bench.rs index f55689c0bd3..087510e2555 100644 --- a/src/bin/cargo/commands/bench.rs +++ b/src/bin/cargo/commands/bench.rs @@ -97,7 +97,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { match err { None => Ok(()), Some(err) => Err(match err.exit.as_ref().and_then(|e| e.code()) { - Some(i) => CliError::new(format_err!("bench failed"), i), + Some(i) => CliError::new(failure::format_err!("bench failed"), i), None => CliError::new(err.into(), 101), }), } diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index 437dbe5e08d..fa2605070b0 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -51,7 +51,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Build)?; compile_opts.export_dir = args.value_of_path("out-dir", config); if compile_opts.export_dir.is_some() && !config.cli_unstable().unstable_options { - Err(format_err!( + Err(failure::format_err!( "`--out-dir` flag is unstable, pass `-Z unstable-options` to enable it" ))?; }; diff --git a/src/bin/cargo/commands/check.rs b/src/bin/cargo/commands/check.rs index 261d503f95c..33d92796670 100644 --- a/src/bin/cargo/commands/check.rs +++ b/src/bin/cargo/commands/check.rs @@ -59,7 +59,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { Some("test") => true, None => false, Some(profile) => { - let err = format_err!( + let err = failure::format_err!( "unknown profile: `{}`, only `test` is \ currently supported", profile diff --git a/src/bin/cargo/commands/fix.rs b/src/bin/cargo/commands/fix.rs index e2fc23e1879..9b58c22b04c 100644 --- a/src/bin/cargo/commands/fix.rs +++ b/src/bin/cargo/commands/fix.rs @@ -110,7 +110,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { Some("test") => true, None => false, Some(profile) => { - let err = format_err!( + let err = failure::format_err!( "unknown profile: `{}`, only `test` is \ currently supported", profile diff --git a/src/bin/cargo/commands/locate_project.rs b/src/bin/cargo/commands/locate_project.rs index 7c562f334b2..8fb1cc60021 100644 --- a/src/bin/cargo/commands/locate_project.rs +++ b/src/bin/cargo/commands/locate_project.rs @@ -20,7 +20,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let root = root .to_str() .ok_or_else(|| { - format_err!( + failure::format_err!( "your package path contains characters \ not representable in Unicode" ) diff --git a/src/bin/cargo/commands/login.rs b/src/bin/cargo/commands/login.rs index fb36c5ad51a..eef05526cfe 100644 --- a/src/bin/cargo/commands/login.rs +++ b/src/bin/cargo/commands/login.rs @@ -26,7 +26,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { None => { let host = match registry { Some(ref _registry) => { - return Err(format_err!( + return Err(failure::format_err!( "token must be provided when \ --registry is provided." ) diff --git a/src/bin/cargo/commands/rustc.rs b/src/bin/cargo/commands/rustc.rs index 53a757650d4..cd959cc559d 100644 --- a/src/bin/cargo/commands/rustc.rs +++ b/src/bin/cargo/commands/rustc.rs @@ -54,7 +54,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { Some("bench") => CompileMode::Bench, Some("check") => CompileMode::Check { test: false }, Some(mode) => { - let err = format_err!( + let err = failure::format_err!( "unknown profile: `{}`, use dev, test, or bench", mode diff --git a/src/bin/cargo/commands/test.rs b/src/bin/cargo/commands/test.rs index 8c1a3751c37..0f1ef69ede2 100644 --- a/src/bin/cargo/commands/test.rs +++ b/src/bin/cargo/commands/test.rs @@ -98,7 +98,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { if doc { if let CompileFilter::Only { .. } = compile_opts.filter { return Err(CliError::new( - format_err!("Can't mix --doc with other target selecting options"), + failure::format_err!("Can't mix --doc with other target selecting options"), 101, )); } @@ -137,7 +137,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { match err { None => Ok(()), Some(err) => Err(match err.exit.as_ref().and_then(|e| e.code()) { - Some(i) => CliError::new(format_err!("{}", err.hint(&ws)), i), + Some(i) => CliError::new(failure::format_err!("{}", err.hint(&ws)), i), None => CliError::new(err.into(), 101), }), } diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index b89016a2d85..d0a18293f6e 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -2,9 +2,6 @@ #![allow(clippy::too_many_arguments)] // large project #![allow(clippy::redundant_closure)] // there's a false positive -#[macro_use] -extern crate failure; - use std::collections::BTreeSet; use std::env; use std::fs; @@ -136,12 +133,12 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli Some(command) => command, None => { let err = match find_closest(config, cmd) { - Some(closest) => format_err!( + Some(closest) => failure::format_err!( "no such subcommand: `{}`\n\n\tDid you mean `{}`?\n", cmd, closest ), - None => format_err!("no such subcommand: `{}`", cmd), + None => failure::format_err!("no such subcommand: `{}`", cmd), }; return Err(CliError::new(err, 101)); } diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index fe0ec016b5f..530890469be 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -48,27 +48,27 @@ impl BuildConfig { ) -> CargoResult { let requested_target = match requested_target { &Some(ref target) if target.ends_with(".json") => { - let path = Path::new(target) - .canonicalize() - .chain_err(|| format_err!("Target path {:?} is not a valid file", target))?; + let path = Path::new(target).canonicalize().chain_err(|| { + failure::format_err!("Target path {:?} is not a valid file", target) + })?; Some( path.into_os_string() .into_string() - .map_err(|_| format_err!("Target path is not valid unicode"))?, + .map_err(|_| failure::format_err!("Target path is not valid unicode"))?, ) } other => other.clone(), }; if let Some(ref s) = requested_target { if s.trim().is_empty() { - bail!("target was empty") + failure::bail!("target was empty") } } let cfg_target = config.get_string("build.target")?.map(|s| s.val); let target = requested_target.or(cfg_target); if jobs == Some(0) { - bail!("jobs must be at least 1") + failure::bail!("jobs must be at least 1") } if jobs.is_some() && config.jobserver_from_env().is_some() { config.shell().warn( diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index c069bfcfef7..03aa4e58514 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -276,7 +276,7 @@ impl TargetConfig { } } "warning" | "rerun-if-changed" | "rerun-if-env-changed" => { - bail!("`{}` is not supported in build script overrides", k); + failure::bail!("`{}` is not supported in build script overrides", k); } _ => { let val = value.string(k)?.0; diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 8fa1b03f32e..0aef86742f3 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -113,7 +113,7 @@ impl TargetInfo { if has_cfg_and_sysroot { let line = match lines.next() { Some(line) => line, - None => bail!( + None => failure::bail!( "output of --print=sysroot missing when learning about \ target-specific information from rustc" ), @@ -270,7 +270,7 @@ fn parse_crate_type( } let line = match lines.next() { Some(line) => line, - None => bail!( + None => failure::bail!( "malformed output when learning about \ crate-type {} information", crate_type @@ -280,7 +280,7 @@ fn parse_crate_type( let prefix = parts.next().unwrap(); let suffix = match parts.next() { Some(part) => part, - None => bail!( + None => failure::bail!( "output of --print=file-names has changed in \ the compiler, cannot parse" ), diff --git a/src/cargo/core/compiler/build_plan.rs b/src/cargo/core/compiler/build_plan.rs index 2cd845cfb6f..d6c79d004be 100644 --- a/src/cargo/core/compiler/build_plan.rs +++ b/src/cargo/core/compiler/build_plan.rs @@ -74,13 +74,13 @@ impl Invocation { self.program = cmd .get_program() .to_str() - .ok_or_else(|| format_err!("unicode program string required"))? + .ok_or_else(|| failure::format_err!("unicode program string required"))? .to_string(); self.cwd = Some(cmd.get_cwd().unwrap().to_path_buf()); for arg in cmd.get_args().iter() { self.args.push( arg.to_str() - .ok_or_else(|| format_err!("unicode argument string required"))? + .ok_or_else(|| failure::format_err!("unicode argument string required"))? .to_string(), ); } @@ -93,7 +93,7 @@ impl Invocation { var.clone(), value .to_str() - .ok_or_else(|| format_err!("unicode environment value required"))? + .ok_or_else(|| failure::format_err!("unicode environment value required"))? .to_string(), ); } diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 62b826b0960..3fc0148bbec 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -276,7 +276,7 @@ fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult CompilationFiles<'a, 'cfg> { } if ret.is_empty() { if !unsupported.is_empty() { - bail!( + failure::bail!( "cannot produce {} for `{}` as the target `{}` \ does not support these crate types", unsupported.join(", "), @@ -349,7 +349,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { bcx.target_triple() ) } - bail!( + failure::bail!( "cannot compile `{}` as the target `{}` does not \ support any of the output crate types", unit.pkg, diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index 9dad3acad5d..8a485db7c5a 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -450,7 +450,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { self.package_cache .get(&id) .cloned() - .ok_or_else(|| format_err!("failed to find {}", id)) + .ok_or_else(|| failure::format_err!("failed to find {}", id)) } /// Return the list of filenames read by cargo to generate the BuildContext @@ -588,7 +588,7 @@ impl Links { dep_path_desc }; - bail!( + failure::bail!( "multiple packages link to native library `{}`, \ but a native library can be linked only once\n\ \n\ @@ -609,7 +609,7 @@ impl Links { .iter() .any(|t| t.is_custom_build()) { - bail!( + failure::bail!( "package `{}` specifies that it links to `{}` but does not \ have a custom build script", unit.pkg.package_id(), diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 892459338f8..9480bf36507 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -339,7 +339,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes cmd.exec_with_output() }; let output = output.map_err(|e| { - format_err!( + failure::format_err!( "failed to run custom build command for `{}`\n{}", pkg_name, e @@ -468,7 +468,7 @@ impl BuildOutput { let (key, value) = match (key, value) { (Some(a), Some(b)) => (a, b.trim_end()), // line started with `cargo:` but didn't match `key=value` - _ => bail!("Wrong output in {}: `{}`", whence, line), + _ => failure::bail!("Wrong output in {}: `{}`", whence, line), }; // This will rewrite paths if the target directory has been moved. @@ -517,7 +517,7 @@ impl BuildOutput { let (mut library_paths, mut library_links) = (Vec::new(), Vec::new()); while let Some(flag) = flags_iter.next() { if flag != "-l" && flag != "-L" { - bail!( + failure::bail!( "Only `-l` and `-L` flags are allowed in {}: `{}`", whence, value @@ -525,7 +525,7 @@ impl BuildOutput { } let value = match flags_iter.next() { Some(v) => v, - None => bail!( + None => failure::bail!( "Flag in rustc-flags has no value in {}: `{}`", whence, value @@ -536,7 +536,7 @@ impl BuildOutput { "-L" => library_paths.push(PathBuf::from(value)), // was already checked above - _ => bail!("only -l and -L flags are allowed"), + _ => failure::bail!("only -l and -L flags are allowed"), }; } Ok((library_paths, library_links)) @@ -548,7 +548,7 @@ impl BuildOutput { let val = iter.next(); match (name, val) { (Some(n), Some(v)) => Ok((n.to_owned(), v.to_owned())), - _ => bail!("Variable rustc-env has no value in {}: {}", whence, value), + _ => failure::bail!("Variable rustc-env has no value in {}: {}", whence, value), } } } diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 8969f9a80bf..c8dd1ebb460 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -259,32 +259,32 @@ impl Fingerprint { fn compare(&self, old: &Fingerprint) -> CargoResult<()> { if self.rustc != old.rustc { - bail!("rust compiler has changed") + failure::bail!("rust compiler has changed") } if self.features != old.features { - bail!( + failure::bail!( "features have changed: {} != {}", self.features, old.features ) } if self.target != old.target { - bail!("target configuration has changed") + failure::bail!("target configuration has changed") } if self.path != old.path { - bail!("path to the compiler has changed") + failure::bail!("path to the compiler has changed") } if self.profile != old.profile { - bail!("profile configuration has changed") + failure::bail!("profile configuration has changed") } if self.rustflags != old.rustflags { - bail!("RUSTFLAGS has changed") + failure::bail!("RUSTFLAGS has changed") } if self.local.len() != old.local.len() { - bail!("local lens changed"); + failure::bail!("local lens changed"); } if self.edition != old.edition { - bail!("edition changed") + failure::bail!("edition changed") } for (new, old) in self.local.iter().zip(&old.local) { match (new, old) { @@ -293,7 +293,7 @@ impl Fingerprint { &LocalFingerprint::Precalculated(ref b), ) => { if a != b { - bail!("precalculated components have changed: {} != {}", a, b) + failure::bail!("precalculated components have changed: {} != {}", a, b) } } ( @@ -310,7 +310,7 @@ impl Fingerprint { }; if should_rebuild { - bail!( + failure::bail!( "mtime based components have changed: previously {:?} now {:?}, \ paths are {:?} and {:?}", *previously_built_mtime, @@ -325,10 +325,10 @@ impl Fingerprint { &LocalFingerprint::EnvBased(ref bkey, ref bvalue), ) => { if *akey != *bkey { - bail!("env vars changed: {} != {}", akey, bkey); + failure::bail!("env vars changed: {} != {}", akey, bkey); } if *avalue != *bvalue { - bail!( + failure::bail!( "env var `{}` changed: previously {:?} now {:?}", akey, bvalue, @@ -336,16 +336,16 @@ impl Fingerprint { ) } } - _ => bail!("local fingerprint type has changed"), + _ => failure::bail!("local fingerprint type has changed"), } } if self.deps.len() != old.deps.len() { - bail!("number of dependencies has changed") + failure::bail!("number of dependencies has changed") } for (a, b) in self.deps.iter().zip(old.deps.iter()) { if a.1 != b.1 || a.2.hash() != b.2.hash() { - bail!("new ({}) != old ({})", a.0, b.0) + failure::bail!("new ({}) != old ({})", a.0, b.0) } } Ok(()) diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 555342c8238..8855cc273d9 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -328,7 +328,7 @@ impl<'a> JobQueue<'a> { self.emit_warnings(Some(msg), &key, cx)?; if !self.active.is_empty() { - error = Some(format_err!("build failed")); + error = Some(failure::format_err!("build failed")); handle_error(&e, &mut *cx.bcx.config.shell()); cx.bcx.config.shell().warn( "build failed, waiting for other \ diff --git a/src/cargo/core/compiler/layout.rs b/src/cargo/core/compiler/layout.rs index 8d13b845a75..7606fefa2b1 100644 --- a/src/cargo/core/compiler/layout.rs +++ b/src/cargo/core/compiler/layout.rs @@ -95,7 +95,7 @@ impl Layout { path.push( triple .file_stem() - .ok_or_else(|| format_err!("invalid target"))?, + .ok_or_else(|| failure::format_err!("invalid target"))?, ); } else { path.push(triple); diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index df652f913d7..262c3753874 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -454,10 +454,9 @@ impl FromStr for Platform { fn from_str(s: &str) -> CargoResult { if s.starts_with("cfg(") && s.ends_with(')') { let s = &s[4..s.len() - 1]; - let p = s - .parse() - .map(Platform::Cfg) - .chain_err(|| format_err!("failed to parse `{}` as a cfg expression", s))?; + let p = s.parse().map(Platform::Cfg).chain_err(|| { + failure::format_err!("failed to parse `{}` as a cfg expression", s) + })?; Ok(p) } else { Ok(Platform::Name(s.to_string())) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index dfe108310e3..ccc6546dc88 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -78,7 +78,7 @@ impl FromStr for Edition { match s { "2015" => Ok(Edition::Edition2015), "2018" => Ok(Edition::Edition2018), - s => bail!( + s => failure::bail!( "supported edition values are `2015` or `2018`, but `{}` \ is unknown", s @@ -216,11 +216,11 @@ impl Features { fn add(&mut self, feature: &str, warnings: &mut Vec) -> CargoResult<()> { let (slot, status) = match self.status(feature) { Some(p) => p, - None => bail!("unknown cargo feature `{}`", feature), + None => failure::bail!("unknown cargo feature `{}`", feature), }; if *slot { - bail!("the cargo feature `{}` has already been activated", feature); + failure::bail!("the cargo feature `{}` has already been activated", feature); } match status { @@ -233,7 +233,7 @@ impl Features { ); warnings.push(warning); } - Status::Unstable if !nightly_features_allowed() => bail!( + Status::Unstable if !nightly_features_allowed() => failure::bail!( "the cargo feature `{}` requires a nightly version of \ Cargo, but this is the `{}` channel", feature, @@ -275,7 +275,7 @@ impl Features { ); msg.push_str(&s); } - bail!("{}", msg); + failure::bail!("{}", msg); } } @@ -325,7 +325,7 @@ pub struct CliUnstable { impl CliUnstable { pub fn parse(&mut self, flags: &[String]) -> CargoResult<()> { if !flags.is_empty() && !nightly_features_allowed() { - bail!("the `-Z` flag is only accepted on the nightly channel of Cargo") + failure::bail!("the `-Z` flag is only accepted on the nightly channel of Cargo") } for flag in flags { self.add(flag)?; @@ -342,7 +342,7 @@ impl CliUnstable { match value { None | Some("yes") => Ok(true), Some("no") => Ok(false), - Some(s) => bail!("expected `no` or `yes`, found: {}", s), + Some(s) => failure::bail!("expected `no` or `yes`, found: {}", s), } } @@ -356,7 +356,7 @@ impl CliUnstable { "package-features" => self.package_features = true, "advanced-env" => self.advanced_env = true, "config-profile" => self.config_profile = true, - _ => bail!("unknown `-Z` flag specified: {}", k), + _ => failure::bail!("unknown `-Z` flag specified: {}", k), } Ok(()) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 051ee1ed1b6..fd3734d351a 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -477,7 +477,7 @@ impl Manifest { self.features .require(Feature::test_dummy_unstable()) .chain_err(|| { - format_err!( + failure::format_err!( "the `im-a-teapot` manifest key is unstable and may \ not work properly in England" ) @@ -487,7 +487,7 @@ impl Manifest { if self.default_run.is_some() { self.features .require(Feature::default_run()) - .chain_err(|| format_err!("the `default-run` manifest key is unstable"))?; + .chain_err(|| failure::format_err!("the `default-run` manifest key is unstable"))?; } Ok(()) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 75917c63aa3..0de5e3cee95 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -426,7 +426,7 @@ macro_rules! try_old_curl { } } else { result.with_context(|_| { - format_err!("failed to enable {}, is curl not built right?", $msg) + failure::format_err!("failed to enable {}, is curl not built right?", $msg) })?; } }; @@ -459,7 +459,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> { .ok_or_else(|| internal(format!("couldn't find source for `{}`", id)))?; let pkg = source .download(id) - .chain_err(|| format_err!("unable to get packages from source"))?; + .chain_err(|| failure::format_err!("unable to get packages from source"))?; let (url, descriptor) = match pkg { MaybePackage::Ready(pkg) => { debug!("{} doesn't need a download", id); diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index afac8403ffb..dcb216f12fe 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -66,7 +66,7 @@ impl PackageIdSpec { }; for ch in name.chars() { if !ch.is_alphanumeric() && ch != '_' && ch != '-' { - bail!("invalid character in pkgid `{}`: `{}`", spec, ch) + failure::bail!("invalid character in pkgid `{}`: `{}`", spec, ch) } } Ok(PackageIdSpec { @@ -82,7 +82,7 @@ impl PackageIdSpec { I: IntoIterator, { let spec = PackageIdSpec::parse(spec) - .chain_err(|| format_err!("invalid package id specification: `{}`", spec))?; + .chain_err(|| failure::format_err!("invalid package id specification: `{}`", spec))?; spec.query(i) } @@ -99,16 +99,16 @@ impl PackageIdSpec { /// Tries to convert a valid `Url` to a `PackageIdSpec`. fn from_url(mut url: Url) -> CargoResult { if url.query().is_some() { - bail!("cannot have a query string in a pkgid: {}", url) + failure::bail!("cannot have a query string in a pkgid: {}", url) } let frag = url.fragment().map(|s| s.to_owned()); url.set_fragment(None); let (name, version) = { let mut path = url .path_segments() - .ok_or_else(|| format_err!("pkgid urls must have a path: {}", url))?; + .ok_or_else(|| failure::format_err!("pkgid urls must have a path: {}", url))?; let path_name = path.next_back().ok_or_else(|| { - format_err!( + failure::format_err!( "pkgid urls must have at least one path \ component: {}", url @@ -186,7 +186,7 @@ impl PackageIdSpec { let mut ids = i.into_iter().filter(|p| self.matches(*p)); let ret = match ids.next() { Some(id) => id, - None => bail!( + None => failure::bail!( "package id specification `{}` \ matched no packages", self @@ -207,7 +207,7 @@ impl PackageIdSpec { let mut vec = vec![ret, other]; vec.extend(ids); minimize(&mut msg, &vec, self); - Err(format_err!("{}", msg)) + Err(failure::format_err!("{}", msg)) } None => Ok(ret), }; diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 1b44d743853..6a4214c90ae 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -231,7 +231,7 @@ impl ProfileMaker { .map(|spec| spec.to_string()) .collect::>() .join(", "); - bail!( + failure::bail!( "multiple profile overrides in profile `{}` match package `{}`\n\ found profile override specs: {}", self.default.name, @@ -643,12 +643,14 @@ impl ConfigProfiles { if let Some(ref profile) = self.dev { profile .validate("dev", features, warnings) - .chain_err(|| format_err!("config profile `profile.dev` is not valid"))?; + .chain_err(|| failure::format_err!("config profile `profile.dev` is not valid"))?; } if let Some(ref profile) = self.release { profile .validate("release", features, warnings) - .chain_err(|| format_err!("config profile `profile.release` is not valid"))?; + .chain_err(|| { + failure::format_err!("config profile `profile.release` is not valid") + })?; } Ok(()) } diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 2e3858f893e..533b4cb0b72 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -221,7 +221,7 @@ impl<'cfg> PackageRegistry<'cfg> { // corresponding to this `dep`. self.ensure_loaded(dep.source_id(), Kind::Normal) .chain_err(|| { - format_err!( + failure::format_err!( "failed to load source for a dependency \ on `{}`", dep.package_name() @@ -237,7 +237,7 @@ impl<'cfg> PackageRegistry<'cfg> { let summary = match summaries.next() { Some(summary) => summary, - None => bail!( + None => failure::bail!( "patch for `{}` in `{}` did not resolve to any crates. If this is \ unexpected, you may wish to consult: \ https://github.com/rust-lang/cargo/issues/4678", @@ -246,14 +246,14 @@ impl<'cfg> PackageRegistry<'cfg> { ), }; if summaries.next().is_some() { - bail!( + failure::bail!( "patch for `{}` in `{}` resolved to more than one candidate", dep.package_name(), url ) } if summary.package_id().source_id().url() == url { - bail!( + failure::bail!( "patch for `{}` in `{}` points to the same source, but \ patches must point to different sources", dep.package_name(), @@ -263,7 +263,7 @@ impl<'cfg> PackageRegistry<'cfg> { Ok(summary) }) .collect::>>() - .chain_err(|| format_err!("failed to resolve patches for `{}`", url))?; + .chain_err(|| failure::format_err!("failed to resolve patches for `{}`", url))?; // Note that we do not use `lock` here to lock summaries! That step // happens later once `lock_patches` is invoked. In the meantime though @@ -313,7 +313,7 @@ impl<'cfg> PackageRegistry<'cfg> { let _p = profile::start(format!("updating: {}", source_id)); self.sources.get_mut(source_id).unwrap().update() })() - .chain_err(|| format_err!("Unable to update {}", source_id))?; + .chain_err(|| failure::format_err!("Unable to update {}", source_id))?; Ok(()) } @@ -467,7 +467,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> { // Ensure the requested source_id is loaded self.ensure_loaded(dep.source_id(), Kind::Normal) .chain_err(|| { - format_err!( + failure::format_err!( "failed to load source for a dependency \ on `{}`", dep.package_name() @@ -476,7 +476,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> { let source = self.sources.get_mut(dep.source_id()); match (override_summary, source) { - (Some(_), None) => bail!("override found but no real ones"), + (Some(_), None) => failure::bail!("override found but no real ones"), (None, None) => return Ok(()), // If we don't have an override then we just ship @@ -516,7 +516,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> { // the summaries it gives us though. (Some(override_summary), Some(source)) => { if !patches.is_empty() { - bail!("found patches and a path override") + failure::bail!("found patches and a path override") } let mut n = 0; let mut to_warn = None; @@ -538,7 +538,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> { }; if n > 1 { - bail!("found an override with a non-locked list"); + failure::bail!("found an override with a non-locked list"); } else if let Some(summary) = to_warn { self.warn_bad_override(&override_summary, &summary)?; } diff --git a/src/cargo/core/resolver/context.rs b/src/cargo/core/resolver/context.rs index 3658c4c89fa..ef48192a276 100644 --- a/src/cargo/core/resolver/context.rs +++ b/src/cargo/core/resolver/context.rs @@ -1,6 +1,8 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use std::rc::Rc; +#[allow(unused_imports)] // "ensure" seems to require "bail" be in scope (macro hygiene issue?) +use failure::{bail, ensure}; use log::debug; use crate::core::interning::InternedString; @@ -204,9 +206,11 @@ impl Context { base.extend(dep.features().iter()); for feature in base.iter() { if feature.contains('/') { - return Err( - format_err!("feature names may not contain slashes: `{}`", feature).into(), - ); + return Err(failure::format_err!( + "feature names may not contain slashes: `{}`", + feature + ) + .into()); } } ret.push((dep.clone(), base)); @@ -225,7 +229,7 @@ impl Context { if !remaining.is_empty() { let features = remaining.join(", "); return Err(match parent { - None => format_err!( + None => failure::format_err!( "Package `{}` does not have these features: `{}`", s.package_id(), features @@ -390,7 +394,7 @@ impl<'r> Requirements<'r> { .expect("must be a valid feature") { match *fv { - FeatureValue::Feature(ref dep_feat) if **dep_feat == *feat => bail!( + FeatureValue::Feature(ref dep_feat) if **dep_feat == *feat => failure::bail!( "Cyclic feature dependency: feature `{}` depends on itself", feat ), diff --git a/src/cargo/core/resolver/encode.rs b/src/cargo/core/resolver/encode.rs index 9a37ff0dbd3..ffa880ca268 100644 --- a/src/cargo/core/resolver/encode.rs +++ b/src/cargo/core/resolver/encode.rs @@ -56,7 +56,7 @@ impl EncodableResolve { }; if !all_pkgs.insert(enc_id.clone()) { - bail!("package `{}` is specified twice in the lockfile", pkg.name); + failure::bail!("package `{}` is specified twice in the lockfile", pkg.name); } let id = match pkg.source.as_ref().or_else(|| path_deps.get(&pkg.name)) { // We failed to find a local package in the workspace. @@ -289,7 +289,7 @@ impl FromStr for EncodablePackageId { if s.starts_with('(') && s.ends_with(')') { Some(SourceId::from_url(&s[1..s.len() - 1])?) } else { - bail!("invalid serialized PackageId") + failure::bail!("invalid serialized PackageId") } } None => None, diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index 8720f3f1009..217523e8655 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -161,7 +161,7 @@ pub(super) fn activation_error( msg.push_str(&*dep.package_name()); msg.push_str("` which could resolve this conflict"); - return to_resolve_err(format_err!("{}", msg)); + return to_resolve_err(failure::format_err!("{}", msg)); } // We didn't actually find any candidates, so we need to @@ -274,7 +274,7 @@ pub(super) fn activation_error( } } - to_resolve_err(format_err!("{}", msg)) + to_resolve_err(failure::format_err!("{}", msg)) } /// Returns String representation of dependency chain for a particular `pkgid`. diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index ca602c0d640..9f753fc8eec 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -845,7 +845,7 @@ fn check_cycles(resolve: &Resolve, activations: &Activations) -> CargoResult<()> ) -> CargoResult<()> { // See if we visited ourselves if !visited.insert(id) { - bail!( + failure::bail!( "cyclic package dependency: package `{}` depends on itself. Cycle:\n{}", id, errors::describe_path(&resolve.path_to_top(&id)) @@ -896,7 +896,7 @@ fn check_duplicate_pkgs_in_lockfile(resolve: &Resolve) -> CargoResult<()> { for pkg_id in resolve.iter() { let encodable_pkd_id = encode::encodable_package_id(pkg_id); if let Some(prev_pkg_id) = unique_pkg_ids.insert(encodable_pkd_id, pkg_id) { - bail!( + failure::bail!( "package collision in the lockfile: packages {} and {} are different, \ but only one can be written to lockfile unambiguously", prev_pkg_id, diff --git a/src/cargo/core/resolver/resolve.rs b/src/cargo/core/resolver/resolve.rs index 9ee26c4787d..b3d990830c5 100644 --- a/src/cargo/core/resolver/resolve.rs +++ b/src/cargo/core/resolver/resolve.rs @@ -94,7 +94,7 @@ impl Resolve { // desires stronger checksum guarantees than can be afforded // elsewhere. if cksum.is_none() { - bail!( + failure::bail!( "\ checksum for `{}` was not previously calculated, but a checksum could now \ be calculated @@ -116,7 +116,7 @@ this could be indicative of a few possible situations: // more realistically we were overridden with a source that does // not have checksums. } else if mine.is_none() { - bail!( + failure::bail!( "\ checksum for `{}` could not be calculated, but a checksum is listed in \ the existing lock file @@ -137,7 +137,7 @@ unable to verify that `{0}` is the same as when the lockfile was generated // must both be Some, in which case the checksum now differs. // That's quite bad! } else { - bail!( + failure::bail!( "\ checksum for `{}` changed between lock files @@ -243,7 +243,7 @@ unable to verify that `{0}` is the same as when the lockfile was generated if n == name { continue; } - bail!( + failure::bail!( "multiple dependencies listed for the same crate must \ all have the same name, but the dependency on `{}` \ is listed as having different names", diff --git a/src/cargo/core/resolver/types.rs b/src/cargo/core/resolver/types.rs index 2e79dcd2d4e..fa00d413edd 100644 --- a/src/cargo/core/resolver/types.rs +++ b/src/cargo/core/resolver/types.rs @@ -144,7 +144,7 @@ impl<'a> RegistryQueryer<'a> { let mut summaries = self.registry.query_vec(dep, false)?.into_iter(); let s = summaries.next().ok_or_else(|| { - format_err!( + failure::format_err!( "no matching package for override `{}` found\n\ location searched: {}\n\ version required: {}", @@ -159,7 +159,7 @@ impl<'a> RegistryQueryer<'a> { .iter() .map(|s| format!(" * {}", s.package_id())) .collect::>(); - bail!( + failure::bail!( "the replacement specification `{}` matched \ multiple packages:\n * {}\n{}", spec, @@ -184,7 +184,7 @@ impl<'a> RegistryQueryer<'a> { // Make sure no duplicates if let Some(&(ref spec, _)) = potential_matches.next() { - bail!( + failure::bail!( "overlapping replacement specifications found:\n\n \ * {}\n * {}\n\nboth specifications match: {}", matched_spec, diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 336a1be6f6d..074c8c3bfcc 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -218,7 +218,7 @@ impl Shell { Some("auto") | None => ColorChoice::CargoAuto, - Some(arg) => bail!( + Some(arg) => failure::bail!( "argument for --color must be auto, always, or \ never, but found `{}`", arg @@ -376,13 +376,13 @@ mod imp { #[cfg(windows)] mod imp { + use std::{cmp, mem, ptr}; use winapi::um::fileapi::*; use winapi::um::handleapi::*; use winapi::um::processenv::*; use winapi::um::winbase::*; use winapi::um::wincon::*; use winapi::um::winnt::*; - use std::{cmp, mem, ptr}; pub(super) use super::default_err_erase_line as err_erase_line; diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index d0f093be1b9..713c15138d1 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -110,7 +110,7 @@ impl SourceId { let kind = parts.next().unwrap(); let url = parts .next() - .ok_or_else(|| format_err!("invalid source `{}`", string))?; + .ok_or_else(|| failure::format_err!("invalid source `{}`", string))?; match kind { "git" => { @@ -139,7 +139,10 @@ impl SourceId { let url = url.to_url()?; SourceId::new(Kind::Path, url) } - kind => Err(format_err!("unsupported source protocol: {}", kind)), + kind => Err(failure::format_err!( + "unsupported source protocol: {}", + kind + )), } } diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index bcf1b25388a..65a1a6bfc56 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -45,14 +45,14 @@ impl Summary { for dep in dependencies.iter() { let feature = dep.name_in_toml(); if !namespaced_features && features.get(&*feature).is_some() { - bail!( + failure::bail!( "Features and dependencies cannot have the \ same name: `{}`", feature ) } if dep.is_optional() && !dep.is_transitive() { - bail!( + failure::bail!( "Dev-dependencies are not allowed to be optional: `{}`", feature ) @@ -172,7 +172,7 @@ where match dep_map.get(feature.borrow()) { Some(ref dep_data) => { if !dep_data.iter().any(|d| d.is_optional()) { - bail!( + failure::bail!( "Feature `{}` includes the dependency of the same name, but this is \ left implicit in the features included by this feature.\n\ Additionally, the dependency must be marked as optional to be \ @@ -241,7 +241,7 @@ where (&Feature(feat), dep_exists, false) => { if namespaced && !features.contains_key(&*feat) { if dep_exists { - bail!( + failure::bail!( "Feature `{}` includes `{}` which is not defined as a feature.\n\ A non-optional dependency of the same name is defined; consider \ adding `optional = true` to its definition", @@ -249,7 +249,7 @@ where feat ) } else { - bail!( + failure::bail!( "Feature `{}` includes `{}` which is not defined as a feature", feature, feat @@ -264,7 +264,7 @@ where // just to provide the correct string for the crate dependency in the error. (&Crate(ref dep), true, false) => { if namespaced { - bail!( + failure::bail!( "Feature `{}` includes `crate:{}` which is not an \ optional dependency.\nConsider adding \ `optional = true` to the dependency", @@ -272,7 +272,7 @@ where dep ) } else { - bail!( + failure::bail!( "Feature `{}` depends on `{}` which is not an \ optional dependency.\nConsider adding \ `optional = true` to the dependency", @@ -287,14 +287,14 @@ where // namespaced here is just to provide the correct string in the error. (&Crate(ref dep), false, _) => { if namespaced { - bail!( + failure::bail!( "Feature `{}` includes `crate:{}` which is not a known \ dependency", feature, dep ) } else { - bail!( + failure::bail!( "Feature `{}` includes `{}` which is neither a dependency nor \ another feature", feature, @@ -305,7 +305,7 @@ where (&Crate(_), true, true) => {} // If the value is a feature for one of the dependencies, bail out if no such // dependency is actually defined in the manifest. - (&CrateFeature(ref dep, _), false, _) => bail!( + (&CrateFeature(ref dep, _), false, _) => failure::bail!( "Feature `{}` requires a feature of `{}` which is not a \ dependency", feature, @@ -319,7 +319,7 @@ where if !dependency_found { // If we have not found the dependency of the same-named feature, we should // bail here. - bail!( + failure::bail!( "Feature `{}` includes the optional dependency of the \ same name, but this is left implicit in the features \ included by this feature.\nConsider adding \ diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 9d09cef5e9a..647eed0292c 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -207,7 +207,7 @@ impl<'cfg> Workspace<'cfg> { /// indicating that something else should be passed. pub fn current(&self) -> CargoResult<&Package> { let pkg = self.current_opt().ok_or_else(|| { - format_err!( + failure::format_err!( "manifest path `{}` is a virtual manifest, but this \ command requires running against an actual package in \ this workspace", @@ -436,7 +436,7 @@ impl<'cfg> Workspace<'cfg> { None } } - _ => bail!( + _ => failure::bail!( "root of a workspace inferred but wasn't a root: {}", root_manifest_path.display() ), @@ -451,7 +451,7 @@ impl<'cfg> Workspace<'cfg> { for path in default { let manifest_path = paths::normalize_path(&path.join("Cargo.toml")); if !self.members.contains(&manifest_path) { - bail!( + failure::bail!( "package `{}` is listed in workspace’s default-members \ but is not a member.", path.display() @@ -544,7 +544,7 @@ impl<'cfg> Workspace<'cfg> { MaybePackage::Virtual(_) => continue, }; if let Some(prev) = names.insert(name, member) { - bail!( + failure::bail!( "two packages named `{}` in this workspace:\n\ - {}\n\ - {}", @@ -557,7 +557,7 @@ impl<'cfg> Workspace<'cfg> { } match roots.len() { - 0 => bail!( + 0 => failure::bail!( "`package.workspace` configuration points to a crate \ which is not configured with [workspace]: \n\ configuration at: {}\n\ @@ -567,7 +567,7 @@ impl<'cfg> Workspace<'cfg> { ), 1 => {} _ => { - bail!( + failure::bail!( "multiple workspace roots found in the same workspace:\n{}", roots .iter() @@ -586,7 +586,7 @@ impl<'cfg> Workspace<'cfg> { match root { Some(root) => { - bail!( + failure::bail!( "package `{}` is a member of the wrong workspace\n\ expected: {}\n\ actual: {}", @@ -596,7 +596,7 @@ impl<'cfg> Workspace<'cfg> { ); } None => { - bail!( + failure::bail!( "workspace member `{}` is not hierarchically below \ the workspace root `{}`", member.display(), @@ -648,7 +648,7 @@ impl<'cfg> Workspace<'cfg> { } } }; - bail!( + failure::bail!( "current package believes it's in a workspace when it's not:\n\ current: {}\n\ workspace: {}\n\n{}", @@ -695,7 +695,7 @@ impl<'cfg> Workspace<'cfg> { pub fn load(&self, manifest_path: &Path) -> CargoResult { match self.packages.maybe_get(manifest_path) { Some(&MaybePackage::Package(ref p)) => return Ok(p.clone()), - Some(&MaybePackage::Virtual(_)) => bail!("cannot load workspace root"), + Some(&MaybePackage::Virtual(_)) => failure::bail!("cannot load workspace root"), None => {} } @@ -749,8 +749,9 @@ impl<'cfg> Workspace<'cfg> { let path = path.join("Cargo.toml"); for warning in warnings { if warning.is_critical { - let err = format_err!("{}", warning.message); - let cx = format_err!("failed to parse manifest at `{}`", path.display()); + let err = failure::format_err!("{}", warning.message); + let cx = + failure::format_err!("failed to parse manifest at `{}`", path.display()); return Err(err.context(cx).into()); } else { let msg = if self.root_manifest.is_none() { @@ -888,9 +889,12 @@ impl WorkspaceRootConfig { Some(p) => p, None => return Ok(Vec::new()), }; - let res = glob(path).chain_err(|| format_err!("could not parse pattern `{}`", &path))?; + let res = + glob(path).chain_err(|| failure::format_err!("could not parse pattern `{}`", &path))?; let res = res - .map(|p| p.chain_err(|| format_err!("unable to match path to pattern `{}`", &path))) + .map(|p| { + p.chain_err(|| failure::format_err!("unable to match path to pattern `{}`", &path)) + }) .collect::, _>>()?; Ok(res) } diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 40b7db71fac..cafc95409d0 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(test, deny(warnings))] -#![warn(rust_2018_idioms)] // while we're getting used to 2018 +#![warn(rust_2018_idioms)] +// while we're getting used to 2018 // Clippy isn't enforced by CI, and know that @alexcrichton isn't a fan :) #![allow(clippy::boxed_local)] // bug rust-lang-nursery/rust-clippy#1123 #![allow(clippy::cyclomatic_complexity)] // large project @@ -14,9 +15,6 @@ #![allow(clippy::type_complexity)] // there's an exceptionally complex type #![allow(clippy::wrong_self_convention)] // perhaps Rc should be special cased in Clippy? -#[macro_use] -extern crate failure; - use std::fmt; use failure::Error; diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 7224c1a6a06..8dae82603bd 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -135,12 +135,13 @@ fn rm_rf(path: &Path, config: &Config) -> CargoResult<()> { .shell() .verbose(|shell| shell.status("Removing", path.display()))?; paths::remove_dir_all(path) - .chain_err(|| format_err!("could not remove build directory"))?; + .chain_err(|| failure::format_err!("could not remove build directory"))?; } else if m.is_ok() { config .shell() .verbose(|shell| shell.status("Removing", path.display()))?; - paths::remove_file(path).chain_err(|| format_err!("failed to remove build artifact"))?; + paths::remove_file(path) + .chain_err(|| failure::format_err!("failed to remove build artifact"))?; } Ok(()) } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 1e41483325c..7fec9a06e6b 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -103,7 +103,7 @@ impl Packages { Ok(match (all, exclude.len(), package.len()) { (false, 0, 0) => Packages::Default, (false, 0, _) => Packages::Packages(package), - (false, _, _) => bail!("--exclude can only be used together with --all"), + (false, _, _) => failure::bail!("--exclude can only be used together with --all"), (true, 0, _) => Packages::All, (true, _, _) => Packages::OptOut(exclude), }) @@ -137,13 +137,13 @@ impl Packages { }; if specs.is_empty() { if ws.is_virtual() { - bail!( + failure::bail!( "manifest path `{}` contains no package: The manifest is virtual, \ and the workspace has no members.", ws.root().display() ) } - bail!("no packages to compile") + failure::bail!("no packages to compile") } Ok(specs) } @@ -162,7 +162,10 @@ impl Packages { ws.members() .find(|pkg| pkg.name().as_str() == name) .ok_or_else(|| { - format_err!("package `{}` is not a member of the workspace", name) + failure::format_err!( + "package `{}` is not a member of the workspace", + name + ) }) }) .collect::>>()?, @@ -267,7 +270,7 @@ pub fn compile_ws<'a>( && !ws.is_member(pkg) && pkg.dependencies().iter().any(|dep| !dep.is_transitive()) { - bail!( + failure::bail!( "package `{}` cannot be tested because it requires dev-dependencies \ and is not a member of the workspace", pkg.name() @@ -304,7 +307,7 @@ pub fn compile_ws<'a>( let mut extra_compiler_args = HashMap::new(); if let Some(args) = extra_args { if units.len() != 1 { - bail!( + failure::bail!( "extra arguments to `{}` can only be passed to one \ target, consider filtering\nthe package by passing \ e.g. `--lib` or `--bin NAME` to specify a single target", @@ -639,9 +642,12 @@ fn generate_targets<'a>( if !all_targets && libs.is_empty() { let names = packages.iter().map(|pkg| pkg.name()).collect::>(); if names.len() == 1 { - bail!("no library targets found in package `{}`", names[0]); + failure::bail!("no library targets found in package `{}`", names[0]); } else { - bail!("no library targets found in packages: {}", names.join(", ")); + failure::bail!( + "no library targets found in packages: {}", + names.join(", ") + ); } } proposals.extend(libs); @@ -730,7 +736,7 @@ fn generate_targets<'a>( .iter() .map(|s| format!("`{}`", s)) .collect(); - bail!( + failure::bail!( "target `{}` in package `{}` requires the features: {}\n\ Consider enabling them by passing e.g. `--features=\"{}\"`", target.name(), @@ -865,13 +871,13 @@ fn find_named_targets<'a>( .min_by_key(|t| t.0) .map(|t| t.1); match suggestion { - Some(s) => bail!( + Some(s) => failure::bail!( "no {} target named `{}`\n\nDid you mean `{}`?", target_desc, target_name, s.name() ), - None => bail!("no {} target named `{}`", target_desc, target_name), + None => failure::bail!("no {} target named `{}`", target_desc, target_name), } } Ok(result) diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 8fe5075e911..a61e9c25cca 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -43,7 +43,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> { for target in package.targets().iter().filter(|t| t.documented()) { if target.is_lib() { if let Some(prev) = lib_names.insert(target.crate_name(), package) { - bail!( + failure::bail!( "The library `{}` is specified by packages `{}` and \ `{}` but can only be documented once. Consider renaming \ or marking one of the targets as `doc = false`.", @@ -53,7 +53,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> { ); } } else if let Some(prev) = bin_names.insert(target.crate_name(), package) { - bail!( + failure::bail!( "The binary `{}` is specified by packages `{}` and \ `{}` but can be documented only once. Consider renaming \ or marking one of the targets as `doc = false`.", @@ -69,7 +69,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> { if options.open_result { let name = if pkgs.len() > 1 { - bail!( + failure::bail!( "Passing multiple packages and `open` is not supported.\n\ Please re-run this command with `-p ` where `` \ is one of the following:\n {}", diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index 111e76b0394..e559a92278c 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -37,15 +37,15 @@ pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> { pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> { if opts.aggressive && opts.precise.is_some() { - bail!("cannot specify both aggressive and precise simultaneously") + failure::bail!("cannot specify both aggressive and precise simultaneously") } if ws.members().count() == 0 { - bail!("you can't generate a lockfile for an empty workspace.") + failure::bail!("you can't generate a lockfile for an empty workspace.") } if opts.config.cli_unstable().offline { - bail!("you can't update in the offline mode"); + failure::bail!("you can't update in the offline mode"); } let previous_resolve = match ops::load_pkg_lockfile(ws)? { diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index f355997585f..dccc5e8fbb8 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -144,7 +144,7 @@ pub fn install( } if scheduled_error { - bail!("some crates failed to install"); + failure::bail!("some crates failed to install"); } Ok(()) @@ -175,7 +175,7 @@ fn install_one( } else if source_id.is_path() { let mut src = path_source(source_id, config)?; src.update().chain_err(|| { - format_err!( + failure::format_err!( "`{}` is not a crate root; specify a crate to \ install from crates.io, or use --path or --git to \ specify an alternate source", @@ -193,7 +193,7 @@ fn install_one( config, is_first_install, &mut |_| { - bail!( + failure::bail!( "must specify a crate to install from \ crates.io, or use --path or --git to \ specify alternate source" @@ -235,7 +235,7 @@ fn install_one( use `cargo install --path .` instead. \ Use `cargo build` if you want to simply build the package.", )?, - Edition::Edition2018 => bail!( + Edition::Edition2018 => failure::bail!( "Using `cargo install` to install the binaries for the \ package in current working directory is no longer supported, \ use `cargo install --path .` instead. \ @@ -263,7 +263,7 @@ fn install_one( td.into_path(); } - format_err!( + failure::format_err!( "failed to compile `{}`, intermediate artifacts can be \ found at `{}`", pkg, @@ -278,12 +278,12 @@ fn install_one( if let Some(s) = name.to_str() { Ok((s, bin.as_ref())) } else { - bail!("Binary `{:?}` name can't be serialized into string", name) + failure::bail!("Binary `{:?}` name can't be serialized into string", name) } }) .collect::>()?; if binaries.is_empty() { - bail!( + failure::bail!( "no binaries are available for install using the selected \ features" ); @@ -309,7 +309,7 @@ fn install_one( continue; } fs::copy(src, &dst).chain_err(|| { - format_err!("failed to copy `{}` to `{}`", src.display(), dst.display()) + failure::format_err!("failed to copy `{}` to `{}`", src.display(), dst.display()) })?; } @@ -326,7 +326,7 @@ fn install_one( let dst = dst.join(bin); config.shell().status("Installing", dst.display())?; fs::rename(&src, &dst).chain_err(|| { - format_err!("failed to move `{}` to `{}`", src.display(), dst.display()) + failure::format_err!("failed to move `{}` to `{}`", src.display(), dst.display()) })?; installed.bins.push(dst); } @@ -341,7 +341,11 @@ fn install_one( let dst = dst.join(bin); config.shell().status("Replacing", dst.display())?; fs::rename(&src, &dst).chain_err(|| { - format_err!("failed to move `{}` to `{}`", src.display(), dst.display()) + failure::format_err!( + "failed to move `{}` to `{}`", + src.display(), + dst.display() + ) })?; replaced_names.push(bin); } @@ -410,7 +414,7 @@ fn path_source<'a>(source_id: SourceId, config: &'a Config) -> CargoResult { // If the version begins with character <, >, =, ^, ~ parse it as a // version range, otherwise parse it as a specific version - let first = v - .chars() - .nth(0) - .ok_or_else(|| format_err!("no version provided for the `--vers` flag"))?; + let first = v.chars().nth(0).ok_or_else(|| { + failure::format_err!("no version provided for the `--vers` flag") + })?; match first { '<' | '>' | '=' | '^' | '~' => match v.parse::() { Ok(v) => Some(v.to_string()), - Err(_) => bail!( + Err(_) => failure::bail!( "the `--vers` provided, `{}`, is \ not a valid semver version requirement\n\n Please have a look at \ @@ -500,7 +503,7 @@ where let vers_info = vers .map(|v| format!(" with version `{}`", v)) .unwrap_or_default(); - bail!( + failure::bail!( "could not find `{}` in {}{}", name, source.source_id(), @@ -530,7 +533,7 @@ where Some(p) => p, None => match one(examples, |v| multi_err("examples", v))? { Some(p) => p, - None => bail!( + None => failure::bail!( "no packages found with binaries or \ examples" ), @@ -562,7 +565,7 @@ where (Some(i1), Some(i2)) => { let mut v = vec![i1, i2]; v.extend(i); - Err(format_err!("{}", f(v))) + Err(failure::format_err!("{}", f(v))) } (Some(i), None) => Ok(Some(i)), (None, _) => Ok(None), @@ -580,7 +583,7 @@ fn check_overwrites( // get checked during cargo_compile, we only care about the "build // everything" case here if !filter.is_specific() && !pkg.targets().iter().any(|t| t.is_bin()) { - bail!("specified package has no binaries") + failure::bail!("specified package has no binaries") } let duplicates = find_duplicates(dst, pkg, filter, prev); if force || duplicates.is_empty() { @@ -597,7 +600,7 @@ fn check_overwrites( } } msg.push_str("Add --force to overwrite"); - Err(format_err!("{}", msg)) + Err(failure::format_err!("{}", msg)) } fn find_duplicates( @@ -667,7 +670,7 @@ fn read_crate_list(file: &FileLock) -> CargoResult { } })() .chain_err(|| { - format_err!( + failure::format_err!( "failed to parse crate metadata at `{}`", file.path().to_string_lossy() ) @@ -685,7 +688,7 @@ fn write_crate_list(file: &FileLock, listing: CrateListingV1) -> CargoResult<()> Ok(()) })() .chain_err(|| { - format_err!( + failure::format_err!( "failed to write crate metadata at `{}`", file.path().to_string_lossy() ) @@ -713,7 +716,7 @@ pub fn uninstall( config: &Config, ) -> CargoResult<()> { if specs.len() > 1 && !bins.is_empty() { - bail!("A binary can only be associated with a single installed package, specifying multiple specs with --bin is redundant."); + failure::bail!("A binary can only be associated with a single installed package, specifying multiple specs with --bin is redundant."); } let root = resolve_root(root, config)?; @@ -759,7 +762,7 @@ pub fn uninstall( }; if scheduled_error { - bail!("some packages failed to uninstall"); + failure::bail!("some packages failed to uninstall"); } Ok(()) @@ -800,13 +803,13 @@ fn uninstall_pkgid( { let mut installed = match metadata.v1.entry(pkgid) { Entry::Occupied(e) => e, - Entry::Vacant(..) => bail!("package `{}` is not installed", pkgid), + Entry::Vacant(..) => failure::bail!("package `{}` is not installed", pkgid), }; let dst = crate_metadata.parent().join("bin"); for bin in installed.get() { let bin = dst.join(bin); if fs::metadata(&bin).is_err() { - bail!( + failure::bail!( "corrupt metadata, `{}` does not exist when it should", bin.display() ) @@ -826,7 +829,7 @@ fn uninstall_pkgid( for bin in bins.iter() { if !installed.get().contains(bin) { - bail!("binary `{}` not installed as part of `{}`", bin, pkgid) + failure::bail!("binary `{}` not installed as part of `{}`", bin, pkgid) } } diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index cfdd0e727ef..3fdd88141af 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -83,7 +83,7 @@ impl NewOptions { registry: Option, ) -> CargoResult { let kind = match (bin, lib) { - (true, true) => bail!("can't specify both lib and binary outputs"), + (true, true) => failure::bail!("can't specify both lib and binary outputs"), (false, true) => NewProjectKind::Lib, // default to bin (_, false) => NewProjectKind::Bin, @@ -113,14 +113,14 @@ fn get_name<'a>(path: &'a Path, opts: &'a NewOptions) -> CargoResult<&'a str> { } let file_name = path.file_name().ok_or_else(|| { - format_err!( + failure::format_err!( "cannot auto-detect package name from path {:?} ; use --name to override", path.as_os_str() ) })?; file_name.to_str().ok_or_else(|| { - format_err!( + failure::format_err!( "cannot create package with a non-unicode name: {:?}", file_name ) @@ -145,7 +145,7 @@ fn check_name(name: &str, opts: &NewOptions) -> CargoResult<()> { "true", "type", "typeof", "unsafe", "unsized", "use", "virtual", "where", "while", "yield", ]; if blacklist.contains(&name) || (opts.kind.is_bin() && compiler::is_bad_artifact_name(name)) { - bail!( + failure::bail!( "The name `{}` cannot be used as a crate name{}", name, name_help @@ -154,7 +154,7 @@ fn check_name(name: &str, opts: &NewOptions) -> CargoResult<()> { if let Some(ref c) = name.chars().nth(0) { if c.is_digit(10) { - bail!( + failure::bail!( "Package names starting with a digit cannot be used as a crate name{}", name_help ) @@ -168,7 +168,7 @@ fn check_name(name: &str, opts: &NewOptions) -> CargoResult<()> { if c == '_' || c == '-' { continue; } - bail!( + failure::bail!( "Invalid character `{}` in crate name: `{}`{}", c, name, @@ -267,7 +267,7 @@ fn detect_source_paths_and_types( for i in detected_files { if i.bin { if let Some(x) = BTreeMap::get::(&duplicates_checker, i.target_name.as_ref()) { - bail!( + failure::bail!( "\ multiple possible binary sources found: {} @@ -280,7 +280,7 @@ cannot automatically generate Cargo.toml as the main target would be ambiguous", duplicates_checker.insert(i.target_name.as_ref(), i); } else { if let Some(plp) = previous_lib_relpath { - bail!( + failure::bail!( "cannot have a package with \ multiple libraries, \ found both `{}` and `{}`", @@ -314,7 +314,7 @@ fn plan_new_source_file(bin: bool, package_name: String) -> SourceFileInformatio pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> { let path = &opts.path; if fs::metadata(path).is_ok() { - bail!( + failure::bail!( "destination `{}` already exists\n\n\ Use `cargo init` to initialize the directory", path.display() @@ -335,7 +335,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> { }; mk(config, &mkopts).chain_err(|| { - format_err!( + failure::format_err!( "Failed to create package `{}` at `{}`", name, path.display() @@ -348,7 +348,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { let path = &opts.path; if fs::metadata(&path.join("Cargo.toml")).is_ok() { - bail!("`cargo init` cannot be run on existing Cargo packages") + failure::bail!("`cargo init` cannot be run on existing Cargo packages") } let name = get_name(path, opts)?; @@ -394,7 +394,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { // if none exists, maybe create git, like in `cargo new` if num_detected_vsces > 1 { - bail!( + failure::bail!( "more than one of .hg, .git, .pijul, .fossil configurations \ found and the ignore file can't be filled in as \ a result. specify --vcs to override detection" @@ -413,7 +413,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { }; mk(config, &mkopts).chain_err(|| { - format_err!( + failure::format_err!( "Failed to create package `{}` at `{}`", name, path.display() @@ -646,7 +646,7 @@ fn discover_author() -> CargoResult<(String, Option)> { Some(name) => name, None => { let username_var = if cfg!(windows) { "USERNAME" } else { "USER" }; - bail!( + failure::bail!( "could not determine the current user, please set ${}", username_var ) @@ -694,7 +694,7 @@ fn global_config(config: &Config) -> CargoResult { `cargo-new.vcs`, unknown vcs `{}` \ (found in {})", s, p - ))) + ))); } None => None, }; diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index 1291c4be86e..d66301b862e 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -23,7 +23,7 @@ pub struct OutputMetadataOptions { /// format to stdout. pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> CargoResult { if opt.version != VERSION { - bail!( + failure::bail!( "metadata version {} not supported, only {} is currently supported", opt.version, VERSION diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 213eb2c11b9..e616c5136d8 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -98,7 +98,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult