@@ -2,14 +2,13 @@ use super::ty::AllowPlus;
2
2
use super :: TokenType ;
3
3
use super :: { BlockMode , Parser , PathStyle , Restrictions , SemiColonMode , SeqSep , TokenExpectType } ;
4
4
5
+ use rustc_ast as ast;
5
6
use rustc_ast:: ptr:: P ;
6
7
use rustc_ast:: token:: { self , Lit , LitKind , TokenKind } ;
7
8
use rustc_ast:: util:: parser:: AssocOp ;
8
- use rustc_ast:: {
9
- self as ast, AngleBracketedArg , AngleBracketedArgs , AnonConst , AttrVec , BinOpKind , BindingMode ,
10
- Block , BlockCheckMode , Expr , ExprKind , GenericArg , Item , ItemKind , Mutability , Param , Pat ,
11
- PatKind , Path , PathSegment , QSelf , Ty , TyKind ,
12
- } ;
9
+ use rustc_ast:: { AngleBracketedArg , AngleBracketedArgs , AnonConst , AttrVec } ;
10
+ use rustc_ast:: { BinOpKind , BindingMode , Block , BlockCheckMode , Expr , ExprKind , GenericArg , Item } ;
11
+ use rustc_ast:: { ItemKind , Mutability , Param , Pat , PatKind , Path , PathSegment , QSelf , Ty , TyKind } ;
13
12
use rustc_ast_pretty:: pprust;
14
13
use rustc_data_structures:: fx:: FxHashSet ;
15
14
use rustc_errors:: { pluralize, struct_span_err} ;
@@ -220,6 +219,7 @@ impl<'a> Parser<'a> {
220
219
edible : & [ TokenKind ] ,
221
220
inedible : & [ TokenKind ] ,
222
221
) -> PResult < ' a , bool /* recovered */ > {
222
+ debug ! ( "expected_one_of_not_found(edible: {:?}, inedible: {:?})" , edible, inedible) ;
223
223
fn tokens_to_string ( tokens : & [ TokenType ] ) -> String {
224
224
let mut i = tokens. iter ( ) ;
225
225
// This might be a sign we need a connect method on `Iterator`.
@@ -245,6 +245,7 @@ impl<'a> Parser<'a> {
245
245
. collect :: < Vec < _ > > ( ) ;
246
246
expected. sort_by_cached_key ( |x| x. to_string ( ) ) ;
247
247
expected. dedup ( ) ;
248
+
248
249
let expect = tokens_to_string ( & expected[ ..] ) ;
249
250
let actual = super :: token_descr ( & self . token ) ;
250
251
let ( msg_exp, ( label_sp, label_exp) ) = if expected. len ( ) > 1 {
@@ -270,6 +271,16 @@ impl<'a> Parser<'a> {
270
271
} ;
271
272
self . last_unexpected_token_span = Some ( self . token . span ) ;
272
273
let mut err = self . struct_span_err ( self . token . span , & msg_exp) ;
274
+
275
+ // Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
276
+ // there are unclosed angle brackets
277
+ if self . unmatched_angle_bracket_count > 0
278
+ && self . token . kind == TokenKind :: Eq
279
+ && expected. iter ( ) . any ( |tok| matches ! ( tok, TokenType :: Token ( TokenKind :: Gt ) ) )
280
+ {
281
+ err. span_label ( self . prev_token . span , "maybe try to close unmatched angle bracket" ) ;
282
+ }
283
+
273
284
let sp = if self . token == token:: Eof {
274
285
// This is EOF; don't want to point at the following char, but rather the last token.
275
286
self . prev_token . span
0 commit comments