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,16 +2046,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
// build a tuple (issue #86100)
|
||||
(ty::Tuple(_), _) if expected.tuple_fields().count() == 1 => {
|
||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
|
||||
if let Some(code) =
|
||||
code.strip_prefix('(').and_then(|s| s.strip_suffix(')'))
|
||||
{
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"use a trailing comma to create a tuple with one element",
|
||||
format!("({},)", code),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
let code_stripped = code
|
||||
.strip_prefix('(')
|
||||
.and_then(|s| s.strip_suffix(')'))
|
||||
.unwrap_or(&code);
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"use a trailing comma to create a tuple with one element",
|
||||
format!("({},)", code_stripped),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
}
|
||||
// If a character was expected and the found expression is a string literal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue