Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0f69caf

Browse files
committed
Rework suggestion generation and use multipart_suggestion again
1 parent a1a1a4b commit 0f69caf

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

clippy_lints/src/types.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -794,32 +794,43 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
794794
if !args_to_recover.is_empty() {
795795
let mut applicability = Applicability::MachineApplicable;
796796
span_lint_and_then(cx, UNIT_ARG, expr.span, "passing a unit value to a function", |db| {
797+
let sugg = args_to_recover
798+
.iter()
799+
.enumerate()
800+
.map(|(i, arg)| {
801+
let indent = if i == 0 {
802+
0
803+
} else {
804+
indent_of(cx, expr.span).unwrap_or(0)
805+
};
806+
format!(
807+
"{}{};",
808+
" ".repeat(indent),
809+
snippet_block_with_applicability(
810+
cx,
811+
arg.span,
812+
"..",
813+
Some(expr.span),
814+
&mut applicability
815+
)
816+
)
817+
})
818+
.collect::<Vec<String>>()
819+
.join("\n");
797820
db.span_suggestion(
798821
expr.span.with_hi(expr.span.lo()),
799-
"move the expressions in front of the call...",
800-
format!(
801-
"{} ",
802-
args_to_recover
803-
.iter()
804-
.map(|arg| {
805-
format!(
806-
"{};",
807-
snippet_with_applicability(cx, arg.span, "..", &mut applicability)
808-
)
809-
})
810-
.collect::<Vec<String>>()
811-
.join(" ")
812-
),
822+
&format!("{}move the expressions in front of the call...", or),
823+
format!("{}\n", sugg),
824+
applicability,
825+
);
826+
db.multipart_suggestion(
827+
"...and use unit literals instead",
828+
args_to_recover
829+
.iter()
830+
.map(|arg| (arg.span, "()".to_string()))
831+
.collect::<Vec<_>>(),
813832
applicability,
814833
);
815-
for arg in args_to_recover {
816-
db.span_suggestion(
817-
arg.span,
818-
"...and use unit literals instead",
819-
"()".to_string(),
820-
applicability,
821-
);
822-
}
823834
});
824835
}
825836
},

0 commit comments

Comments
 (0)