@@ -23,7 +23,7 @@ use crate::parser;
2323use crate :: parser:: attr:: InnerAttrPolicy ;
2424use rustc_ast as ast;
2525use rustc_ast:: ptr:: P ;
26- use rustc_ast:: token:: { self , Delimiter , Lit , LitKind , TokenKind } ;
26+ use rustc_ast:: token:: { self , Delimiter , Lit , LitKind , Token , TokenKind } ;
2727use rustc_ast:: tokenstream:: AttrTokenTree ;
2828use rustc_ast:: util:: parser:: AssocOp ;
2929use rustc_ast:: {
@@ -35,7 +35,7 @@ use rustc_ast_pretty::pprust;
3535use rustc_data_structures:: fx:: FxHashSet ;
3636use rustc_errors:: {
3737 pluralize, AddToDiagnostic , Applicability , DiagCtxt , Diagnostic , DiagnosticBuilder , FatalError ,
38- PResult ,
38+ PErr , PResult ,
3939} ;
4040use rustc_session:: errors:: ExprParenthesesNeeded ;
4141use rustc_span:: source_map:: Spanned ;
@@ -448,11 +448,16 @@ impl<'a> Parser<'a> {
448448 } )
449449 }
450450
451- let mut expected = edible
451+ self . expected_tokens . extend (
452+ edible
453+ . iter ( )
454+ . map ( |x| TokenType :: Token ( x. clone ( ) ) )
455+ . chain ( inedible. iter ( ) . map ( |x| TokenType :: Token ( x. clone ( ) ) ) ) ,
456+ ) ;
457+ let mut expected = self
458+ . expected_tokens
452459 . iter ( )
453- . map ( |x| TokenType :: Token ( x. clone ( ) ) )
454- . chain ( inedible. iter ( ) . map ( |x| TokenType :: Token ( x. clone ( ) ) ) )
455- . chain ( self . expected_tokens . iter ( ) . cloned ( ) )
460+ . cloned ( )
456461 . filter_map ( |token| {
457462 // filter out suggestions which suggest the same token which was found and deemed incorrect
458463 fn is_ident_eq_keyword ( found : & TokenKind , expected : & TokenType ) -> bool {
@@ -2907,6 +2912,22 @@ impl<'a> Parser<'a> {
29072912 Ok ( ( ) )
29082913 }
29092914
2915+ /// Check for exclusive ranges written as `..<`
2916+ pub ( crate ) fn maybe_err_dotdotlt_syntax ( & self , maybe_lt : Token , mut err : PErr < ' a > ) -> PErr < ' a > {
2917+ if maybe_lt == token:: Lt
2918+ && ( self . expected_tokens . contains ( & TokenType :: Token ( token:: Gt ) )
2919+ || matches ! ( self . token. kind, token:: Literal ( ..) ) )
2920+ {
2921+ err. span_suggestion (
2922+ maybe_lt. span ,
2923+ "remove the `<` to write an exclusive range" ,
2924+ "" ,
2925+ Applicability :: MachineApplicable ,
2926+ ) ;
2927+ }
2928+ err
2929+ }
2930+
29102931 pub fn is_diff_marker ( & mut self , long_kind : & TokenKind , short_kind : & TokenKind ) -> bool {
29112932 ( 0 ..3 ) . all ( |i| self . look_ahead ( i, |tok| tok == long_kind) )
29122933 && self . look_ahead ( 3 , |tok| tok == short_kind)
0 commit comments