@@ -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,12 +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- . chain ( inedible)
454460 . cloned ( )
455- . map ( TokenType :: Token )
456- . chain ( self . expected_tokens . iter ( ) . cloned ( ) )
457461 . filter ( |token| {
458462 // Filter out suggestions that suggest the same token which was found and deemed incorrect.
459463 fn is_ident_eq_keyword ( found : & TokenKind , expected : & TokenType ) -> bool {
@@ -2929,6 +2933,22 @@ impl<'a> Parser<'a> {
29292933 Ok ( ( ) )
29302934 }
29312935
2936+ /// Check for exclusive ranges written as `..<`
2937+ pub ( crate ) fn maybe_err_dotdotlt_syntax ( & self , maybe_lt : Token , mut err : PErr < ' a > ) -> PErr < ' a > {
2938+ if maybe_lt == token:: Lt
2939+ && ( self . expected_tokens . contains ( & TokenType :: Token ( token:: Gt ) )
2940+ || matches ! ( self . token. kind, token:: Literal ( ..) ) )
2941+ {
2942+ err. span_suggestion (
2943+ maybe_lt. span ,
2944+ "remove the `<` to write an exclusive range" ,
2945+ "" ,
2946+ Applicability :: MachineApplicable ,
2947+ ) ;
2948+ }
2949+ err
2950+ }
2951+
29322952 pub fn is_diff_marker ( & mut self , long_kind : & TokenKind , short_kind : & TokenKind ) -> bool {
29332953 ( 0 ..3 ) . all ( |i| self . look_ahead ( i, |tok| tok == long_kind) )
29342954 && self . look_ahead ( 3 , |tok| tok == short_kind)
0 commit comments