Skip to content

Commit 5bb3023

Browse files
committed
Auto merge of #6422 - dwijnand:more-rust-2018, r=alexcrichton
More Rust 2018 edition cleanups None
2 parents 9725a51 + 54c4214 commit 5bb3023

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+392
-371
lines changed

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
9797
match err {
9898
None => Ok(()),
9999
Some(err) => Err(match err.exit.as_ref().and_then(|e| e.code()) {
100-
Some(i) => CliError::new(format_err!("bench failed"), i),
100+
Some(i) => CliError::new(failure::format_err!("bench failed"), i),
101101
None => CliError::new(err.into(), 101),
102102
}),
103103
}

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5151
let mut compile_opts = args.compile_options(config, CompileMode::Build)?;
5252
compile_opts.export_dir = args.value_of_path("out-dir", config);
5353
if compile_opts.export_dir.is_some() && !config.cli_unstable().unstable_options {
54-
Err(format_err!(
54+
Err(failure::format_err!(
5555
"`--out-dir` flag is unstable, pass `-Z unstable-options` to enable it"
5656
))?;
5757
};

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5959
Some("test") => true,
6060
None => false,
6161
Some(profile) => {
62-
let err = format_err!(
62+
let err = failure::format_err!(
6363
"unknown profile: `{}`, only `test` is \
6464
currently supported",
6565
profile

src/bin/cargo/commands/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
110110
Some("test") => true,
111111
None => false,
112112
Some(profile) => {
113-
let err = format_err!(
113+
let err = failure::format_err!(
114114
"unknown profile: `{}`, only `test` is \
115115
currently supported",
116116
profile

src/bin/cargo/commands/locate_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
2020
let root = root
2121
.to_str()
2222
.ok_or_else(|| {
23-
format_err!(
23+
failure::format_err!(
2424
"your package path contains characters \
2525
not representable in Unicode"
2626
)

src/bin/cargo/commands/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
2626
None => {
2727
let host = match registry {
2828
Some(ref _registry) => {
29-
return Err(format_err!(
29+
return Err(failure::format_err!(
3030
"token must be provided when \
3131
--registry is provided."
3232
)

src/bin/cargo/commands/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5454
Some("bench") => CompileMode::Bench,
5555
Some("check") => CompileMode::Check { test: false },
5656
Some(mode) => {
57-
let err = format_err!(
57+
let err = failure::format_err!(
5858
"unknown profile: `{}`, use dev,
5959
test, or bench",
6060
mode

src/bin/cargo/commands/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
9898
if doc {
9999
if let CompileFilter::Only { .. } = compile_opts.filter {
100100
return Err(CliError::new(
101-
format_err!("Can't mix --doc with other target selecting options"),
101+
failure::format_err!("Can't mix --doc with other target selecting options"),
102102
101,
103103
));
104104
}
@@ -137,7 +137,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
137137
match err {
138138
None => Ok(()),
139139
Some(err) => Err(match err.exit.as_ref().and_then(|e| e.code()) {
140-
Some(i) => CliError::new(format_err!("{}", err.hint(&ws)), i),
140+
Some(i) => CliError::new(failure::format_err!("{}", err.hint(&ws)), i),
141141
None => CliError::new(err.into(), 101),
142142
}),
143143
}

src/bin/cargo/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#![allow(clippy::too_many_arguments)] // large project
33
#![allow(clippy::redundant_closure)] // there's a false positive
44

5-
#[macro_use]
6-
extern crate failure;
7-
85
use std::collections::BTreeSet;
96
use std::env;
107
use std::fs;
@@ -136,12 +133,12 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
136133
Some(command) => command,
137134
None => {
138135
let err = match find_closest(config, cmd) {
139-
Some(closest) => format_err!(
136+
Some(closest) => failure::format_err!(
140137
"no such subcommand: `{}`\n\n\tDid you mean `{}`?\n",
141138
cmd,
142139
closest
143140
),
144-
None => format_err!("no such subcommand: `{}`", cmd),
141+
None => failure::format_err!("no such subcommand: `{}`", cmd),
145142
};
146143
return Err(CliError::new(err, 101));
147144
}

src/cargo/core/compiler/build_config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ impl BuildConfig {
4848
) -> CargoResult<BuildConfig> {
4949
let requested_target = match requested_target {
5050
&Some(ref target) if target.ends_with(".json") => {
51-
let path = Path::new(target)
52-
.canonicalize()
53-
.chain_err(|| format_err!("Target path {:?} is not a valid file", target))?;
51+
let path = Path::new(target).canonicalize().chain_err(|| {
52+
failure::format_err!("Target path {:?} is not a valid file", target)
53+
})?;
5454
Some(
5555
path.into_os_string()
5656
.into_string()
57-
.map_err(|_| format_err!("Target path is not valid unicode"))?,
57+
.map_err(|_| failure::format_err!("Target path is not valid unicode"))?,
5858
)
5959
}
6060
other => other.clone(),
6161
};
6262
if let Some(ref s) = requested_target {
6363
if s.trim().is_empty() {
64-
bail!("target was empty")
64+
failure::bail!("target was empty")
6565
}
6666
}
6767
let cfg_target = config.get_string("build.target")?.map(|s| s.val);
6868
let target = requested_target.or(cfg_target);
6969

7070
if jobs == Some(0) {
71-
bail!("jobs must be at least 1")
71+
failure::bail!("jobs must be at least 1")
7272
}
7373
if jobs.is_some() && config.jobserver_from_env().is_some() {
7474
config.shell().warn(

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl TargetConfig {
276276
}
277277
}
278278
"warning" | "rerun-if-changed" | "rerun-if-env-changed" => {
279-
bail!("`{}` is not supported in build script overrides", k);
279+
failure::bail!("`{}` is not supported in build script overrides", k);
280280
}
281281
_ => {
282282
let val = value.string(k)?.0;

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl TargetInfo {
113113
if has_cfg_and_sysroot {
114114
let line = match lines.next() {
115115
Some(line) => line,
116-
None => bail!(
116+
None => failure::bail!(
117117
"output of --print=sysroot missing when learning about \
118118
target-specific information from rustc"
119119
),
@@ -270,7 +270,7 @@ fn parse_crate_type(
270270
}
271271
let line = match lines.next() {
272272
Some(line) => line,
273-
None => bail!(
273+
None => failure::bail!(
274274
"malformed output when learning about \
275275
crate-type {} information",
276276
crate_type
@@ -280,7 +280,7 @@ fn parse_crate_type(
280280
let prefix = parts.next().unwrap();
281281
let suffix = match parts.next() {
282282
Some(part) => part,
283-
None => bail!(
283+
None => failure::bail!(
284284
"output of --print=file-names has changed in \
285285
the compiler, cannot parse"
286286
),

src/cargo/core/compiler/build_plan.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ impl Invocation {
7474
self.program = cmd
7575
.get_program()
7676
.to_str()
77-
.ok_or_else(|| format_err!("unicode program string required"))?
77+
.ok_or_else(|| failure::format_err!("unicode program string required"))?
7878
.to_string();
7979
self.cwd = Some(cmd.get_cwd().unwrap().to_path_buf());
8080
for arg in cmd.get_args().iter() {
8181
self.args.push(
8282
arg.to_str()
83-
.ok_or_else(|| format_err!("unicode argument string required"))?
83+
.ok_or_else(|| failure::format_err!("unicode argument string required"))?
8484
.to_string(),
8585
);
8686
}
@@ -93,7 +93,7 @@ impl Invocation {
9393
var.clone(),
9494
value
9595
.to_str()
96-
.ok_or_else(|| format_err!("unicode environment value required"))?
96+
.ok_or_else(|| failure::format_err!("unicode environment value required"))?
9797
.to_string(),
9898
);
9999
}

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult<Option<(PathBuf, Vec
276276
if let Some(runner) = bcx.config.get_path_and_args(&key)? {
277277
// more than one match, error out
278278
if matching_runner.is_some() {
279-
bail!(
279+
failure::bail!(
280280
"several matching instances of `target.'cfg(..)'.runner` \
281281
in `.cargo/config`"
282282
)

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,15 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
341341
}
342342
if ret.is_empty() {
343343
if !unsupported.is_empty() {
344-
bail!(
344+
failure::bail!(
345345
"cannot produce {} for `{}` as the target `{}` \
346346
does not support these crate types",
347347
unsupported.join(", "),
348348
unit.pkg,
349349
bcx.target_triple()
350350
)
351351
}
352-
bail!(
352+
failure::bail!(
353353
"cannot compile `{}` as the target `{}` does not \
354354
support any of the output crate types",
355355
unit.pkg,

src/cargo/core/compiler/context/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
450450
self.package_cache
451451
.get(&id)
452452
.cloned()
453-
.ok_or_else(|| format_err!("failed to find {}", id))
453+
.ok_or_else(|| failure::format_err!("failed to find {}", id))
454454
}
455455

456456
/// Return the list of filenames read by cargo to generate the BuildContext
@@ -588,7 +588,7 @@ impl Links {
588588
dep_path_desc
589589
};
590590

591-
bail!(
591+
failure::bail!(
592592
"multiple packages link to native library `{}`, \
593593
but a native library can be linked only once\n\
594594
\n\
@@ -609,7 +609,7 @@ impl Links {
609609
.iter()
610610
.any(|t| t.is_custom_build())
611611
{
612-
bail!(
612+
failure::bail!(
613613
"package `{}` specifies that it links to `{}` but does not \
614614
have a custom build script",
615615
unit.pkg.package_id(),

src/cargo/core/compiler/custom_build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
339339
cmd.exec_with_output()
340340
};
341341
let output = output.map_err(|e| {
342-
format_err!(
342+
failure::format_err!(
343343
"failed to run custom build command for `{}`\n{}",
344344
pkg_name,
345345
e
@@ -468,7 +468,7 @@ impl BuildOutput {
468468
let (key, value) = match (key, value) {
469469
(Some(a), Some(b)) => (a, b.trim_end()),
470470
// line started with `cargo:` but didn't match `key=value`
471-
_ => bail!("Wrong output in {}: `{}`", whence, line),
471+
_ => failure::bail!("Wrong output in {}: `{}`", whence, line),
472472
};
473473

474474
// This will rewrite paths if the target directory has been moved.
@@ -517,15 +517,15 @@ impl BuildOutput {
517517
let (mut library_paths, mut library_links) = (Vec::new(), Vec::new());
518518
while let Some(flag) = flags_iter.next() {
519519
if flag != "-l" && flag != "-L" {
520-
bail!(
520+
failure::bail!(
521521
"Only `-l` and `-L` flags are allowed in {}: `{}`",
522522
whence,
523523
value
524524
)
525525
}
526526
let value = match flags_iter.next() {
527527
Some(v) => v,
528-
None => bail!(
528+
None => failure::bail!(
529529
"Flag in rustc-flags has no value in {}: `{}`",
530530
whence,
531531
value
@@ -536,7 +536,7 @@ impl BuildOutput {
536536
"-L" => library_paths.push(PathBuf::from(value)),
537537

538538
// was already checked above
539-
_ => bail!("only -l and -L flags are allowed"),
539+
_ => failure::bail!("only -l and -L flags are allowed"),
540540
};
541541
}
542542
Ok((library_paths, library_links))
@@ -548,7 +548,7 @@ impl BuildOutput {
548548
let val = iter.next();
549549
match (name, val) {
550550
(Some(n), Some(v)) => Ok((n.to_owned(), v.to_owned())),
551-
_ => bail!("Variable rustc-env has no value in {}: {}", whence, value),
551+
_ => failure::bail!("Variable rustc-env has no value in {}: {}", whence, value),
552552
}
553553
}
554554
}

0 commit comments

Comments
 (0)