Skip to content

Commit c734c32

Browse files
committed
Replace span suggestion with multipart
1 parent 4738ce4 commit c734c32

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,18 +2045,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20452045
// parentheses around it, perhaps the user meant to write `(expr,)` to
20462046
// build a tuple (issue #86100)
20472047
(ty::Tuple(_), _) if expected.tuple_fields().count() == 1 => {
2048-
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
2049-
let code_stripped = code
2050-
.strip_prefix('(')
2051-
.and_then(|s| s.strip_suffix(')'))
2052-
.unwrap_or(&code);
2053-
err.span_suggestion(
2054-
span,
2055-
"use a trailing comma to create a tuple with one element",
2056-
format!("({},)", code_stripped),
2057-
Applicability::MaybeIncorrect,
2058-
);
2059-
}
2048+
err.multipart_suggestion(
2049+
"use a trailing comma to create a tuple with one element",
2050+
vec![
2051+
(span.shrink_to_lo(), "(".into()),
2052+
(span.shrink_to_hi(), ",)".into()),
2053+
],
2054+
Applicability::MaybeIncorrect,
2055+
);
20602056
}
20612057
// If a character was expected and the found expression is a string literal
20622058
// containing a single character, perhaps the user meant to write `'c'` to

src/test/ui/consts/const-tup-index-span.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | const TUP: (usize,) = 5usize << 64;
99
help: use a trailing comma to create a tuple with one element
1010
|
1111
LL | const TUP: (usize,) = (5usize << 64,);
12-
| ~~~~~~~~~~~~~~~
12+
| + ++
1313

1414
error: aborting due to previous error
1515

src/test/ui/typeck/issue-84768.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | <F as FnOnce(&mut u8)>::call_once(f, 1)
1515
help: use a trailing comma to create a tuple with one element
1616
|
1717
LL | <F as FnOnce(&mut u8)>::call_once(f, (1,))
18-
| ~~~~
18+
| + ++
1919

2020
error: aborting due to 2 previous errors
2121

0 commit comments

Comments
 (0)