@@ -8,6 +8,7 @@ use rustc_ast::ast::*;
88use rustc_ast:: ptr:: P ;
99use rustc_ast:: token:: { self , Delimiter , TokenKind } ;
1010use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
11+ use rustc_ast:: util:: case:: Case ;
1112use rustc_ast:: { self as ast, AttrVec , Attribute , DUMMY_NODE_ID } ;
1213use rustc_ast:: { Async , Const , Defaultness , IsAuto , Mutability , Unsafe , UseTree , UseTreeKind } ;
1314use rustc_ast:: { BindingAnnotation , Block , FnDecl , FnSig , Param , SelfKind } ;
@@ -34,7 +35,7 @@ impl<'a> Parser<'a> {
3435
3536 /// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
3637 fn parse_item_mod ( & mut self , attrs : & mut AttrVec ) -> PResult < ' a , ItemInfo > {
37- let unsafety = self . parse_unsafety ( false ) ;
38+ let unsafety = self . parse_unsafety ( Case :: Sensitive ) ;
3839 self . expect_keyword ( kw:: Mod ) ?;
3940 let id = self . parse_ident ( ) ?;
4041 let mod_kind = if self . eat ( & token:: Semi ) {
@@ -150,7 +151,7 @@ impl<'a> Parser<'a> {
150151 & vis,
151152 & mut def,
152153 fn_parse_mode,
153- false ,
154+ Case :: Sensitive ,
154155 ) ?;
155156 if let Some ( ( ident, kind) ) = kind {
156157 self . error_on_unconsumed_default ( def, & kind) ;
@@ -212,14 +213,14 @@ impl<'a> Parser<'a> {
212213 vis : & Visibility ,
213214 def : & mut Defaultness ,
214215 fn_parse_mode : FnParseMode ,
215- kw_case_insensitive : bool ,
216+ case : Case ,
216217 ) -> PResult < ' a , Option < ItemInfo > > {
217218 let def_final = def == & Defaultness :: Final ;
218219 let mut def_ = || mem:: replace ( def, Defaultness :: Final ) ;
219220
220- let info = if self . eat_keyword_case ( kw:: Use , kw_case_insensitive ) {
221+ let info = if self . eat_keyword_case ( kw:: Use , case ) {
221222 self . parse_use_item ( ) ?
222- } else if self . check_fn_front_matter ( def_final, kw_case_insensitive ) {
223+ } else if self . check_fn_front_matter ( def_final, case ) {
223224 // FUNCTION ITEM
224225 let ( ident, sig, generics, body) = self . parse_fn ( attrs, fn_parse_mode, lo, vis) ?;
225226 ( ident, ItemKind :: Fn ( Box :: new ( Fn { defaultness : def_ ( ) , sig, generics, body } ) ) )
@@ -233,7 +234,7 @@ impl<'a> Parser<'a> {
233234 }
234235 } else if self . is_unsafe_foreign_mod ( ) {
235236 // EXTERN BLOCK
236- let unsafety = self . parse_unsafety ( false ) ;
237+ let unsafety = self . parse_unsafety ( Case :: Sensitive ) ;
237238 self . expect_keyword ( kw:: Extern ) ?;
238239 self . parse_item_foreign_mod ( attrs, unsafety) ?
239240 } else if self . is_static_global ( ) {
@@ -242,7 +243,7 @@ impl<'a> Parser<'a> {
242243 let m = self . parse_mutability ( ) ;
243244 let ( ident, ty, expr) = self . parse_item_global ( Some ( m) ) ?;
244245 ( ident, ItemKind :: Static ( ty, m, expr) )
245- } else if let Const :: Yes ( const_span) = self . parse_constness ( false ) {
246+ } else if let Const :: Yes ( const_span) = self . parse_constness ( Case :: Sensitive ) {
246247 // CONST ITEM
247248 if self . token . is_keyword ( kw:: Impl ) {
248249 // recover from `const impl`, suggest `impl const`
@@ -294,11 +295,19 @@ impl<'a> Parser<'a> {
294295 } else if self . isnt_macro_invocation ( ) && vis. kind . is_pub ( ) {
295296 self . recover_missing_kw_before_item ( ) ?;
296297 return Ok ( None ) ;
297- } else if self . isnt_macro_invocation ( ) && !kw_case_insensitive {
298+ } else if self . isnt_macro_invocation ( ) && case == Case :: Sensitive {
298299 _ = def_;
299300
300301 // Recover wrong cased keywords
301- return self . parse_item_kind ( attrs, macros_allowed, lo, vis, def, fn_parse_mode, true ) ;
302+ return self . parse_item_kind (
303+ attrs,
304+ macros_allowed,
305+ lo,
306+ vis,
307+ def,
308+ fn_parse_mode,
309+ Case :: Insensitive ,
310+ ) ;
302311 } else if macros_allowed && self . check_path ( ) {
303312 // MACRO INVOCATION ITEM
304313 ( Ident :: empty ( ) , ItemKind :: MacCall ( P ( self . parse_item_macro ( vis) ?) ) )
@@ -551,7 +560,7 @@ impl<'a> Parser<'a> {
551560 attrs : & mut AttrVec ,
552561 defaultness : Defaultness ,
553562 ) -> PResult < ' a , ItemInfo > {
554- let unsafety = self . parse_unsafety ( false ) ;
563+ let unsafety = self . parse_unsafety ( Case :: Sensitive ) ;
555564 self . expect_keyword ( kw:: Impl ) ?;
556565
557566 // First, parse generic parameters if necessary.
@@ -565,7 +574,7 @@ impl<'a> Parser<'a> {
565574 generics
566575 } ;
567576
568- let constness = self . parse_constness ( false ) ;
577+ let constness = self . parse_constness ( Case :: Sensitive ) ;
569578 if let Const :: Yes ( span) = constness {
570579 self . sess . gated_spans . gate ( sym:: const_trait_impl, span) ;
571580 }
@@ -809,7 +818,7 @@ impl<'a> Parser<'a> {
809818
810819 /// Parses `unsafe? auto? trait Foo { ... }` or `trait Foo = Bar;`.
811820 fn parse_item_trait ( & mut self , attrs : & mut AttrVec , lo : Span ) -> PResult < ' a , ItemInfo > {
812- let unsafety = self . parse_unsafety ( false ) ;
821+ let unsafety = self . parse_unsafety ( Case :: Sensitive ) ;
813822 // Parse optional `auto` prefix.
814823 let is_auto = if self . eat_keyword ( kw:: Auto ) { IsAuto :: Yes } else { IsAuto :: No } ;
815824
@@ -1758,7 +1767,7 @@ impl<'a> Parser<'a> {
17581767 let ( ident, is_raw) = self . ident_or_err ( ) ?;
17591768 if !is_raw && ident. is_reserved ( ) {
17601769 let snapshot = self . create_snapshot_for_diagnostic ( ) ;
1761- let err = if self . check_fn_front_matter ( false , false ) {
1770+ let err = if self . check_fn_front_matter ( false , Case :: Sensitive ) {
17621771 let inherited_vis = Visibility {
17631772 span : rustc_span:: DUMMY_SP ,
17641773 kind : VisibilityKind :: Inherited ,
@@ -2147,11 +2156,7 @@ impl<'a> Parser<'a> {
21472156 ///
21482157 /// `check_pub` adds additional `pub` to the checks in case users place it
21492158 /// wrongly, can be used to ensure `pub` never comes after `default`.
2150- pub ( super ) fn check_fn_front_matter (
2151- & mut self ,
2152- check_pub : bool ,
2153- kw_case_insensitive : bool ,
2154- ) -> bool {
2159+ pub ( super ) fn check_fn_front_matter ( & mut self , check_pub : bool , case : Case ) -> bool {
21552160 // We use an over-approximation here.
21562161 // `const const`, `fn const` won't parse, but we're not stepping over other syntax either.
21572162 // `pub` is added in case users got confused with the ordering like `async pub fn`,
@@ -2161,12 +2166,12 @@ impl<'a> Parser<'a> {
21612166 } else {
21622167 & [ kw:: Const , kw:: Async , kw:: Unsafe , kw:: Extern ]
21632168 } ;
2164- self . check_keyword_case ( kw:: Fn , kw_case_insensitive ) // Definitely an `fn`.
2169+ self . check_keyword_case ( kw:: Fn , case ) // Definitely an `fn`.
21652170 // `$qual fn` or `$qual $qual`:
2166- || quals. iter ( ) . any ( |& kw| self . check_keyword_case ( kw, kw_case_insensitive ) )
2171+ || quals. iter ( ) . any ( |& kw| self . check_keyword_case ( kw, case ) )
21672172 && self . look_ahead ( 1 , |t| {
21682173 // `$qual fn`, e.g. `const fn` or `async fn`.
2169- t. is_keyword_case ( kw:: Fn , kw_case_insensitive )
2174+ t. is_keyword_case ( kw:: Fn , case )
21702175 // Two qualifiers `$qual $qual` is enough, e.g. `async unsafe`.
21712176 || (
21722177 (
@@ -2175,16 +2180,16 @@ impl<'a> Parser<'a> {
21752180 // Rule out 2015 `const async: T = val`.
21762181 && i. is_reserved ( )
21772182 )
2178- || kw_case_insensitive
2183+ || case == Case :: Insensitive
21792184 && t. is_non_raw_ident_where ( |i| quals. iter ( ) . any ( |qual| qual. as_str ( ) == i. name . as_str ( ) . to_lowercase ( ) ) )
21802185 )
21812186 // Rule out unsafe extern block.
21822187 && !self . is_unsafe_foreign_mod ( ) )
21832188 } )
21842189 // `extern ABI fn`
2185- || self . check_keyword_case ( kw:: Extern , kw_case_insensitive )
2190+ || self . check_keyword_case ( kw:: Extern , case )
21862191 && self . look_ahead ( 1 , |t| t. can_begin_literal_maybe_minus ( ) )
2187- && self . look_ahead ( 2 , |t| t. is_keyword_case ( kw:: Fn , kw_case_insensitive ) )
2192+ && self . look_ahead ( 2 , |t| t. is_keyword_case ( kw:: Fn , case ) )
21882193 }
21892194
21902195 /// Parses all the "front matter" (or "qualifiers") for a `fn` declaration,
@@ -2200,22 +2205,22 @@ impl<'a> Parser<'a> {
22002205 /// `Visibility::Inherited` when no visibility is known.
22012206 pub ( super ) fn parse_fn_front_matter ( & mut self , orig_vis : & Visibility ) -> PResult < ' a , FnHeader > {
22022207 let sp_start = self . token . span ;
2203- let constness = self . parse_constness ( true ) ;
2208+ let constness = self . parse_constness ( Case :: Insensitive ) ;
22042209
22052210 let async_start_sp = self . token . span ;
2206- let asyncness = self . parse_asyncness ( true ) ;
2211+ let asyncness = self . parse_asyncness ( Case :: Insensitive ) ;
22072212
22082213 let unsafe_start_sp = self . token . span ;
2209- let unsafety = self . parse_unsafety ( true ) ;
2214+ let unsafety = self . parse_unsafety ( Case :: Insensitive ) ;
22102215
22112216 let ext_start_sp = self . token . span ;
2212- let ext = self . parse_extern ( true ) ;
2217+ let ext = self . parse_extern ( Case :: Insensitive ) ;
22132218
22142219 if let Async :: Yes { span, .. } = asyncness {
22152220 self . ban_async_in_2015 ( span) ;
22162221 }
22172222
2218- if !self . eat_keyword_case ( kw:: Fn , true ) {
2223+ if !self . eat_keyword_case ( kw:: Fn , Case :: Insensitive ) {
22192224 // It is possible for `expect_one_of` to recover given the contents of
22202225 // `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
22212226 // account for this.
0 commit comments