@@ -4641,7 +4641,7 @@ impl<'a> Parser<'a> {
46414641
46424642 let mut attrs = self . parse_outer_attributes ( ) ?;
46434643 let lo = self . span . lo ;
4644- let vis = self . parse_visibility ( true ) ?;
4644+ let vis = self . parse_visibility ( ) ?;
46454645 let defaultness = self . parse_defaultness ( ) ?;
46464646 let ( name, node) = if self . eat_keyword ( keywords:: Type ) {
46474647 let name = self . parse_ident ( ) ?;
@@ -4972,7 +4972,7 @@ impl<'a> Parser<'a> {
49724972 |p| {
49734973 let attrs = p. parse_outer_attributes ( ) ?;
49744974 let lo = p. span . lo ;
4975- let mut vis = p. parse_visibility ( false ) ?;
4975+ let mut vis = p. parse_visibility ( ) ?;
49764976 let ty_is_interpolated =
49774977 p. token . is_interpolated ( ) || p. look_ahead ( 1 , |t| t. is_interpolated ( ) ) ;
49784978 let mut ty = p. parse_ty ( ) ?;
@@ -5029,38 +5029,46 @@ impl<'a> Parser<'a> {
50295029 fn parse_struct_decl_field ( & mut self ) -> PResult < ' a , StructField > {
50305030 let attrs = self . parse_outer_attributes ( ) ?;
50315031 let lo = self . span . lo ;
5032- let vis = self . parse_visibility ( true ) ?;
5032+ let vis = self . parse_visibility ( ) ?;
50335033 self . parse_single_struct_field ( lo, vis, attrs)
50345034 }
50355035
5036- // If `allow_path` is false, just parse the `pub` in `pub(path)` (but still parse `pub(crate)`)
5037- fn parse_visibility ( & mut self , allow_path : bool ) -> PResult < ' a , Visibility > {
5038- let pub_crate = |this : & mut Self | {
5039- let span = this. prev_span ;
5040- this. expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5041- Ok ( Visibility :: Crate ( span) )
5042- } ;
5043-
5036+ // Parse `pub`, `pub(crate)` and `pub(in path)` plus shortcuts
5037+ // `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
5038+ fn parse_visibility ( & mut self ) -> PResult < ' a , Visibility > {
50445039 if !self . eat_keyword ( keywords:: Pub ) {
5045- Ok ( Visibility :: Inherited )
5046- } else if !allow_path {
5047- // Look ahead to avoid eating the `(` in `pub(path)` while still parsing `pub(crate)`
5048- if self . token == token:: OpenDelim ( token:: Paren ) &&
5049- self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Crate ) ) {
5050- self . bump ( ) ; self . bump ( ) ;
5051- pub_crate ( self )
5052- } else {
5053- Ok ( Visibility :: Public )
5054- }
5055- } else if !self . eat ( & token:: OpenDelim ( token:: Paren ) ) {
5056- Ok ( Visibility :: Public )
5057- } else if self . eat_keyword ( keywords:: Crate ) {
5058- pub_crate ( self )
5059- } else {
5060- let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ;
5061- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5062- Ok ( Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } )
5063- }
5040+ return Ok ( Visibility :: Inherited )
5041+ }
5042+
5043+ if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
5044+ if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Crate ) ) {
5045+ // `pub(crate)`
5046+ self . bump ( ) ; // `(`
5047+ self . bump ( ) ; // `crate`
5048+ let vis = Visibility :: Crate ( self . prev_span ) ;
5049+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5050+ return Ok ( vis)
5051+ } else if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: In ) ) {
5052+ // `pub(in path)`
5053+ self . bump ( ) ; // `(`
5054+ self . bump ( ) ; // `in`
5055+ let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ; // `path`
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+ } else if self . look_ahead ( 2 , |t| t == & token:: CloseDelim ( token:: Paren ) ) &&
5060+ self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Super ) ||
5061+ t. is_keyword ( keywords:: SelfValue ) ) {
5062+ // `pub(self)` or `pub(super)`
5063+ self . bump ( ) ; // `(`
5064+ let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ; // `super`/`self`
5065+ let vis = Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
5066+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5067+ return Ok ( vis)
5068+ }
5069+ }
5070+
5071+ Ok ( Visibility :: Public )
50645072 }
50655073
50665074 /// Parse defaultness: DEFAULT or nothing
@@ -5535,7 +5543,7 @@ impl<'a> Parser<'a> {
55355543
55365544 let lo = self . span . lo ;
55375545
5538- let visibility = self . parse_visibility ( true ) ?;
5546+ let visibility = self . parse_visibility ( ) ?;
55395547
55405548 if self . eat_keyword ( keywords:: Use ) {
55415549 // USE ITEM
@@ -5814,7 +5822,7 @@ impl<'a> Parser<'a> {
58145822 fn parse_foreign_item ( & mut self ) -> PResult < ' a , Option < ForeignItem > > {
58155823 let attrs = self . parse_outer_attributes ( ) ?;
58165824 let lo = self . span . lo ;
5817- let visibility = self . parse_visibility ( true ) ?;
5825+ let visibility = self . parse_visibility ( ) ?;
58185826
58195827 if self . check_keyword ( keywords:: Static ) {
58205828 // FOREIGN STATIC ITEM
0 commit comments