@@ -2960,13 +2960,30 @@ impl<'a> Parser<'a> {
29602960 let parser_snapshot_before_ty = this. create_snapshot_for_diagnostic ( ) ;
29612961 this. eat_incorrect_doc_comment_for_param_type ( ) ;
29622962 let mut ty = this. parse_ty_for_param ( ) ;
2963- if ty. is_ok ( )
2964- && this. token != token:: Comma
2965- && this. token != token:: CloseDelim ( Delimiter :: Parenthesis )
2966- {
2967- // This wasn't actually a type, but a pattern looking like a type,
2968- // so we are going to rollback and re-parse for recovery.
2969- ty = this. unexpected_any ( ) ;
2963+
2964+ if let Ok ( t) = & ty {
2965+ // Check for trailing angle brackets
2966+ if let TyKind :: Path ( _, Path { segments, .. } ) = & t. kind {
2967+ if let Some ( segment) = segments. last ( ) {
2968+ if let Some ( guar) =
2969+ this. check_trailing_angle_brackets ( segment, & [ exp ! ( CloseParen ) ] )
2970+ {
2971+ return Ok ( (
2972+ dummy_arg ( segment. ident , guar) ,
2973+ Trailing :: No ,
2974+ UsePreAttrPos :: No ,
2975+ ) ) ;
2976+ }
2977+ }
2978+ }
2979+
2980+ if this. token != token:: Comma
2981+ && this. token != token:: CloseDelim ( Delimiter :: Parenthesis )
2982+ {
2983+ // This wasn't actually a type, but a pattern looking like a type,
2984+ // so we are going to rollback and re-parse for recovery.
2985+ ty = this. unexpected_any ( ) ;
2986+ }
29702987 }
29712988 match ty {
29722989 Ok ( ty) => {
@@ -2977,6 +2994,7 @@ impl<'a> Parser<'a> {
29772994 }
29782995 // If this is a C-variadic argument and we hit an error, return the error.
29792996 Err ( err) if this. token == token:: DotDotDot => return Err ( err) ,
2997+ Err ( err) if this. unmatched_angle_bracket_count > 0 => return Err ( err) ,
29802998 // Recover from attempting to parse the argument as a type without pattern.
29812999 Err ( err) => {
29823000 err. cancel ( ) ;
0 commit comments