Provide suggestion for missing >
in a type parameter list
When encountering an inproperly terminated type parameter list, provide a suggestion to close it after the last non-constraint type parameter that was successfully parsed. Fix #94058.
This commit is contained in:
parent
3fe3b89cd5
commit
6874bd27f5
18 changed files with 175 additions and 10 deletions
|
@ -272,7 +272,23 @@ impl<'a> Parser<'a> {
|
|||
lo,
|
||||
ty_generics,
|
||||
)?;
|
||||
self.expect_gt()?;
|
||||
self.expect_gt().map_err(|mut err| {
|
||||
// Attempt to find places where a missing `>` might belong.
|
||||
if let Some(arg) = args
|
||||
.iter()
|
||||
.rev()
|
||||
.skip_while(|arg| matches!(arg, AngleBracketedArg::Constraint(_)))
|
||||
.next()
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
arg.span().shrink_to_hi(),
|
||||
"you might have meant to end the type parameters here",
|
||||
">".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
err
|
||||
})?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
AngleBracketedArgs { args, span }.into()
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue