@@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
25
25
use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
26
26
use rustc_ast:: AttrId ;
27
27
use rustc_ast:: DUMMY_NODE_ID ;
28
- use rustc_ast:: { self as ast, AnonConst , AttrStyle , AttrVec , Const , CrateSugar , Extern } ;
28
+ use rustc_ast:: { self as ast, AnonConst , AttrStyle , AttrVec , Const , Extern } ;
29
29
use rustc_ast:: { Async , Expr , ExprKind , MacArgs , MacArgsEq , MacDelimiter , Mutability , StrLit } ;
30
30
use rustc_ast:: { HasAttrs , HasTokens , Unsafe , Visibility , VisibilityKind } ;
31
31
use rustc_ast_pretty:: pprust;
@@ -1245,30 +1245,15 @@ impl<'a> Parser<'a> {
1245
1245
res
1246
1246
}
1247
1247
1248
- fn is_crate_vis ( & self ) -> bool {
1249
- self . token . is_keyword ( kw:: Crate ) && self . look_ahead ( 1 , |t| t != & token:: ModSep )
1250
- }
1251
-
1252
- /// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
1253
- /// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
1248
+ /// Parses `pub` and `pub(in path)` plus shortcuts `pub(crate)` for `pub(in crate)`, `pub(self)`
1249
+ /// for `pub(in self)` and `pub(super)` for `pub(in super)`.
1254
1250
/// If the following element can't be a tuple (i.e., it's a function definition), then
1255
1251
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
1256
1252
/// so emit a proper diagnostic.
1257
1253
// Public for rustfmt usage.
1258
1254
pub fn parse_visibility ( & mut self , fbt : FollowedByType ) -> PResult < ' a , Visibility > {
1259
1255
maybe_whole ! ( self , NtVis , |x| x. into_inner( ) ) ;
1260
1256
1261
- self . expected_tokens . push ( TokenType :: Keyword ( kw:: Crate ) ) ;
1262
- if self . is_crate_vis ( ) {
1263
- self . bump ( ) ; // `crate`
1264
- self . sess . gated_spans . gate ( sym:: crate_visibility_modifier, self . prev_token . span ) ;
1265
- return Ok ( Visibility {
1266
- span : self . prev_token . span ,
1267
- kind : VisibilityKind :: Crate ( CrateSugar :: JustCrate ) ,
1268
- tokens : None ,
1269
- } ) ;
1270
- }
1271
-
1272
1257
if !self . eat_keyword ( kw:: Pub ) {
1273
1258
// We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
1274
1259
// keyword to grab a span from for inherited visibility; an empty span at the
@@ -1286,20 +1271,7 @@ impl<'a> Parser<'a> {
1286
1271
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
1287
1272
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
1288
1273
// by the following tokens.
1289
- if self . is_keyword_ahead ( 1 , & [ kw:: Crate ] ) && self . look_ahead ( 2 , |t| t != & token:: ModSep )
1290
- // account for `pub(crate::foo)`
1291
- {
1292
- // Parse `pub(crate)`.
1293
- self . bump ( ) ; // `(`
1294
- self . bump ( ) ; // `crate`
1295
- self . expect ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) ?; // `)`
1296
- let vis = VisibilityKind :: Crate ( CrateSugar :: PubCrate ) ;
1297
- return Ok ( Visibility {
1298
- span : lo. to ( self . prev_token . span ) ,
1299
- kind : vis,
1300
- tokens : None ,
1301
- } ) ;
1302
- } else if self . is_keyword_ahead ( 1 , & [ kw:: In ] ) {
1274
+ if self . is_keyword_ahead ( 1 , & [ kw:: In ] ) {
1303
1275
// Parse `pub(in path)`.
1304
1276
self . bump ( ) ; // `(`
1305
1277
self . bump ( ) ; // `in`
@@ -1312,11 +1284,11 @@ impl<'a> Parser<'a> {
1312
1284
tokens : None ,
1313
1285
} ) ;
1314
1286
} else if self . look_ahead ( 2 , |t| t == & token:: CloseDelim ( Delimiter :: Parenthesis ) )
1315
- && self . is_keyword_ahead ( 1 , & [ kw:: Super , kw:: SelfLower ] )
1287
+ && self . is_keyword_ahead ( 1 , & [ kw:: Crate , kw :: Super , kw:: SelfLower ] )
1316
1288
{
1317
- // Parse `pub(self)` or `pub(super)`.
1289
+ // Parse `pub(crate)`, `pub( self)`, or `pub(super)`.
1318
1290
self . bump ( ) ; // `(`
1319
- let path = self . parse_path ( PathStyle :: Mod ) ?; // `super`/`self`
1291
+ let path = self . parse_path ( PathStyle :: Mod ) ?; // `crate`/` super`/`self`
1320
1292
self . expect ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) ?; // `)`
1321
1293
let vis = VisibilityKind :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
1322
1294
return Ok ( Visibility {
0 commit comments