From 6874bd27f527b6c5f40e8fd866d91813da2df35a Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Tue, 1 Mar 2022 19:40:48 +0000 Subject: 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. --- compiler/rustc_parse/src/parser/path.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_parse/src/parser') 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 { -- cgit 1.4.1-3-g733a5