1
Fork 0

Merge duplicate suggestion string

This commit is contained in:
Rob Pilling 2022-02-02 22:22:13 +00:00
parent 344ea6e0e5
commit 82a012299d

View file

@ -2125,22 +2125,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
else { return }; else { return };
let msg = "use a trailing comma to create a tuple with one element";
if code.starts_with('(') && code.ends_with(')') { if code.starts_with('(') && code.ends_with(')') {
let before_close = span.hi() - BytePos::from_u32(1); let before_close = span.hi() - BytePos::from_u32(1);
err.span_suggestion( err.span_suggestion(
span.with_hi(before_close).shrink_to_hi(), span.with_hi(before_close).shrink_to_hi(),
"use a trailing comma to create a tuple with one element", msg,
",".into(), ",".into(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else { } else {
err.multipart_suggestion( err.multipart_suggestion(
"use a trailing comma to create a tuple with one element", msg,
vec![ vec![(span.shrink_to_lo(), "(".into()), (span.shrink_to_hi(), ",)".into())],
(span.shrink_to_lo(), "(".into()),
(span.shrink_to_hi(), ",)".into()),
],
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} }