Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 43cc63e

Browse files
committed
Simplify some .context() calls
1 parent 7d83fdf commit 43cc63e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

cargo-fix/src/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn cargo_fix() -> Result<(), Error> {
5353
// Override the rustc compiler as ourselves. That way whenever rustc would
5454
// run we run instead and have an opportunity to inject fixes.
5555
let me = env::current_exe()
56-
.with_context(|_| "failed to learn about path to current exe")?;
56+
.context("failed to learn about path to current exe")?;
5757
cmd.env("RUSTC", &me)
5858
.env("__CARGO_FIX_NOW_RUSTC", "1");
5959
if let Some(rustc) = env::var_os("RUSTC") {
@@ -100,8 +100,7 @@ fn cargo_fix_rustc() -> Result<(), Error> {
100100
// we applied, present a scary warning, and then move on.
101101
let mut cmd = Command::new(&rustc);
102102
cmd.args(env::args().skip(1));
103-
exit_with(cmd.status().with_context(|_| "failed to spawn rustc")?);
104-
103+
exit_with(cmd.status().context("failed to spawn rustc")?);
105104
}
106105

107106
fn rustfix_crate(rustc: &Path, filename: &str) -> Result<(), Error> {
@@ -121,15 +120,16 @@ fn rustfix_crate(rustc: &Path, filename: &str) -> Result<(), Error> {
121120
let mut cmd = Command::new(&rustc);
122121
cmd.args(env::args().skip(1));
123122
cmd.arg("--error-format=json");
124-
let context = format!("failed to execute `{}`", rustc.to_string_lossy());
125-
let output = cmd.output().context(context.clone())?;
123+
let output = cmd.output()
124+
.with_context(|_| format!("failed to execute `{}`", rustc.display()))?;
126125

127126
// Sift through the output of the compiler to look for JSON messages
128127
// indicating fixes that we can apply. Note that we *do not* look at the
129128
// exit status here, that's intentional! We want to apply fixes even if
130129
// there are compiler errors.
131130
let stderr = str::from_utf8(&output.stderr)
132-
.map_err(|_| format_err!("failed to parse rustc stderr as utf-8"))?;
131+
.context("failed to parse rustc stderr as utf-8")?;
132+
133133
let suggestions = stderr.lines()
134134
.filter(|x| !x.is_empty())
135135

0 commit comments

Comments
 (0)