@@ -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:: {
@@ -448,12 +448,11 @@ impl<'a> Parser<'a> {
448448 } )
449449 }
450450
451- let mut expected = edible
451+ self . expected_tokens . extend ( edible. iter ( ) . chain ( inedible) . cloned ( ) . map ( TokenType :: Token ) ) ;
452+ let mut expected = self
453+ . expected_tokens
452454 . iter ( )
453- . chain ( inedible)
454455 . cloned ( )
455- . map ( TokenType :: Token )
456- . chain ( self . expected_tokens . iter ( ) . cloned ( ) )
457456 . filter ( |token| {
458457 // Filter out suggestions that suggest the same token which was found and deemed incorrect.
459458 fn is_ident_eq_keyword ( found : & TokenKind , expected : & TokenType ) -> bool {
@@ -2927,6 +2926,22 @@ impl<'a> Parser<'a> {
29272926 Ok ( ( ) )
29282927 }
29292928
2929+ /// Check for exclusive ranges written as `..<`
2930+ pub ( crate ) fn maybe_err_dotdotlt_syntax ( & self , maybe_lt : Token , mut err : PErr < ' a > ) -> PErr < ' a > {
2931+ if maybe_lt == token:: Lt
2932+ && ( self . expected_tokens . contains ( & TokenType :: Token ( token:: Gt ) )
2933+ || matches ! ( self . token. kind, token:: Literal ( ..) ) )
2934+ {
2935+ err. span_suggestion (
2936+ maybe_lt. span ,
2937+ "remove the `<` to write an exclusive range" ,
2938+ "" ,
2939+ Applicability :: MachineApplicable ,
2940+ ) ;
2941+ }
2942+ err
2943+ }
2944+
29302945 pub fn is_diff_marker ( & mut self , long_kind : & TokenKind , short_kind : & TokenKind ) -> bool {
29312946 ( 0 ..3 ) . all ( |i| self . look_ahead ( i, |tok| tok == long_kind) )
29322947 && self . look_ahead ( 3 , |tok| tok == short_kind)
0 commit comments