@@ -4630,7 +4630,7 @@ impl<'a> Parser<'a> {
46304630
46314631 let mut attrs = self . parse_outer_attributes ( ) ?;
46324632 let lo = self . span . lo ;
4633- let vis = self . parse_visibility ( true ) ?;
4633+ let vis = self . parse_visibility ( ) ?;
46344634 let defaultness = self . parse_defaultness ( ) ?;
46354635 let ( name, node) = if self . eat_keyword ( keywords:: Type ) {
46364636 let name = self . parse_ident ( ) ?;
@@ -4963,7 +4963,7 @@ impl<'a> Parser<'a> {
49634963 |p| {
49644964 let attrs = p. parse_outer_attributes ( ) ?;
49654965 let lo = p. span . lo ;
4966- let mut vis = p. parse_visibility ( false ) ?;
4966+ let mut vis = p. parse_visibility ( ) ?;
49674967 let ty_is_interpolated =
49684968 p. token . is_interpolated ( ) || p. look_ahead ( 1 , |t| t. is_interpolated ( ) ) ;
49694969 let mut ty = p. parse_ty ( ) ?;
@@ -5020,38 +5020,46 @@ impl<'a> Parser<'a> {
50205020 fn parse_struct_decl_field ( & mut self ) -> PResult < ' a , StructField > {
50215021 let attrs = self . parse_outer_attributes ( ) ?;
50225022 let lo = self . span . lo ;
5023- let vis = self . parse_visibility ( true ) ?;
5023+ let vis = self . parse_visibility ( ) ?;
50245024 self . parse_single_struct_field ( lo, vis, attrs)
50255025 }
50265026
5027- // If `allow_path` is false, just parse the `pub` in `pub(path)` (but still parse `pub(crate)`)
5028- fn parse_visibility ( & mut self , allow_path : bool ) -> PResult < ' a , Visibility > {
5029- let pub_crate = |this : & mut Self | {
5030- let span = this. prev_span ;
5031- this. expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5032- Ok ( Visibility :: Crate ( span) )
5033- } ;
5034-
5027+ // Parse `pub`, `pub(crate)` and `pub(in path)` plus shortcuts
5028+ // `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
5029+ fn parse_visibility ( & mut self ) -> PResult < ' a , Visibility > {
50355030 if !self . eat_keyword ( keywords:: Pub ) {
5036- Ok ( Visibility :: Inherited )
5037- } else if !allow_path {
5038- // Look ahead to avoid eating the `(` in `pub(path)` while still parsing `pub(crate)`
5039- if self . token == token:: OpenDelim ( token:: Paren ) &&
5040- self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Crate ) ) {
5041- self . bump ( ) ; self . bump ( ) ;
5042- pub_crate ( self )
5043- } else {
5044- Ok ( Visibility :: Public )
5045- }
5046- } else if !self . eat ( & token:: OpenDelim ( token:: Paren ) ) {
5047- Ok ( Visibility :: Public )
5048- } else if self . eat_keyword ( keywords:: Crate ) {
5049- pub_crate ( self )
5050- } else {
5051- let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ;
5052- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5053- Ok ( Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } )
5054- }
5031+ return Ok ( Visibility :: Inherited )
5032+ }
5033+
5034+ if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
5035+ if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Crate ) ) {
5036+ // `pub(crate)`
5037+ self . bump ( ) ; // `(`
5038+ self . bump ( ) ; // `crate`
5039+ let vis = Visibility :: Crate ( self . prev_span ) ;
5040+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5041+ return Ok ( vis)
5042+ } else if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: In ) ) {
5043+ // `pub(in path)`
5044+ self . bump ( ) ; // `(`
5045+ self . bump ( ) ; // `in`
5046+ let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ; // `path`
5047+ let vis = Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
5048+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5049+ return Ok ( vis)
5050+ } else if self . look_ahead ( 2 , |t| t == & token:: CloseDelim ( token:: Paren ) ) &&
5051+ self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Super ) ||
5052+ t. is_keyword ( keywords:: SelfValue ) ) {
5053+ // `pub(self)` or `pub(super)`
5054+ self . bump ( ) ; // `(`
5055+ let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ; // `super`/`self`
5056+ let vis = Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
5057+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5058+ return Ok ( vis)
5059+ }
5060+ }
5061+
5062+ Ok ( Visibility :: Public )
50555063 }
50565064
50575065 /// Parse defaultness: DEFAULT or nothing
@@ -5526,7 +5534,7 @@ impl<'a> Parser<'a> {
55265534
55275535 let lo = self . span . lo ;
55285536
5529- let visibility = self . parse_visibility ( true ) ?;
5537+ let visibility = self . parse_visibility ( ) ?;
55305538
55315539 if self . eat_keyword ( keywords:: Use ) {
55325540 // USE ITEM
@@ -5801,7 +5809,7 @@ impl<'a> Parser<'a> {
58015809 fn parse_foreign_item ( & mut self ) -> PResult < ' a , Option < ForeignItem > > {
58025810 let attrs = self . parse_outer_attributes ( ) ?;
58035811 let lo = self . span . lo ;
5804- let visibility = self . parse_visibility ( true ) ?;
5812+ let visibility = self . parse_visibility ( ) ?;
58055813
58065814 if self . check_keyword ( keywords:: Static ) {
58075815 // FOREIGN STATIC ITEM
0 commit comments