@@ -8,6 +8,7 @@ use rustc_ast::ast::*;
8
8
use rustc_ast:: ptr:: P ;
9
9
use rustc_ast:: token:: { self , Delimiter , TokenKind } ;
10
10
use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
11
+ use rustc_ast:: util:: case:: Case ;
11
12
use rustc_ast:: { self as ast, AttrVec , Attribute , DUMMY_NODE_ID } ;
12
13
use rustc_ast:: { Async , Const , Defaultness , IsAuto , Mutability , Unsafe , UseTree , UseTreeKind } ;
13
14
use rustc_ast:: { BindingAnnotation , Block , FnDecl , FnSig , Param , SelfKind } ;
@@ -34,7 +35,7 @@ impl<'a> Parser<'a> {
34
35
35
36
/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
36
37
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 ) ;
38
39
self . expect_keyword ( kw:: Mod ) ?;
39
40
let id = self . parse_ident ( ) ?;
40
41
let mod_kind = if self . eat ( & token:: Semi ) {
@@ -150,7 +151,7 @@ impl<'a> Parser<'a> {
150
151
& vis,
151
152
& mut def,
152
153
fn_parse_mode,
153
- false ,
154
+ Case :: Sensitive ,
154
155
) ?;
155
156
if let Some ( ( ident, kind) ) = kind {
156
157
self . error_on_unconsumed_default ( def, & kind) ;
@@ -212,14 +213,14 @@ impl<'a> Parser<'a> {
212
213
vis : & Visibility ,
213
214
def : & mut Defaultness ,
214
215
fn_parse_mode : FnParseMode ,
215
- kw_case_insensitive : bool ,
216
+ case : Case ,
216
217
) -> PResult < ' a , Option < ItemInfo > > {
217
218
let def_final = def == & Defaultness :: Final ;
218
219
let mut def_ = || mem:: replace ( def, Defaultness :: Final ) ;
219
220
220
- let info = if self . eat_keyword_case ( kw:: Use , kw_case_insensitive ) {
221
+ let info = if self . eat_keyword_case ( kw:: Use , case ) {
221
222
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 ) {
223
224
// FUNCTION ITEM
224
225
let ( ident, sig, generics, body) = self . parse_fn ( attrs, fn_parse_mode, lo, vis) ?;
225
226
( ident, ItemKind :: Fn ( Box :: new ( Fn { defaultness : def_ ( ) , sig, generics, body } ) ) )
@@ -233,7 +234,7 @@ impl<'a> Parser<'a> {
233
234
}
234
235
} else if self . is_unsafe_foreign_mod ( ) {
235
236
// EXTERN BLOCK
236
- let unsafety = self . parse_unsafety ( false ) ;
237
+ let unsafety = self . parse_unsafety ( Case :: Sensitive ) ;
237
238
self . expect_keyword ( kw:: Extern ) ?;
238
239
self . parse_item_foreign_mod ( attrs, unsafety) ?
239
240
} else if self . is_static_global ( ) {
@@ -242,7 +243,7 @@ impl<'a> Parser<'a> {
242
243
let m = self . parse_mutability ( ) ;
243
244
let ( ident, ty, expr) = self . parse_item_global ( Some ( m) ) ?;
244
245
( 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 ) {
246
247
// CONST ITEM
247
248
if self . token . is_keyword ( kw:: Impl ) {
248
249
// recover from `const impl`, suggest `impl const`
@@ -294,11 +295,19 @@ impl<'a> Parser<'a> {
294
295
} else if self . isnt_macro_invocation ( ) && vis. kind . is_pub ( ) {
295
296
self . recover_missing_kw_before_item ( ) ?;
296
297
return Ok ( None ) ;
297
- } else if self . isnt_macro_invocation ( ) && !kw_case_insensitive {
298
+ } else if self . isnt_macro_invocation ( ) && case == Case :: Sensitive {
298
299
_ = def_;
299
300
300
301
// 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
+ ) ;
302
311
} else if macros_allowed && self . check_path ( ) {
303
312
// MACRO INVOCATION ITEM
304
313
( Ident :: empty ( ) , ItemKind :: MacCall ( P ( self . parse_item_macro ( vis) ?) ) )
@@ -551,7 +560,7 @@ impl<'a> Parser<'a> {
551
560
attrs : & mut AttrVec ,
552
561
defaultness : Defaultness ,
553
562
) -> PResult < ' a , ItemInfo > {
554
- let unsafety = self . parse_unsafety ( false ) ;
563
+ let unsafety = self . parse_unsafety ( Case :: Sensitive ) ;
555
564
self . expect_keyword ( kw:: Impl ) ?;
556
565
557
566
// First, parse generic parameters if necessary.
@@ -565,7 +574,7 @@ impl<'a> Parser<'a> {
565
574
generics
566
575
} ;
567
576
568
- let constness = self . parse_constness ( false ) ;
577
+ let constness = self . parse_constness ( Case :: Sensitive ) ;
569
578
if let Const :: Yes ( span) = constness {
570
579
self . sess . gated_spans . gate ( sym:: const_trait_impl, span) ;
571
580
}
@@ -809,7 +818,7 @@ impl<'a> Parser<'a> {
809
818
810
819
/// Parses `unsafe? auto? trait Foo { ... }` or `trait Foo = Bar;`.
811
820
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 ) ;
813
822
// Parse optional `auto` prefix.
814
823
let is_auto = if self . eat_keyword ( kw:: Auto ) { IsAuto :: Yes } else { IsAuto :: No } ;
815
824
@@ -1758,7 +1767,7 @@ impl<'a> Parser<'a> {
1758
1767
let ( ident, is_raw) = self . ident_or_err ( ) ?;
1759
1768
if !is_raw && ident. is_reserved ( ) {
1760
1769
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 ) {
1762
1771
let inherited_vis = Visibility {
1763
1772
span : rustc_span:: DUMMY_SP ,
1764
1773
kind : VisibilityKind :: Inherited ,
@@ -2147,11 +2156,7 @@ impl<'a> Parser<'a> {
2147
2156
///
2148
2157
/// `check_pub` adds additional `pub` to the checks in case users place it
2149
2158
/// 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 {
2155
2160
// We use an over-approximation here.
2156
2161
// `const const`, `fn const` won't parse, but we're not stepping over other syntax either.
2157
2162
// `pub` is added in case users got confused with the ordering like `async pub fn`,
@@ -2161,12 +2166,12 @@ impl<'a> Parser<'a> {
2161
2166
} else {
2162
2167
& [ kw:: Const , kw:: Async , kw:: Unsafe , kw:: Extern ]
2163
2168
} ;
2164
- self . check_keyword_case ( kw:: Fn , kw_case_insensitive ) // Definitely an `fn`.
2169
+ self . check_keyword_case ( kw:: Fn , case ) // Definitely an `fn`.
2165
2170
// `$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 ) )
2167
2172
&& self . look_ahead ( 1 , |t| {
2168
2173
// `$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 )
2170
2175
// Two qualifiers `$qual $qual` is enough, e.g. `async unsafe`.
2171
2176
|| (
2172
2177
(
@@ -2175,16 +2180,16 @@ impl<'a> Parser<'a> {
2175
2180
// Rule out 2015 `const async: T = val`.
2176
2181
&& i. is_reserved ( )
2177
2182
)
2178
- || kw_case_insensitive
2183
+ || case == Case :: Insensitive
2179
2184
&& t. is_non_raw_ident_where ( |i| quals. iter ( ) . any ( |qual| qual. as_str ( ) == i. name . as_str ( ) . to_lowercase ( ) ) )
2180
2185
)
2181
2186
// Rule out unsafe extern block.
2182
2187
&& !self . is_unsafe_foreign_mod ( ) )
2183
2188
} )
2184
2189
// `extern ABI fn`
2185
- || self . check_keyword_case ( kw:: Extern , kw_case_insensitive )
2190
+ || self . check_keyword_case ( kw:: Extern , case )
2186
2191
&& 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 ) )
2188
2193
}
2189
2194
2190
2195
/// Parses all the "front matter" (or "qualifiers") for a `fn` declaration,
@@ -2200,22 +2205,22 @@ impl<'a> Parser<'a> {
2200
2205
/// `Visibility::Inherited` when no visibility is known.
2201
2206
pub ( super ) fn parse_fn_front_matter ( & mut self , orig_vis : & Visibility ) -> PResult < ' a , FnHeader > {
2202
2207
let sp_start = self . token . span ;
2203
- let constness = self . parse_constness ( true ) ;
2208
+ let constness = self . parse_constness ( Case :: Insensitive ) ;
2204
2209
2205
2210
let async_start_sp = self . token . span ;
2206
- let asyncness = self . parse_asyncness ( true ) ;
2211
+ let asyncness = self . parse_asyncness ( Case :: Insensitive ) ;
2207
2212
2208
2213
let unsafe_start_sp = self . token . span ;
2209
- let unsafety = self . parse_unsafety ( true ) ;
2214
+ let unsafety = self . parse_unsafety ( Case :: Insensitive ) ;
2210
2215
2211
2216
let ext_start_sp = self . token . span ;
2212
- let ext = self . parse_extern ( true ) ;
2217
+ let ext = self . parse_extern ( Case :: Insensitive ) ;
2213
2218
2214
2219
if let Async :: Yes { span, .. } = asyncness {
2215
2220
self . ban_async_in_2015 ( span) ;
2216
2221
}
2217
2222
2218
- if !self . eat_keyword_case ( kw:: Fn , true ) {
2223
+ if !self . eat_keyword_case ( kw:: Fn , Case :: Insensitive ) {
2219
2224
// It is possible for `expect_one_of` to recover given the contents of
2220
2225
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
2221
2226
// account for this.
0 commit comments