Suggest 1-tuple parentheses, without existing parens
This commit is contained in:
parent
427eba2f0b
commit
4738ce463e
3 changed files with 18 additions and 10 deletions
|
@ -2046,18 +2046,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
// build a tuple (issue #86100)
|
// build a tuple (issue #86100)
|
||||||
(ty::Tuple(_), _) if expected.tuple_fields().count() == 1 => {
|
(ty::Tuple(_), _) if expected.tuple_fields().count() == 1 => {
|
||||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
|
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
|
||||||
if let Some(code) =
|
let code_stripped = code
|
||||||
code.strip_prefix('(').and_then(|s| s.strip_suffix(')'))
|
.strip_prefix('(')
|
||||||
{
|
.and_then(|s| s.strip_suffix(')'))
|
||||||
|
.unwrap_or(&code);
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"use a trailing comma to create a tuple with one element",
|
"use a trailing comma to create a tuple with one element",
|
||||||
format!("({},)", code),
|
format!("({},)", code_stripped),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// If a character was expected and the found expression is a string literal
|
// If a character was expected and the found expression is a string literal
|
||||||
// containing a single character, perhaps the user meant to write `'c'` to
|
// containing a single character, perhaps the user meant to write `'c'` to
|
||||||
// specify a character literal (issue #92479)
|
// specify a character literal (issue #92479)
|
||||||
|
|
|
@ -6,6 +6,10 @@ LL | const TUP: (usize,) = 5usize << 64;
|
||||||
|
|
|
|
||||||
= note: expected tuple `(usize,)`
|
= note: expected tuple `(usize,)`
|
||||||
found type `usize`
|
found type `usize`
|
||||||
|
help: use a trailing comma to create a tuple with one element
|
||||||
|
|
|
||||||
|
LL | const TUP: (usize,) = (5usize << 64,);
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ LL | <F as FnOnce(&mut u8)>::call_once(f, 1)
|
||||||
|
|
|
|
||||||
= note: expected tuple `(&mut u8,)`
|
= note: expected tuple `(&mut u8,)`
|
||||||
found type `{integer}`
|
found type `{integer}`
|
||||||
|
help: use a trailing comma to create a tuple with one element
|
||||||
|
|
|
||||||
|
LL | <F as FnOnce(&mut u8)>::call_once(f, (1,))
|
||||||
|
| ~~~~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue