mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Remove trailing extern crate usage
This commit is contained in:
parent
ec197891e8
commit
54c4214251
@ -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),
|
||||
}),
|
||||
}
|
||||
|
@ -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"
|
||||
))?;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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."
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
}),
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -48,27 +48,27 @@ impl BuildConfig {
|
||||
) -> CargoResult<BuildConfig> {
|
||||
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(
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
),
|
||||
|
@ -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(),
|
||||
);
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult<Option<(PathBuf, Vec
|
||||
if let Some(runner) = bcx.config.get_path_and_args(&key)? {
|
||||
// more than one match, error out
|
||||
if matching_runner.is_some() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"several matching instances of `target.'cfg(..)'.runner` \
|
||||
in `.cargo/config`"
|
||||
)
|
||||
|
@ -341,7 +341,7 @@ impl<'a, 'cfg: 'a> 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,
|
||||
|
@ -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(),
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(())
|
||||
|
@ -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 \
|
||||
|
@ -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);
|
||||
|
@ -454,10 +454,9 @@ impl FromStr for Platform {
|
||||
fn from_str(s: &str) -> CargoResult<Platform> {
|
||||
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()))
|
||||
|
@ -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<String>) -> 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(())
|
||||
|
@ -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(())
|
||||
|
@ -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);
|
||||
|
@ -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<Item = PackageId>,
|
||||
{
|
||||
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<PackageIdSpec> {
|
||||
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),
|
||||
};
|
||||
|
@ -231,7 +231,7 @@ impl ProfileMaker {
|
||||
.map(|spec| spec.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.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(())
|
||||
}
|
||||
|
@ -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::<CargoResult<Vec<_>>>()
|
||||
.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)?;
|
||||
}
|
||||
|
@ -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
|
||||
),
|
||||
|
@ -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,
|
||||
|
@ -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`.
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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::<Vec<_>>();
|
||||
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,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 \
|
||||
|
@ -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<Package> {
|
||||
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::<Result<Vec<_>, _>>()?;
|
||||
Ok(res)
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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::<CargoResult<Vec<_>>>()?,
|
||||
@ -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::<Vec<_>>();
|
||||
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)
|
||||
|
@ -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 <spec>` where `<spec>` \
|
||||
is one of the following:\n {}",
|
||||
|
@ -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)? {
|
||||
|
@ -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::<CargoResult<_>>()?;
|
||||
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<PathS
|
||||
let path = source_id
|
||||
.url()
|
||||
.to_file_path()
|
||||
.map_err(|()| format_err!("path sources must have a valid path"))?;
|
||||
.map_err(|()| failure::format_err!("path sources must have a valid path"))?;
|
||||
Ok(PathSource::new(&path, source_id, config))
|
||||
}
|
||||
|
||||
@ -435,15 +439,14 @@ where
|
||||
Some(v) => {
|
||||
// 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::<VersionReq>() {
|
||||
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<CrateListingV1> {
|
||||
}
|
||||
})()
|
||||
.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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ impl NewOptions {
|
||||
registry: Option<String>,
|
||||
) -> CargoResult<NewOptions> {
|
||||
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::<str>(&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<String>)> {
|
||||
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<CargoNewConfig> {
|
||||
`cargo-new.vcs`, unknown vcs `{}` \
|
||||
(found in {})",
|
||||
s, p
|
||||
)))
|
||||
)));
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ pub struct OutputMetadataOptions {
|
||||
/// format to stdout.
|
||||
pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> CargoResult<ExportInfo> {
|
||||
if opt.version != VERSION {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"metadata version {} not supported, only {} is currently supported",
|
||||
opt.version,
|
||||
VERSION
|
||||
|
@ -98,7 +98,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult<Option
|
||||
.status("Packaging", pkg.package_id().to_string())?;
|
||||
dst.file().set_len(0)?;
|
||||
tar(ws, &src_files, vcs_info.as_ref(), dst.file(), &filename)
|
||||
.chain_err(|| format_err!("failed to prepare local package for uploading"))?;
|
||||
.chain_err(|| failure::format_err!("failed to prepare local package for uploading"))?;
|
||||
if opts.verify {
|
||||
dst.seek(SeekFrom::Start(0))?;
|
||||
run_verify(ws, &dst, opts).chain_err(|| "failed to verify package tarball")?
|
||||
@ -161,7 +161,7 @@ fn check_metadata(pkg: &Package, config: &Config) -> CargoResult<()> {
|
||||
fn verify_dependencies(pkg: &Package) -> CargoResult<()> {
|
||||
for dep in pkg.dependencies() {
|
||||
if dep.source_id().is_path() && !dep.specified_req() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"all path dependencies must have a version specified \
|
||||
when packaging.\ndependency `{}` does not specify \
|
||||
a version.",
|
||||
@ -243,7 +243,7 @@ fn check_repo_state(
|
||||
Ok(Some(rev_obj.id().to_string()))
|
||||
} else {
|
||||
if !allow_dirty {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"{} files in the working directory contain changes that were \
|
||||
not yet committed into git:\n\n{}\n\n\
|
||||
to proceed despite this, pass the `--allow-dirty` flag",
|
||||
@ -266,7 +266,7 @@ fn check_vcs_file_collision(pkg: &Package, src_files: &[PathBuf]) -> CargoResult
|
||||
.iter()
|
||||
.find(|&p| util::without_prefix(&p, root).unwrap() == vcs_info_path);
|
||||
if collision.is_some() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"Invalid inclusion of reserved file name \
|
||||
{} in package source",
|
||||
VCS_INFO_FILE
|
||||
@ -297,7 +297,7 @@ fn tar(
|
||||
let relative = util::without_prefix(file, root).unwrap();
|
||||
check_filename(relative)?;
|
||||
let relative = relative.to_str().ok_or_else(|| {
|
||||
format_err!("non-utf8 path in source directory: {}", relative.display())
|
||||
failure::format_err!("non-utf8 path in source directory: {}", relative.display())
|
||||
})?;
|
||||
config
|
||||
.shell()
|
||||
@ -467,7 +467,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
|
||||
let ws_fingerprint = src.last_modified_file(ws.current()?)?;
|
||||
if pkg_fingerprint != ws_fingerprint {
|
||||
let (_, path) = ws_fingerprint;
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"Source directory was modified by build.rs during cargo publish. \
|
||||
Build scripts should not modify anything outside of OUT_DIR. \
|
||||
Modified file: {}\n\n\
|
||||
@ -492,7 +492,7 @@ fn check_filename(file: &Path) -> CargoResult<()> {
|
||||
};
|
||||
let name = match name.to_str() {
|
||||
Some(name) => name,
|
||||
None => bail!(
|
||||
None => failure::bail!(
|
||||
"path does not have a unicode filename which may not unpack \
|
||||
on all platforms: {}",
|
||||
file.display()
|
||||
@ -500,7 +500,7 @@ fn check_filename(file: &Path) -> CargoResult<()> {
|
||||
};
|
||||
let bad_chars = ['/', '\\', '<', '>', ':', '"', '|', '?', '*'];
|
||||
if let Some(c) = bad_chars.iter().find(|c| name.contains(**c)) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"cannot package a filename with a special character `{}`: {}",
|
||||
c,
|
||||
file.display()
|
||||
|
@ -5,7 +5,7 @@ use crate::util::CargoResult;
|
||||
pub fn pkgid(ws: &Workspace<'_>, spec: Option<&str>) -> CargoResult<PackageIdSpec> {
|
||||
let resolve = match ops::load_pkg_lockfile(ws)? {
|
||||
Some(resolve) => resolve,
|
||||
None => bail!("a Cargo.lock must exist for this command"),
|
||||
None => failure::bail!("a Cargo.lock must exist for this command"),
|
||||
};
|
||||
|
||||
let pkgid = match spec {
|
||||
|
@ -24,7 +24,7 @@ pub fn read_package(
|
||||
let (manifest, nested) = read_manifest(path, source_id, config)?;
|
||||
let manifest = match manifest {
|
||||
EitherManifest::Real(manifest) => manifest,
|
||||
EitherManifest::Virtual(..) => bail!(
|
||||
EitherManifest::Virtual(..) => failure::bail!(
|
||||
"found a virtual manifest at `{}` instead of a package \
|
||||
manifest",
|
||||
path.display()
|
||||
@ -88,7 +88,7 @@ pub fn read_packages(
|
||||
if all_packages.is_empty() {
|
||||
match errors.pop() {
|
||||
Some(err) => Err(err),
|
||||
None => Err(format_err!(
|
||||
None => Err(failure::format_err!(
|
||||
"Could not find Cargo.toml in `{}`",
|
||||
path.display()
|
||||
)),
|
||||
|
@ -32,7 +32,7 @@ pub fn run(
|
||||
|
||||
if bins.is_empty() {
|
||||
if !options.filter.is_specific() {
|
||||
bail!("a bin target must be available for `cargo run`")
|
||||
failure::bail!("a bin target must be available for `cargo run`")
|
||||
} else {
|
||||
// this will be verified in cargo_compile
|
||||
}
|
||||
@ -41,7 +41,7 @@ pub fn run(
|
||||
if bins.len() == 1 {
|
||||
let target = bins[0].1;
|
||||
if let TargetKind::ExampleLib(..) = target.kind() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"example target `{}` is a library and cannot be executed",
|
||||
target.name()
|
||||
)
|
||||
@ -55,7 +55,7 @@ pub fn run(
|
||||
.map(|(_pkg, target)| target.name())
|
||||
.collect();
|
||||
if nightly_features_allowed() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"`cargo run` could not determine which binary to run. \
|
||||
Use the `--bin` option to specify a binary, \
|
||||
or (on nightly) the `default-run` manifest key.\n\
|
||||
@ -63,7 +63,7 @@ pub fn run(
|
||||
names.join(", ")
|
||||
)
|
||||
} else {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"`cargo run` requires that a package only have one \
|
||||
executable; use the `--bin` option to specify which one \
|
||||
to run\navailable binaries: {}",
|
||||
@ -71,7 +71,7 @@ pub fn run(
|
||||
)
|
||||
}
|
||||
} else {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"`cargo run` can run at most one executable, but \
|
||||
multiple were specified"
|
||||
)
|
||||
|
@ -93,7 +93,7 @@ fn check_version_control(opts: &FixOptions<'_>) -> CargoResult<()> {
|
||||
}
|
||||
let config = opts.compile_opts.config;
|
||||
if !existing_vcs_repo(config.cwd(), config.cwd()) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"no VCS found for this package and `cargo fix` can potentially \
|
||||
perform destructive changes; if you'd like to suppress this \
|
||||
error pass `--allow-no-vcs`"
|
||||
@ -148,7 +148,7 @@ fn check_version_control(opts: &FixOptions<'_>) -> CargoResult<()> {
|
||||
files_list.push_str(" (staged)\n");
|
||||
}
|
||||
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"the working directory of this package has uncommitted changes, and \
|
||||
`cargo fix` can potentially perform destructive changes; if you'd \
|
||||
like to suppress this error pass `--allow-dirty`, `--allow-staged`, \
|
||||
|
@ -85,7 +85,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &Resolve) -> CargoResult<
|
||||
|
||||
if !ws.config().lock_update_allowed() {
|
||||
if ws.config().cli_unstable().offline {
|
||||
bail!("can't update in the offline mode");
|
||||
failure::bail!("can't update in the offline mode");
|
||||
}
|
||||
|
||||
let flag = if ws.config().network_allowed() {
|
||||
@ -93,7 +93,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &Resolve) -> CargoResult<
|
||||
} else {
|
||||
"--frozen"
|
||||
};
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"the lock file {} needs to be updated but {} was passed to \
|
||||
prevent this",
|
||||
ws.root().to_path_buf().join("Cargo.lock").display(),
|
||||
|
@ -48,7 +48,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
|
||||
Some(ref registry) => allowed_registries.contains(registry),
|
||||
None => false,
|
||||
} {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"some crates cannot be published.\n\
|
||||
`{}` is marked as unpublishable",
|
||||
pkg.name()
|
||||
@ -57,7 +57,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
|
||||
}
|
||||
|
||||
if !pkg.manifest().patch().is_empty() {
|
||||
bail!("published crates cannot contain [patch] sections");
|
||||
failure::bail!("published crates cannot contain [patch] sections");
|
||||
}
|
||||
|
||||
let (mut registry, reg_id) = registry(
|
||||
@ -105,7 +105,7 @@ fn verify_dependencies(pkg: &Package, registry_src: SourceId) -> CargoResult<()>
|
||||
for dep in pkg.dependencies().iter() {
|
||||
if dep.source_id().is_path() {
|
||||
if !dep.specified_req() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"all path dependencies must have a version specified \
|
||||
when publishing.\ndependency `{}` does not specify \
|
||||
a version",
|
||||
@ -117,7 +117,7 @@ fn verify_dependencies(pkg: &Package, registry_src: SourceId) -> CargoResult<()>
|
||||
// Block requests to send to a registry if it is not an alternative
|
||||
// registry
|
||||
if !registry_src.is_alt_registry() {
|
||||
bail!("crates cannot be published to crates.io with dependencies sourced from other\n\
|
||||
failure::bail!("crates cannot be published to crates.io with dependencies sourced from other\n\
|
||||
registries either publish `{}` on crates.io or pull it into this repository\n\
|
||||
and specify it with a path and version\n\
|
||||
(crate `{}` is pulled from {})",
|
||||
@ -126,7 +126,7 @@ fn verify_dependencies(pkg: &Package, registry_src: SourceId) -> CargoResult<()>
|
||||
dep.source_id());
|
||||
}
|
||||
} else {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"crates cannot be published to crates.io with dependencies sourced from \
|
||||
a repository\neither publish `{}` as its own crate on crates.io and \
|
||||
specify a crates.io version as a dependency or pull it into this \
|
||||
@ -158,7 +158,7 @@ fn transmit(
|
||||
// registry in the dependency.
|
||||
let dep_registry_id = match dep.registry_id() {
|
||||
Some(id) => id,
|
||||
None => bail!("dependency missing registry ID"),
|
||||
None => failure::bail!("dependency missing registry ID"),
|
||||
};
|
||||
let dep_registry = if dep_registry_id != registry_id {
|
||||
Some(dep_registry_id.url().to_string())
|
||||
@ -205,7 +205,7 @@ fn transmit(
|
||||
};
|
||||
if let Some(ref file) = *license_file {
|
||||
if fs::metadata(&pkg.root().join(file)).is_err() {
|
||||
bail!("the license file `{}` does not exist", file)
|
||||
failure::bail!("the license file `{}` does not exist", file)
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,13 +344,13 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
|
||||
|
||||
pub fn http_handle_and_timeout(config: &Config) -> CargoResult<(Easy, HttpTimeout)> {
|
||||
if config.frozen() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"attempting to make an HTTP request, but --frozen was \
|
||||
specified"
|
||||
)
|
||||
}
|
||||
if !config.network_allowed() {
|
||||
bail!("can't make HTTP request in the offline mode")
|
||||
failure::bail!("can't make HTTP request in the offline mode")
|
||||
}
|
||||
|
||||
// The timeout option for libcurl by default times out the entire transfer,
|
||||
@ -543,9 +543,9 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
|
||||
|
||||
if let Some(ref v) = opts.to_add {
|
||||
let v = v.iter().map(|s| &s[..]).collect::<Vec<_>>();
|
||||
let msg = registry
|
||||
.add_owners(&name, &v)
|
||||
.map_err(|e| format_err!("failed to invite owners to crate {}: {}", name, e))?;
|
||||
let msg = registry.add_owners(&name, &v).map_err(|e| {
|
||||
failure::format_err!("failed to invite owners to crate {}: {}", name, e)
|
||||
})?;
|
||||
|
||||
config.shell().status("Owner", msg)?;
|
||||
}
|
||||
@ -596,7 +596,7 @@ pub fn yank(
|
||||
};
|
||||
let version = match version {
|
||||
Some(v) => v,
|
||||
None => bail!("a version must be specified to yank"),
|
||||
None => failure::bail!("a version must be specified to yank"),
|
||||
};
|
||||
|
||||
let (mut registry, _) = registry(config, token, index, reg)?;
|
||||
|
@ -232,7 +232,7 @@ pub fn resolve_with_previous<'cfg>(
|
||||
..
|
||||
} => {
|
||||
if specs.len() > 1 && !features.is_empty() {
|
||||
bail!("cannot specify features for more than one package");
|
||||
failure::bail!("cannot specify features for more than one package");
|
||||
}
|
||||
members.extend(
|
||||
ws.members()
|
||||
@ -243,7 +243,7 @@ pub fn resolve_with_previous<'cfg>(
|
||||
// into the resolution graph.
|
||||
if members.is_empty() {
|
||||
if !(features.is_empty() && !all_features && uses_default_features) {
|
||||
bail!("cannot specify features for packages outside of workspace");
|
||||
failure::bail!("cannot specify features for packages outside of workspace");
|
||||
}
|
||||
members.extend(ws.members());
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
|
||||
loop {
|
||||
let cfg = match self.cfgs.get(name) {
|
||||
Some(cfg) => cfg,
|
||||
None => bail!(
|
||||
None => failure::bail!(
|
||||
"could not find a configured source with the \
|
||||
name `{}` when attempting to lookup `{}` \
|
||||
(configuration in `{}`)",
|
||||
@ -107,7 +107,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
|
||||
}
|
||||
debug!("following pointer to {}", name);
|
||||
if name == orig_name {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"detected a cycle of `replace-with` sources, the source \
|
||||
`{}` is eventually replaced with itself \
|
||||
(configuration in `{}`)",
|
||||
@ -119,7 +119,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
|
||||
let new_src = new_id.load(self.config)?;
|
||||
let old_src = id.load(self.config)?;
|
||||
if !new_src.supports_checksums() && old_src.supports_checksums() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"\
|
||||
cannot replace `{orig}` with `{name}`, the source `{orig}` supports \
|
||||
checksums, but `{name}` does not
|
||||
@ -132,7 +132,7 @@ a lock file compatible with `{orig}` cannot be generated in this situation
|
||||
}
|
||||
|
||||
if old_src.requires_precise() && id.precise().is_none() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"\
|
||||
the source {orig} requires a lock file to be present first before it can be
|
||||
used against vendored source code
|
||||
@ -203,14 +203,14 @@ restore the source replacement configuration to continue the build
|
||||
|
||||
let mut srcs = srcs.into_iter();
|
||||
let src = srcs.next().ok_or_else(|| {
|
||||
format_err!(
|
||||
failure::format_err!(
|
||||
"no source URL specified for `source.{}`, need \
|
||||
either `registry` or `local-registry` defined",
|
||||
name
|
||||
)
|
||||
})?;
|
||||
if srcs.next().is_some() {
|
||||
bail!("more than one source URL specified for `source.{}`", name)
|
||||
failure::bail!("more than one source URL specified for `source.{}`", name)
|
||||
}
|
||||
|
||||
let mut replace_with = None;
|
||||
|
@ -155,7 +155,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
|
||||
.map(|p| &p.0)
|
||||
.cloned()
|
||||
.map(MaybePackage::Ready)
|
||||
.ok_or_else(|| format_err!("failed to find package with id: {}", id))
|
||||
.ok_or_else(|| failure::format_err!("failed to find package with id: {}", id))
|
||||
}
|
||||
|
||||
fn finish_download(&mut self, _id: PackageId, _data: Vec<u8>) -> CargoResult<Package> {
|
||||
@ -169,7 +169,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
|
||||
fn verify(&self, id: PackageId) -> CargoResult<()> {
|
||||
let (pkg, cksum) = match self.packages.get(&id) {
|
||||
Some(&(ref pkg, ref cksum)) => (pkg, cksum),
|
||||
None => bail!("failed to find entry for `{}` in directory source", id),
|
||||
None => failure::bail!("failed to find entry for `{}` in directory source", id),
|
||||
};
|
||||
|
||||
let mut buf = [0; 16 * 1024];
|
||||
@ -190,7 +190,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
|
||||
|
||||
let actual = hex::encode(h.finish());
|
||||
if &*actual != cksum {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"\
|
||||
the listed checksum of `{}` has changed:\n\
|
||||
expected: {}\n\
|
||||
|
@ -78,7 +78,7 @@ pub fn canonicalize_url(url: &Url) -> CargoResult<Url> {
|
||||
// cannot-be-a-base-urls are not supported
|
||||
// eg. github.com:rust-lang-nursery/rustfmt.git
|
||||
if url.cannot_be_a_base() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"invalid url `{}`: cannot-be-a-base-URLs are not supported",
|
||||
url
|
||||
)
|
||||
@ -162,7 +162,7 @@ impl<'cfg> Source for GitSource<'cfg> {
|
||||
let db_path = lock.parent().join("db").join(&self.ident);
|
||||
|
||||
if self.config.cli_unstable().offline && !db_path.exists() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"can't checkout from '{}': you are in the offline mode (-Z offline)",
|
||||
self.remote.url()
|
||||
);
|
||||
|
@ -221,7 +221,7 @@ impl GitReference {
|
||||
.chain_err(|| format!("failed to find branch `{}`", s))?;
|
||||
b.get()
|
||||
.target()
|
||||
.ok_or_else(|| format_err!("branch `{}` did not have a target", s))?
|
||||
.ok_or_else(|| failure::format_err!("branch `{}` did not have a target", s))?
|
||||
}
|
||||
GitReference::Rev(ref s) => {
|
||||
let obj = repo.revparse_single(s)?;
|
||||
@ -668,13 +668,13 @@ pub fn fetch(
|
||||
config: &Config,
|
||||
) -> CargoResult<()> {
|
||||
if config.frozen() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"attempting to update a git repository, but --frozen \
|
||||
was specified"
|
||||
)
|
||||
}
|
||||
if !config.network_allowed() {
|
||||
bail!("can't update a git repository in the offline mode")
|
||||
failure::bail!("can't update a git repository in the offline mode")
|
||||
}
|
||||
|
||||
// If we're fetching from GitHub, attempt GitHub's special fast path for
|
||||
|
@ -124,7 +124,7 @@ impl<'cfg> PathSource<'cfg> {
|
||||
p
|
||||
};
|
||||
Pattern::new(pattern)
|
||||
.map_err(|e| format_err!("could not parse glob pattern `{}`: {}", p, e))
|
||||
.map_err(|e| failure::format_err!("could not parse glob pattern `{}`: {}", p, e))
|
||||
};
|
||||
|
||||
let glob_exclude = pkg
|
||||
@ -178,7 +178,7 @@ impl<'cfg> PathSource<'cfg> {
|
||||
{
|
||||
Match::None => Ok(true),
|
||||
Match::Ignore(_) => Ok(false),
|
||||
Match::Whitelist(pattern) => Err(format_err!(
|
||||
Match::Whitelist(pattern) => Err(failure::format_err!(
|
||||
"exclude rules cannot start with `!`: {}",
|
||||
pattern.original()
|
||||
)),
|
||||
@ -189,7 +189,7 @@ impl<'cfg> PathSource<'cfg> {
|
||||
{
|
||||
Match::None => Ok(false),
|
||||
Match::Ignore(_) => Ok(true),
|
||||
Match::Whitelist(pattern) => Err(format_err!(
|
||||
Match::Whitelist(pattern) => Err(failure::format_err!(
|
||||
"include rules cannot start with `!`: {}",
|
||||
pattern.original()
|
||||
)),
|
||||
@ -377,9 +377,9 @@ impl<'cfg> PathSource<'cfg> {
|
||||
if is_dir.unwrap_or_else(|| file_path.is_dir()) {
|
||||
warn!(" found submodule {}", file_path.display());
|
||||
let rel = util::without_prefix(&file_path, root).unwrap();
|
||||
let rel = rel
|
||||
.to_str()
|
||||
.ok_or_else(|| format_err!("invalid utf-8 filename: {}", rel.display()))?;
|
||||
let rel = rel.to_str().ok_or_else(|| {
|
||||
failure::format_err!("invalid utf-8 filename: {}", rel.display())
|
||||
})?;
|
||||
// Git submodules are currently only named through `/` path
|
||||
// separators, explicitly not `\` which windows uses. Who knew?
|
||||
let rel = rel.replace(r"\", "/");
|
||||
|
@ -197,7 +197,7 @@ impl<'cfg> RegistryIndex<'cfg> {
|
||||
let err = load.load(&root, Path::new(&path), &mut |contents| {
|
||||
hit_closure = true;
|
||||
let contents = str::from_utf8(contents)
|
||||
.map_err(|_| format_err!("registry index file was not valid utf-8"))?;
|
||||
.map_err(|_| failure::format_err!("registry index file was not valid utf-8"))?;
|
||||
ret.reserve(contents.lines().count());
|
||||
let lines = contents.lines().map(|s| s.trim()).filter(|l| !l.is_empty());
|
||||
|
||||
|
@ -57,11 +57,11 @@ impl<'cfg> RegistryData for LocalRegistry<'cfg> {
|
||||
// these directories exist.
|
||||
let root = self.root.clone().into_path_unlocked();
|
||||
if !root.is_dir() {
|
||||
bail!("local registry path is not a directory: {}", root.display())
|
||||
failure::bail!("local registry path is not a directory: {}", root.display())
|
||||
}
|
||||
let index_path = self.index_path.clone().into_path_unlocked();
|
||||
if !index_path.is_dir() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"local registry index path is not a directory: {}",
|
||||
index_path.display()
|
||||
)
|
||||
@ -96,7 +96,7 @@ impl<'cfg> RegistryData for LocalRegistry<'cfg> {
|
||||
state.update(&buf[..n]);
|
||||
}
|
||||
if hex::encode(state.finish()) != checksum {
|
||||
bail!("failed to verify the checksum of `{}`", pkg)
|
||||
failure::bail!("failed to verify the checksum of `{}`", pkg)
|
||||
}
|
||||
|
||||
crate_file.seek(SeekFrom::Start(0))?;
|
||||
|
@ -450,7 +450,7 @@ impl<'cfg> RegistrySource<'cfg> {
|
||||
// crates.io should also block uploads with these sorts of tarballs,
|
||||
// but be extra sure by adding a check here as well.
|
||||
if !entry_path.starts_with(prefix) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"invalid tarball downloaded, contains \
|
||||
a file at {:?} which isn't under {:?}",
|
||||
entry_path,
|
||||
|
@ -154,7 +154,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
|
||||
let object = entry.to_object(repo)?;
|
||||
let blob = match object.as_blob() {
|
||||
Some(blob) => blob,
|
||||
None => bail!("path `{}` is not a blob in the git repo", path.display()),
|
||||
None => failure::bail!("path `{}` is not a blob in the git repo", path.display()),
|
||||
};
|
||||
data(blob.content())
|
||||
}
|
||||
@ -252,7 +252,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
|
||||
let mut state = Sha256::new();
|
||||
state.update(data);
|
||||
if hex::encode(state.finish()) != checksum {
|
||||
bail!("failed to verify the checksum of `{}`", pkg)
|
||||
failure::bail!("failed to verify the checksum of `{}`", pkg)
|
||||
}
|
||||
|
||||
let filename = self.filename(pkg);
|
||||
|
@ -44,7 +44,7 @@ impl FromStr for Cfg {
|
||||
let mut p = Parser::new(s);
|
||||
let e = p.cfg()?;
|
||||
if p.t.next().is_some() {
|
||||
bail!("malformed cfg value or key/value pair: `{}`", s)
|
||||
failure::bail!("malformed cfg value or key/value pair: `{}`", s)
|
||||
}
|
||||
Ok(e)
|
||||
}
|
||||
@ -91,7 +91,7 @@ impl FromStr for CfgExpr {
|
||||
let mut p = Parser::new(s);
|
||||
let e = p.expr()?;
|
||||
if p.t.next().is_some() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"can only have one cfg-expression, consider using all() or \
|
||||
any() explicitly"
|
||||
)
|
||||
@ -164,7 +164,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
Some(&Ok(..)) => self.cfg().map(CfgExpr::Value),
|
||||
Some(&Err(..)) => Err(self.t.next().unwrap().err().unwrap()),
|
||||
None => bail!(
|
||||
None => failure::bail!(
|
||||
"expected start of a cfg expression, \
|
||||
found nothing"
|
||||
),
|
||||
@ -177,9 +177,9 @@ impl<'a> Parser<'a> {
|
||||
let e = if self.r#try(&Token::Equals) {
|
||||
let val = match self.t.next() {
|
||||
Some(Ok(Token::String(s))) => s,
|
||||
Some(Ok(t)) => bail!("expected a string, found {}", t.classify()),
|
||||
Some(Ok(t)) => failure::bail!("expected a string, found {}", t.classify()),
|
||||
Some(Err(e)) => return Err(e),
|
||||
None => bail!("expected a string, found nothing"),
|
||||
None => failure::bail!("expected a string, found nothing"),
|
||||
};
|
||||
Cfg::KeyPair(name.to_string(), val.to_string())
|
||||
} else {
|
||||
@ -187,9 +187,9 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
Ok(e)
|
||||
}
|
||||
Some(Ok(t)) => bail!("expected identifier, found {}", t.classify()),
|
||||
Some(Ok(t)) => failure::bail!("expected identifier, found {}", t.classify()),
|
||||
Some(Err(e)) => Err(e),
|
||||
None => bail!("expected identifier, found nothing"),
|
||||
None => failure::bail!("expected identifier, found nothing"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,9 +205,9 @@ impl<'a> Parser<'a> {
|
||||
fn eat(&mut self, token: &Token<'a>) -> CargoResult<()> {
|
||||
match self.t.next() {
|
||||
Some(Ok(ref t)) if token == t => Ok(()),
|
||||
Some(Ok(t)) => bail!("expected {}, found {}", token.classify(), t.classify()),
|
||||
Some(Ok(t)) => failure::bail!("expected {}, found {}", token.classify(), t.classify()),
|
||||
Some(Err(e)) => Err(e),
|
||||
None => bail!("expected {}, but cfg expr ended", token.classify()),
|
||||
None => failure::bail!("expected {}, but cfg expr ended", token.classify()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,7 +229,7 @@ impl<'a> Iterator for Tokenizer<'a> {
|
||||
return Some(Ok(Token::String(&self.orig[start + 1..end])));
|
||||
}
|
||||
}
|
||||
return Some(Err(format_err!("unterminated string in cfg")));
|
||||
return Some(Err(failure::format_err!("unterminated string in cfg")));
|
||||
}
|
||||
Some((start, ch)) if is_ident_start(ch) => {
|
||||
while let Some(&(end, ch)) = self.s.peek() {
|
||||
@ -242,13 +242,13 @@ impl<'a> Iterator for Tokenizer<'a> {
|
||||
return Some(Ok(Token::Ident(&self.orig[start..])));
|
||||
}
|
||||
Some((_, ch)) => {
|
||||
return Some(Err(format_err!(
|
||||
return Some(Err(failure::format_err!(
|
||||
"unexpected character in \
|
||||
cfg `{}`, expected parens, \
|
||||
a comma, an identifier, or \
|
||||
a string",
|
||||
ch
|
||||
)))
|
||||
)));
|
||||
}
|
||||
None => return None,
|
||||
}
|
||||
|
@ -238,10 +238,10 @@ pub trait ArgMatchesExt {
|
||||
// but in this particular case we need it to fix #3586.
|
||||
let path = paths::normalize_path(&path);
|
||||
if !path.ends_with("Cargo.toml") {
|
||||
bail!("the manifest-path must be a path to a Cargo.toml file")
|
||||
failure::bail!("the manifest-path must be a path to a Cargo.toml file")
|
||||
}
|
||||
if fs::metadata(&path).is_err() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"manifest path `{}` does not exist",
|
||||
self._value_of("manifest-path").unwrap()
|
||||
)
|
||||
@ -299,7 +299,7 @@ pub trait ArgMatchesExt {
|
||||
build_config.release = self._is_present("release");
|
||||
build_config.build_plan = self._is_present("build-plan");
|
||||
if build_config.build_plan && !config.cli_unstable().unstable_options {
|
||||
Err(format_err!(
|
||||
Err(failure::format_err!(
|
||||
"`--build-plan` flag is unstable, pass `-Z unstable-options` to enable it"
|
||||
))?;
|
||||
};
|
||||
@ -365,7 +365,7 @@ pub trait ArgMatchesExt {
|
||||
match self._value_of("registry") {
|
||||
Some(registry) => {
|
||||
if !config.cli_unstable().unstable_options {
|
||||
return Err(format_err!(
|
||||
return Err(failure::format_err!(
|
||||
"registry option is an unstable feature and \
|
||||
requires -Zunstable-options to use."
|
||||
));
|
||||
|
@ -138,7 +138,7 @@ impl Config {
|
||||
let cwd =
|
||||
env::current_dir().chain_err(|| "couldn't get the current directory of the process")?;
|
||||
let homedir = homedir(&cwd).ok_or_else(|| {
|
||||
format_err!(
|
||||
failure::format_err!(
|
||||
"Cargo couldn't find your home directory. \
|
||||
This probably means that $HOME was not set."
|
||||
)
|
||||
@ -240,7 +240,7 @@ impl Config {
|
||||
let argv0 = env::args_os()
|
||||
.map(PathBuf::from)
|
||||
.next()
|
||||
.ok_or_else(|| format_err!("no argv[0]"))?;
|
||||
.ok_or_else(|| failure::format_err!("no argv[0]"))?;
|
||||
paths::resolve_executable(&argv0)
|
||||
}
|
||||
|
||||
@ -278,11 +278,11 @@ impl Config {
|
||||
// Note: This is used by RLS, not Cargo.
|
||||
pub fn set_values(&self, values: HashMap<String, ConfigValue>) -> CargoResult<()> {
|
||||
if self.values.borrow().is_some() {
|
||||
bail!("config values already found")
|
||||
failure::bail!("config values already found")
|
||||
}
|
||||
match self.values.fill(values) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(_) => bail!("could not fill values"),
|
||||
Err(_) => failure::bail!("could not fill values"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ impl Config {
|
||||
| CV::Boolean(_, ref path) => {
|
||||
let idx = key.split('.').take(i).fold(0, |n, s| n + s.len()) + i - 1;
|
||||
let key_so_far = &key[..idx];
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"expected table for configuration key `{}`, \
|
||||
but found {} in {}",
|
||||
key_so_far,
|
||||
@ -538,7 +538,7 @@ impl Config {
|
||||
|
||||
fn expected<T>(&self, ty: &str, key: &str, val: &CV) -> CargoResult<T> {
|
||||
val.expected(ty, key)
|
||||
.map_err(|e| format_err!("invalid configuration for key `{}`\n{}", key, e))
|
||||
.map_err(|e| failure::format_err!("invalid configuration for key `{}`\n{}", key, e))
|
||||
}
|
||||
|
||||
pub fn configure(
|
||||
@ -570,7 +570,7 @@ impl Config {
|
||||
// Can't pass both at the same time on the command line regardless
|
||||
// of configuration.
|
||||
(Some(true), _, Some(true)) => {
|
||||
bail!("cannot set both --verbose and --quiet");
|
||||
failure::bail!("cannot set both --verbose and --quiet");
|
||||
}
|
||||
|
||||
// Can't actually get `Some(false)` as a value from the command
|
||||
@ -661,11 +661,11 @@ impl Config {
|
||||
Some(index) => {
|
||||
let url = index.val.to_url()?;
|
||||
if url.password().is_some() {
|
||||
bail!("Registry URLs may not contain passwords");
|
||||
failure::bail!("Registry URLs may not contain passwords");
|
||||
}
|
||||
url
|
||||
}
|
||||
None => bail!("No index found for registry: `{}`", registry),
|
||||
None => failure::bail!("No index found for registry: `{}`", registry),
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -897,7 +897,7 @@ impl ConfigError {
|
||||
|
||||
fn expected(key: &str, expected: &str, found: &ConfigValue) -> ConfigError {
|
||||
ConfigError {
|
||||
error: format_err!(
|
||||
error: failure::format_err!(
|
||||
"`{}` expected {}, but found a {}",
|
||||
key,
|
||||
expected,
|
||||
@ -909,14 +909,14 @@ impl ConfigError {
|
||||
|
||||
fn missing(key: &str) -> ConfigError {
|
||||
ConfigError {
|
||||
error: format_err!("missing config key `{}`", key),
|
||||
error: failure::format_err!("missing config key `{}`", key),
|
||||
definition: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn with_key_context(self, key: &str, definition: Definition) -> ConfigError {
|
||||
ConfigError {
|
||||
error: format_err!("could not load config key `{}`: {}", key, self),
|
||||
error: failure::format_err!("could not load config key `{}`: {}", key, self),
|
||||
definition: Some(definition),
|
||||
}
|
||||
}
|
||||
@ -1379,7 +1379,7 @@ impl ConfigValue {
|
||||
val.into_iter()
|
||||
.map(|toml| match toml {
|
||||
toml::Value::String(val) => Ok((val, path.to_path_buf())),
|
||||
v => bail!("expected string but found {} in list", v.type_str()),
|
||||
v => failure::bail!("expected string but found {} in list", v.type_str()),
|
||||
})
|
||||
.collect::<CargoResult<_>>()?,
|
||||
path.to_path_buf(),
|
||||
@ -1394,7 +1394,7 @@ impl ConfigValue {
|
||||
.collect::<CargoResult<_>>()?,
|
||||
path.to_path_buf(),
|
||||
)),
|
||||
v => bail!(
|
||||
v => failure::bail!(
|
||||
"found TOML configuration value of unknown type `{}`",
|
||||
v.type_str()
|
||||
),
|
||||
@ -1455,7 +1455,7 @@ impl ConfigValue {
|
||||
"expected {}, but found {}",
|
||||
expected.desc(),
|
||||
found.desc()
|
||||
)))
|
||||
)));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -1519,7 +1519,7 @@ impl ConfigValue {
|
||||
}
|
||||
|
||||
fn expected<T>(&self, wanted: &str, key: &str) -> CargoResult<T> {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"expected a {}, but found a {} for `{}` in {}",
|
||||
wanted,
|
||||
self.desc(),
|
||||
|
@ -346,5 +346,5 @@ pub fn internal<S: fmt::Display>(error: S) -> failure::Error {
|
||||
}
|
||||
|
||||
fn _internal(error: &dyn fmt::Display) -> failure::Error {
|
||||
Internal::new(format_err!("{}", error)).into()
|
||||
Internal::new(failure::format_err!("{}", error)).into()
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub fn find_root_manifest_for_wd(cwd: &Path) -> CargoResult<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"could not find `{}` in `{}` or any parent directory",
|
||||
file,
|
||||
cwd.display()
|
||||
@ -27,6 +27,6 @@ pub fn find_project_manifest_exact(pwd: &Path, file: &str) -> CargoResult<PathBu
|
||||
if manifest.exists() {
|
||||
Ok(manifest)
|
||||
} else {
|
||||
bail!("Could not find `{}` in `{}`", file, pwd.display())
|
||||
failure::bail!("Could not find `{}` in `{}`", file, pwd.display())
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,10 @@ pub fn join_paths<T: AsRef<OsStr>>(paths: &[T], env: &str) -> CargoResult<OsStri
|
||||
};
|
||||
let paths = paths.iter().map(Path::new).collect::<Vec<_>>();
|
||||
let err = failure::Error::from(err);
|
||||
let explain = Internal::new(format_err!("failed to join path array: {:?}", paths));
|
||||
let explain = Internal::new(failure::format_err!(
|
||||
"failed to join path array: {:?}",
|
||||
paths
|
||||
));
|
||||
let err = failure::Error::from(err.context(explain));
|
||||
let more_explain = format!(
|
||||
"failed to join search paths together\n\
|
||||
@ -87,7 +90,7 @@ pub fn without_prefix<'a>(long_path: &'a Path, prefix: &'a Path) -> Option<&'a P
|
||||
|
||||
pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
|
||||
if exec.components().count() == 1 {
|
||||
let paths = env::var_os("PATH").ok_or_else(|| format_err!("no PATH"))?;
|
||||
let paths = env::var_os("PATH").ok_or_else(|| failure::format_err!("no PATH"))?;
|
||||
let candidates = env::split_paths(&paths).flat_map(|path| {
|
||||
let candidate = path.join(&exec);
|
||||
let with_exe = if env::consts::EXE_EXTENSION == "" {
|
||||
@ -105,7 +108,7 @@ pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
bail!("no executable for `{}` found in PATH", exec.display())
|
||||
failure::bail!("no executable for `{}` found in PATH", exec.display())
|
||||
} else {
|
||||
Ok(exec.canonicalize()?)
|
||||
}
|
||||
@ -114,7 +117,7 @@ pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
|
||||
pub fn read(path: &Path) -> CargoResult<String> {
|
||||
match String::from_utf8(read_bytes(path)?) {
|
||||
Ok(s) => Ok(s),
|
||||
Err(_) => bail!("path at `{}` was not valid utf-8", path.display()),
|
||||
Err(_) => failure::bail!("path at `{}` was not valid utf-8", path.display()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +195,10 @@ pub fn path2bytes(path: &Path) -> CargoResult<&[u8]> {
|
||||
pub fn path2bytes(path: &Path) -> CargoResult<&[u8]> {
|
||||
match path.as_os_str().to_str() {
|
||||
Some(s) => Ok(s.as_bytes()),
|
||||
None => Err(format_err!("invalid non-unicode path: {}", path.display())),
|
||||
None => Err(failure::format_err!(
|
||||
"invalid non-unicode path: {}",
|
||||
path.display()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +213,7 @@ pub fn bytes2path(bytes: &[u8]) -> CargoResult<PathBuf> {
|
||||
use std::str;
|
||||
match str::from_utf8(bytes) {
|
||||
Ok(s) => Ok(PathBuf::from(s)),
|
||||
Err(..) => Err(format_err!("invalid non-unicode path")),
|
||||
Err(..) => Err(failure::format_err!("invalid non-unicode path")),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,10 +340,10 @@ mod imp {
|
||||
|
||||
#[cfg(windows)]
|
||||
mod imp {
|
||||
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
|
||||
use winapi::um::consoleapi::SetConsoleCtrlHandler;
|
||||
use crate::util::{process_error, ProcessBuilder};
|
||||
use crate::CargoResult;
|
||||
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
|
||||
use winapi::um::consoleapi::SetConsoleCtrlHandler;
|
||||
|
||||
unsafe extern "system" fn ctrlc_handler(_: DWORD) -> BOOL {
|
||||
// Do nothing. Let the child process handle it.
|
||||
|
@ -261,7 +261,7 @@ fn rustc_fingerprint(path: &Path, rustup_rustc: &Path) -> CargoResult<u64> {
|
||||
.with_extension(env::consts::EXE_EXTENSION);
|
||||
paths::mtime(&real_rustc)?.hash(&mut hasher);
|
||||
}
|
||||
(true, _, _) => bail!("probably rustup rustc, but without rustup's env vars"),
|
||||
(true, _, _) => failure::bail!("probably rustup rustc, but without rustup's env vars"),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crypto_hash;
|
||||
use self::crypto_hash::{Algorithm, Hasher};
|
||||
use crypto_hash;
|
||||
use std::io::Write;
|
||||
|
||||
pub struct Sha256(Hasher);
|
||||
|
@ -15,7 +15,7 @@ impl<'a> ToSemver for &'a str {
|
||||
fn to_semver(self) -> CargoResult<Version> {
|
||||
match Version::parse(self) {
|
||||
Ok(v) => Ok(v),
|
||||
Err(..) => Err(format_err!("cannot parse '{}' as a semver", self)),
|
||||
Err(..) => Err(failure::format_err!("cannot parse '{}' as a semver", self)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,13 @@ pub trait ToUrl {
|
||||
|
||||
impl<'a> ToUrl for &'a str {
|
||||
fn to_url(self) -> CargoResult<Url> {
|
||||
Url::parse(self).map_err(|s| format_err!("invalid url `{}`: {}", self, s))
|
||||
Url::parse(self).map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ToUrl for &'a Path {
|
||||
fn to_url(self) -> CargoResult<Url> {
|
||||
Url::from_file_path(self).map_err(|()| format_err!("invalid path url `{}`", self.display()))
|
||||
Url::from_file_path(self)
|
||||
.map_err(|()| failure::format_err!("invalid path url `{}`", self.display()))
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ fn do_read_manifest(
|
||||
TomlManifest::to_real_manifest(&manifest, source_id, package_root, config)?;
|
||||
add_unused(manifest.warnings_mut());
|
||||
if !manifest.targets().iter().any(|t| !t.is_custom_build()) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"no targets specified in the manifest\n \
|
||||
either src/lib.rs, src/main.rs, a [lib] section, or \
|
||||
[[bin]] section must be present"
|
||||
@ -447,7 +447,7 @@ impl TomlProfile {
|
||||
"dev" | "release" => {}
|
||||
_ => {
|
||||
if self.overrides.is_some() || self.build_override.is_some() {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"Profile overrides may only be specified for \
|
||||
`dev` or `release` profile, not `{}`.",
|
||||
name
|
||||
@ -472,16 +472,16 @@ impl TomlProfile {
|
||||
|
||||
fn validate_override(&self) -> CargoResult<()> {
|
||||
if self.overrides.is_some() || self.build_override.is_some() {
|
||||
bail!("Profile overrides cannot be nested.");
|
||||
failure::bail!("Profile overrides cannot be nested.");
|
||||
}
|
||||
if self.panic.is_some() {
|
||||
bail!("`panic` may not be specified in a profile override.")
|
||||
failure::bail!("`panic` may not be specified in a profile override.")
|
||||
}
|
||||
if self.lto.is_some() {
|
||||
bail!("`lto` may not be specified in a profile override.")
|
||||
failure::bail!("`lto` may not be specified in a profile override.")
|
||||
}
|
||||
if self.rpath.is_some() {
|
||||
bail!("`rpath` may not be specified in a profile override.")
|
||||
failure::bail!("`rpath` may not be specified in a profile override.")
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -802,11 +802,11 @@ impl TomlManifest {
|
||||
let features = Features::new(&cargo_features, &mut warnings)?;
|
||||
|
||||
let project = me.project.as_ref().or_else(|| me.package.as_ref());
|
||||
let project = project.ok_or_else(|| format_err!("no `package` section found"))?;
|
||||
let project = project.ok_or_else(|| failure::format_err!("no `package` section found"))?;
|
||||
|
||||
let package_name = project.name.trim();
|
||||
if package_name.is_empty() {
|
||||
bail!("package name cannot be an empty string")
|
||||
failure::bail!("package name cannot be an empty string")
|
||||
}
|
||||
|
||||
for c in package_name.chars() {
|
||||
@ -816,7 +816,7 @@ impl TomlManifest {
|
||||
if c == '_' || c == '-' {
|
||||
continue;
|
||||
}
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"Invalid character `{}` in package name: `{}`",
|
||||
c,
|
||||
package_name
|
||||
@ -939,7 +939,7 @@ impl TomlManifest {
|
||||
let name = dep.name_in_toml();
|
||||
let prev = names_sources.insert(name.to_string(), dep.source_id());
|
||||
if prev.is_some() && prev != Some(dep.source_id()) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"Dependency '{}' has different source paths depending on the build \
|
||||
target. Each dependency must have a single canonical source path \
|
||||
irrespective of build target.",
|
||||
@ -994,7 +994,7 @@ impl TomlManifest {
|
||||
(None, root) => WorkspaceConfig::Member {
|
||||
root: root.cloned(),
|
||||
},
|
||||
(Some(..), Some(..)) => bail!(
|
||||
(Some(..), Some(..)) => failure::bail!(
|
||||
"cannot configure both `package.workspace` and \
|
||||
`[workspace]`, only one can be specified"
|
||||
),
|
||||
@ -1077,43 +1077,43 @@ impl TomlManifest {
|
||||
config: &Config,
|
||||
) -> CargoResult<(VirtualManifest, Vec<PathBuf>)> {
|
||||
if me.project.is_some() {
|
||||
bail!("virtual manifests do not define [project]");
|
||||
failure::bail!("virtual manifests do not define [project]");
|
||||
}
|
||||
if me.package.is_some() {
|
||||
bail!("virtual manifests do not define [package]");
|
||||
failure::bail!("virtual manifests do not define [package]");
|
||||
}
|
||||
if me.lib.is_some() {
|
||||
bail!("virtual manifests do not specify [lib]");
|
||||
failure::bail!("virtual manifests do not specify [lib]");
|
||||
}
|
||||
if me.bin.is_some() {
|
||||
bail!("virtual manifests do not specify [[bin]]");
|
||||
failure::bail!("virtual manifests do not specify [[bin]]");
|
||||
}
|
||||
if me.example.is_some() {
|
||||
bail!("virtual manifests do not specify [[example]]");
|
||||
failure::bail!("virtual manifests do not specify [[example]]");
|
||||
}
|
||||
if me.test.is_some() {
|
||||
bail!("virtual manifests do not specify [[test]]");
|
||||
failure::bail!("virtual manifests do not specify [[test]]");
|
||||
}
|
||||
if me.bench.is_some() {
|
||||
bail!("virtual manifests do not specify [[bench]]");
|
||||
failure::bail!("virtual manifests do not specify [[bench]]");
|
||||
}
|
||||
if me.dependencies.is_some() {
|
||||
bail!("virtual manifests do not specify [dependencies]");
|
||||
failure::bail!("virtual manifests do not specify [dependencies]");
|
||||
}
|
||||
if me.dev_dependencies.is_some() || me.dev_dependencies2.is_some() {
|
||||
bail!("virtual manifests do not specify [dev-dependencies]");
|
||||
failure::bail!("virtual manifests do not specify [dev-dependencies]");
|
||||
}
|
||||
if me.build_dependencies.is_some() || me.build_dependencies2.is_some() {
|
||||
bail!("virtual manifests do not specify [build-dependencies]");
|
||||
failure::bail!("virtual manifests do not specify [build-dependencies]");
|
||||
}
|
||||
if me.features.is_some() {
|
||||
bail!("virtual manifests do not specify [features]");
|
||||
failure::bail!("virtual manifests do not specify [features]");
|
||||
}
|
||||
if me.target.is_some() {
|
||||
bail!("virtual manifests do not specify [target]");
|
||||
failure::bail!("virtual manifests do not specify [target]");
|
||||
}
|
||||
if me.badges.is_some() {
|
||||
bail!("virtual manifests do not specify [badges]");
|
||||
failure::bail!("virtual manifests do not specify [badges]");
|
||||
}
|
||||
|
||||
let mut nested_paths = Vec::new();
|
||||
@ -1146,7 +1146,7 @@ impl TomlManifest {
|
||||
&config.exclude,
|
||||
)),
|
||||
None => {
|
||||
bail!("virtual manifests must be configured with [workspace]");
|
||||
failure::bail!("virtual manifests must be configured with [workspace]");
|
||||
}
|
||||
};
|
||||
Ok((
|
||||
@ -1157,7 +1157,7 @@ impl TomlManifest {
|
||||
|
||||
fn replace(&self, cx: &mut Context<'_, '_>) -> CargoResult<Vec<(PackageIdSpec, Dependency)>> {
|
||||
if self.patch.is_some() && self.replace.is_some() {
|
||||
bail!("cannot specify both [replace] and [patch]");
|
||||
failure::bail!("cannot specify both [replace] and [patch]");
|
||||
}
|
||||
let mut replace = Vec::new();
|
||||
for (spec, replacement) in self.replace.iter().flat_map(|x| x) {
|
||||
@ -1177,7 +1177,7 @@ impl TomlManifest {
|
||||
TomlDependency::Simple(..) => true,
|
||||
};
|
||||
if version_specified {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"replacements cannot specify a version \
|
||||
requirement, but found one for `{}`",
|
||||
spec
|
||||
@ -1187,7 +1187,7 @@ impl TomlManifest {
|
||||
let mut dep = replacement.to_dependency(spec.name(), cx, None)?;
|
||||
{
|
||||
let version = spec.version().ok_or_else(|| {
|
||||
format_err!(
|
||||
failure::format_err!(
|
||||
"replacements must specify a version \
|
||||
to replace, but `{}` does not",
|
||||
spec
|
||||
@ -1327,12 +1327,12 @@ impl DetailedTomlDependency {
|
||||
self.registry.as_ref(),
|
||||
self.registry_index.as_ref(),
|
||||
) {
|
||||
(Some(_), _, Some(_), _) | (Some(_), _, _, Some(_)) => bail!(
|
||||
(Some(_), _, Some(_), _) | (Some(_), _, _, Some(_)) => failure::bail!(
|
||||
"dependency ({}) specification is ambiguous. \
|
||||
Only one of `git` or `registry` is allowed.",
|
||||
name_in_toml
|
||||
),
|
||||
(_, _, Some(_), Some(_)) => bail!(
|
||||
(_, _, Some(_), Some(_)) => failure::bail!(
|
||||
"dependency ({}) specification is ambiguous. \
|
||||
Only one of `registry` or `registry-index` is allowed.",
|
||||
name_in_toml
|
||||
|
@ -54,7 +54,7 @@ pub fn targets(
|
||||
.package
|
||||
.as_ref()
|
||||
.or_else(|| manifest.project.as_ref())
|
||||
.ok_or_else(|| format_err!("manifest has no `package` (or `project`)"))?;
|
||||
.ok_or_else(|| failure::format_err!("manifest has no `package` (or `project`)"))?;
|
||||
|
||||
targets.extend(clean_bins(
|
||||
features,
|
||||
@ -101,7 +101,7 @@ pub fn targets(
|
||||
// processing the custom build script
|
||||
if let Some(custom_build) = manifest.maybe_custom_build(custom_build, package_root) {
|
||||
if metabuild.is_some() {
|
||||
bail!("cannot specify both `metabuild` and `build`");
|
||||
failure::bail!("cannot specify both `metabuild` and `build`");
|
||||
}
|
||||
let name = format!(
|
||||
"build-script-{}",
|
||||
@ -121,7 +121,7 @@ pub fn targets(
|
||||
let bdeps = manifest.build_dependencies.as_ref();
|
||||
for name in &metabuild.0 {
|
||||
if !bdeps.map_or(false, |bd| bd.contains_key(name)) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"metabuild package `{}` must be specified in `build-dependencies`",
|
||||
name
|
||||
);
|
||||
@ -151,7 +151,7 @@ fn clean_lib(
|
||||
if let Some(ref name) = lib.name {
|
||||
// XXX: other code paths dodge this validation
|
||||
if name.contains('-') {
|
||||
bail!("library target names cannot contain hyphens: {}", name)
|
||||
failure::bail!("library target names cannot contain hyphens: {}", name)
|
||||
}
|
||||
}
|
||||
Some(TomlTarget {
|
||||
@ -187,7 +187,7 @@ fn clean_lib(
|
||||
));
|
||||
legacy_path
|
||||
} else {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"can't find library `{}`, \
|
||||
rename file to `src/lib.rs` or specify lib.path",
|
||||
lib.name()
|
||||
@ -219,11 +219,13 @@ fn clean_lib(
|
||||
lib.name()
|
||||
));
|
||||
if kinds.len() > 1 {
|
||||
bail!("cannot mix `proc-macro` crate type with others");
|
||||
failure::bail!("cannot mix `proc-macro` crate type with others");
|
||||
}
|
||||
vec![LibKind::ProcMacro]
|
||||
}
|
||||
(_, Some(true), Some(true)) => bail!("lib.plugin and lib.proc-macro cannot both be true"),
|
||||
(_, Some(true), Some(true)) => {
|
||||
failure::bail!("lib.plugin and lib.proc-macro cannot both be true")
|
||||
}
|
||||
(Some(kinds), _, _) => kinds.iter().map(|s| s.into()).collect(),
|
||||
(None, Some(true), _) => vec![LibKind::Dylib],
|
||||
(None, _, Some(true)) => vec![LibKind::ProcMacro],
|
||||
@ -285,7 +287,7 @@ fn clean_bins(
|
||||
}
|
||||
|
||||
if compiler::is_bad_artifact_name(&name) {
|
||||
bail!("the binary target name `{}` is forbidden", name)
|
||||
failure::bail!("the binary target name `{}` is forbidden", name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,7 +310,7 @@ fn clean_bins(
|
||||
});
|
||||
let path = match path {
|
||||
Ok(path) => path,
|
||||
Err(e) => bail!("{}", e),
|
||||
Err(e) => failure::bail!("{}", e),
|
||||
};
|
||||
|
||||
let mut target =
|
||||
@ -724,10 +726,10 @@ fn validate_has_name(
|
||||
match target.name {
|
||||
Some(ref name) => {
|
||||
if name.trim().is_empty() {
|
||||
bail!("{} target names cannot be empty", target_kind_human)
|
||||
failure::bail!("{} target names cannot be empty", target_kind_human)
|
||||
}
|
||||
}
|
||||
None => bail!(
|
||||
None => failure::bail!(
|
||||
"{} target {}.name is required",
|
||||
target_kind_human,
|
||||
target_kind
|
||||
@ -742,7 +744,7 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
|
||||
let mut seen = HashSet::new();
|
||||
for name in targets.iter().map(|e| e.name()) {
|
||||
if !seen.insert(name.clone()) {
|
||||
bail!(
|
||||
failure::bail!(
|
||||
"found duplicate {target_kind} name {name}, \
|
||||
but all {target_kind} targets must have a unique name",
|
||||
target_kind = target_kind,
|
||||
|
@ -16,7 +16,7 @@ path = "lib.rs"
|
||||
[dependencies]
|
||||
curl = "0.4"
|
||||
failure = "0.1.1"
|
||||
serde = "1.0"
|
||||
serde = { version = "1.0", features = ['derive'] }
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
url = "1.0"
|
||||
|
@ -1,19 +1,15 @@
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(clippy::identity_op)] // used for vertical alignment
|
||||
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
use serde_json;
|
||||
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::io::Cursor;
|
||||
|
||||
use curl::easy::{Easy, List};
|
||||
use failure::bail;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use url::percent_encoding::{percent_encode, QUERY_ENCODE_SET};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, failure::Error>;
|
||||
|
@ -1096,7 +1096,7 @@ impl Execs {
|
||||
{}\n",
|
||||
e_line,
|
||||
a.join("\n")
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user