Skip to content

Commit

Permalink
Auto merge of #6422 - dwijnand:more-rust-2018, r=alexcrichton
Browse files Browse the repository at this point in the history
More Rust 2018 edition cleanups

None
  • Loading branch information
bors committed Dec 13, 2018
2 parents 9725a51 + 54c4214 commit 5bb3023
Show file tree
Hide file tree
Showing 79 changed files with 392 additions and 371 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))?;
};
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/locate_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}
Expand Down Expand Up @@ -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),
}),
}
Expand Down
7 changes: 2 additions & 5 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
12 changes: 6 additions & 6 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand Down Expand Up @@ -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
Expand All @@ -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"
),
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/build_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
Expand All @@ -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(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
)
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ 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(", "),
unit.pkg,
bcx.target_triple()
)
}
bail!(
failure::bail!(
"cannot compile `{}` as the target `{}` does not \
support any of the output crate types",
unit.pkg,
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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\
Expand All @@ -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(),
Expand Down
12 changes: 6 additions & 6 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -517,15 +517,15 @@ 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
)
}
let value = match flags_iter.next() {
Some(v) => v,
None => bail!(
None => failure::bail!(
"Flag in rustc-flags has no value in {}: `{}`",
whence,
value
Expand All @@ -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))
Expand All @@ -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),
}
}
}
Expand Down
Loading

0 comments on commit 5bb3023

Please sign in to comment.