mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Address review feedback
* Fix typo * Handle None value instead of using `unwrap()` * `pop()` instead of `x.truncate(x.len() - 1)`
This commit is contained in:
parent
5f007a88b4
commit
9a6216ed05
1 changed files with 52 additions and 26 deletions
|
@ -83,12 +83,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
};
|
};
|
||||||
|
|
||||||
// We need to remove the last trailing newline from the string because the
|
// We need to remove the last trailing newline from the string because the
|
||||||
// underlying `fmt::write` function doesn't know wether `println!` or `print!` was
|
// underlying `fmt::write` function doesn't know whether `println!` or `print!` was
|
||||||
// used.
|
// used.
|
||||||
let mut write_output: String = write_output_string(write_args).unwrap();
|
if let Some(mut write_output) = write_output_string(write_args) {
|
||||||
if write_output.ends_with('\n') {
|
if write_output.ends_with('\n') {
|
||||||
write_output.truncate(write_output.len() - 1)
|
write_output.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(macro_name) = calling_macro {
|
if let Some(macro_name) = calling_macro {
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
@ -112,6 +113,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
format!("{}print!(\"{}\")", prefix, write_output.escape_default())
|
format!("{}print!(\"{}\")", prefix, write_output.escape_default())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// We don't have a proper suggestion
|
||||||
|
if let Some(macro_name) = calling_macro {
|
||||||
|
span_lint(
|
||||||
|
cx,
|
||||||
|
EXPLICIT_WRITE,
|
||||||
|
expr.span,
|
||||||
|
&format!(
|
||||||
|
"use of `{}!({}(), ...).unwrap()`. Consider using `{}{}!` instead",
|
||||||
|
macro_name,
|
||||||
|
dest_name,
|
||||||
|
prefix,
|
||||||
|
macro_name.replace("write", "print")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
span_lint(
|
||||||
|
cx,
|
||||||
|
EXPLICIT_WRITE,
|
||||||
|
expr.span,
|
||||||
|
&format!("use of `{}().write_fmt(...).unwrap()`. Consider using `{}print!` instead", dest_name, prefix),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue