mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 17:28:07 +00:00
Rework suggestion generation and use multipart_suggestion again
This commit is contained in:
parent
a1a1a4b82a
commit
0f69cafc2d
1 changed files with 33 additions and 22 deletions
|
@ -794,32 +794,43 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
|||
if !args_to_recover.is_empty() {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
span_lint_and_then(cx, UNIT_ARG, expr.span, "passing a unit value to a function", |db| {
|
||||
db.span_suggestion(
|
||||
expr.span.with_hi(expr.span.lo()),
|
||||
"move the expressions in front of the call...",
|
||||
format!(
|
||||
"{} ",
|
||||
args_to_recover
|
||||
let sugg = args_to_recover
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
.enumerate()
|
||||
.map(|(i, arg)| {
|
||||
let indent = if i == 0 {
|
||||
0
|
||||
} else {
|
||||
indent_of(cx, expr.span).unwrap_or(0)
|
||||
};
|
||||
format!(
|
||||
"{};",
|
||||
snippet_with_applicability(cx, arg.span, "..", &mut applicability)
|
||||
"{}{};",
|
||||
" ".repeat(indent),
|
||||
snippet_block_with_applicability(
|
||||
cx,
|
||||
arg.span,
|
||||
"..",
|
||||
Some(expr.span),
|
||||
&mut applicability
|
||||
)
|
||||
)
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join(" ")
|
||||
),
|
||||
applicability,
|
||||
);
|
||||
for arg in args_to_recover {
|
||||
.join("\n");
|
||||
db.span_suggestion(
|
||||
arg.span,
|
||||
"...and use unit literals instead",
|
||||
"()".to_string(),
|
||||
expr.span.with_hi(expr.span.lo()),
|
||||
&format!("{}move the expressions in front of the call...", or),
|
||||
format!("{}\n", sugg),
|
||||
applicability,
|
||||
);
|
||||
db.multipart_suggestion(
|
||||
"...and use unit literals instead",
|
||||
args_to_recover
|
||||
.iter()
|
||||
.map(|arg| (arg.span, "()".to_string()))
|
||||
.collect::<Vec<_>>(),
|
||||
applicability,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue