@@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
2525use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
2626use rustc_ast:: AttrId ;
2727use 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 } ;
2929use rustc_ast:: { Async , Expr , ExprKind , MacArgs , MacArgsEq , MacDelimiter , Mutability , StrLit } ;
3030use rustc_ast:: { HasAttrs , HasTokens , Unsafe , Visibility , VisibilityKind } ;
3131use rustc_ast_pretty:: pprust;
@@ -1245,30 +1245,15 @@ impl<'a> Parser<'a> {
12451245 res
12461246 }
12471247
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)`.
12541250 /// If the following element can't be a tuple (i.e., it's a function definition), then
12551251 /// it's not a tuple struct field), and the contents within the parentheses aren't valid,
12561252 /// so emit a proper diagnostic.
12571253 // Public for rustfmt usage.
12581254 pub fn parse_visibility ( & mut self , fbt : FollowedByType ) -> PResult < ' a , Visibility > {
12591255 maybe_whole ! ( self , NtVis , |x| x. into_inner( ) ) ;
12601256
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-
12721257 if !self . eat_keyword ( kw:: Pub ) {
12731258 // We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
12741259 // keyword to grab a span from for inherited visibility; an empty span at the
@@ -1286,20 +1271,7 @@ impl<'a> Parser<'a> {
12861271 // `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
12871272 // Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
12881273 // 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 ] ) {
13031275 // Parse `pub(in path)`.
13041276 self . bump ( ) ; // `(`
13051277 self . bump ( ) ; // `in`
@@ -1312,11 +1284,11 @@ impl<'a> Parser<'a> {
13121284 tokens : None ,
13131285 } ) ;
13141286 } 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 ] )
13161288 {
1317- // Parse `pub(self)` or `pub(super)`.
1289+ // Parse `pub(crate)`, `pub( self)`, or `pub(super)`.
13181290 self . bump ( ) ; // `(`
1319- let path = self . parse_path ( PathStyle :: Mod ) ?; // `super`/`self`
1291+ let path = self . parse_path ( PathStyle :: Mod ) ?; // `crate`/` super`/`self`
13201292 self . expect ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) ?; // `)`
13211293 let vis = VisibilityKind :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
13221294 return Ok ( Visibility {
0 commit comments