@@ -674,15 +674,6 @@ impl<'a> Parser<'a> {
674674 ) ;
675675 }
676676
677- // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
678- // there are unclosed angle brackets
679- if self . unmatched_angle_bracket_count > 0
680- && self . token . kind == TokenKind :: Eq
681- && expected. iter ( ) . any ( |tok| matches ! ( tok, TokenType :: Token ( TokenKind :: Gt ) ) )
682- {
683- err. span_label ( self . prev_token . span , "maybe try to close unmatched angle bracket" ) ;
684- }
685-
686677 let sp = if self . token == token:: Eof {
687678 // This is EOF; don't want to point at the following char, but rather the last token.
688679 self . prev_token . span
@@ -819,6 +810,7 @@ impl<'a> Parser<'a> {
819810 }
820811 err. emit ( ) ;
821812 }
813+
822814 fn check_too_many_raw_str_terminators ( & mut self , err : & mut Diagnostic ) -> bool {
823815 let sm = self . sess . source_map ( ) ;
824816 match ( & self . prev_token . kind , & self . token . kind ) {
@@ -1994,6 +1986,39 @@ impl<'a> Parser<'a> {
19941986 }
19951987 }
19961988
1989+ /// When trying to close a generics list and encountering code like
1990+ /// ```text
1991+ /// impl<S: Into<std::borrow::Cow<'static, str>> From<S> for Canonical {}
1992+ /// // ^ missing > here
1993+ /// ```
1994+ /// we provide a structured suggestion on the error from `expect_gt`.
1995+ pub ( super ) fn expect_gt_or_maybe_suggest_closing_generics (
1996+ & mut self ,
1997+ params : & [ ast:: GenericParam ] ,
1998+ ) -> PResult < ' a , ( ) > {
1999+ let Err ( mut err) = self . expect_gt ( ) else {
2000+ return Ok ( ( ) ) ;
2001+ } ;
2002+ // Attempt to find places where a missing `>` might belong.
2003+ if let [ .., ast:: GenericParam { bounds, .. } ] = params
2004+ && let Some ( poly) = bounds
2005+ . iter ( )
2006+ . filter_map ( |bound| match bound {
2007+ ast:: GenericBound :: Trait ( poly, _) => Some ( poly) ,
2008+ _ => None ,
2009+ } )
2010+ . last ( )
2011+ {
2012+ err. span_suggestion_verbose (
2013+ poly. span . shrink_to_hi ( ) ,
2014+ "you might have meant to end the type parameters here" ,
2015+ ">" ,
2016+ Applicability :: MaybeIncorrect ,
2017+ ) ;
2018+ }
2019+ Err ( err)
2020+ }
2021+
19972022 /// Recovers a situation like `for ( $pat in $expr )`
19982023 /// and suggest writing `for $pat in $expr` instead.
19992024 ///
0 commit comments