diff options
| author | Esteban Kuber <esteban@kuber.com.ar> | 2022-03-01 19:40:48 +0000 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2022-03-27 02:50:04 +0000 |
| commit | 6874bd27f527b6c5f40e8fd866d91813da2df35a (patch) | |
| tree | 53b50c5b05c6d6fe279ace2f35b583b532d33bc5 /compiler/rustc_parse/src/parser | |
| parent | 3fe3b89cd57229343eeca753fdd8c63d9b03c65c (diff) | |
| download | rust-6874bd27f527b6c5f40e8fd866d91813da2df35a.tar.gz rust-6874bd27f527b6c5f40e8fd866d91813da2df35a.zip | |
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.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 07ce879de8f..596099bf2de 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -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 { |
