@@ -4605,7 +4605,7 @@ impl<'a> Parser<'a> {
46054605
46064606 let mut attrs = self . parse_outer_attributes ( ) ?;
46074607 let lo = self . span . lo ;
4608- let vis = self . parse_visibility ( true ) ?;
4608+ let vis = self . parse_visibility ( ) ?;
46094609 let defaultness = self . parse_defaultness ( ) ?;
46104610 let ( name, node) = if self . eat_keyword ( keywords:: Type ) {
46114611 let name = self . parse_ident ( ) ?;
@@ -4936,7 +4936,7 @@ impl<'a> Parser<'a> {
49364936 |p| {
49374937 let attrs = p. parse_outer_attributes ( ) ?;
49384938 let lo = p. span . lo ;
4939- let mut vis = p. parse_visibility ( false ) ?;
4939+ let mut vis = p. parse_visibility ( ) ?;
49404940 let ty_is_interpolated =
49414941 p. token . is_interpolated ( ) || p. look_ahead ( 1 , |t| t. is_interpolated ( ) ) ;
49424942 let mut ty = p. parse_ty ( ) ?;
@@ -4993,38 +4993,46 @@ impl<'a> Parser<'a> {
49934993 fn parse_struct_decl_field ( & mut self ) -> PResult < ' a , StructField > {
49944994 let attrs = self . parse_outer_attributes ( ) ?;
49954995 let lo = self . span . lo ;
4996- let vis = self . parse_visibility ( true ) ?;
4996+ let vis = self . parse_visibility ( ) ?;
49974997 self . parse_single_struct_field ( lo, vis, attrs)
49984998 }
49994999
5000- // If `allow_path` is false, just parse the `pub` in `pub(path)` (but still parse `pub(crate)`)
5001- fn parse_visibility ( & mut self , allow_path : bool ) -> PResult < ' a , Visibility > {
5002- let pub_crate = |this : & mut Self | {
5003- let span = this. prev_span ;
5004- this. expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5005- Ok ( Visibility :: Crate ( span) )
5006- } ;
5007-
5000+ // Parse `pub`, `pub(crate)` and `pub(in path)` plus shortcuts
5001+ // `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
5002+ fn parse_visibility ( & mut self ) -> PResult < ' a , Visibility > {
50085003 if !self . eat_keyword ( keywords:: Pub ) {
5009- Ok ( Visibility :: Inherited )
5010- } else if !allow_path {
5011- // Look ahead to avoid eating the `(` in `pub(path)` while still parsing `pub(crate)`
5012- if self . token == token:: OpenDelim ( token:: Paren ) &&
5013- self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Crate ) ) {
5014- self . bump ( ) ; self . bump ( ) ;
5015- pub_crate ( self )
5016- } else {
5017- Ok ( Visibility :: Public )
5018- }
5019- } else if !self . eat ( & token:: OpenDelim ( token:: Paren ) ) {
5020- Ok ( Visibility :: Public )
5021- } else if self . eat_keyword ( keywords:: Crate ) {
5022- pub_crate ( self )
5023- } else {
5024- let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ;
5025- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5026- Ok ( Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } )
5027- }
5004+ return Ok ( Visibility :: Inherited )
5005+ }
5006+
5007+ if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
5008+ if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Crate ) ) {
5009+ // `pub(crate)`
5010+ self . bump ( ) ; // `(`
5011+ self . bump ( ) ; // `crate`
5012+ let vis = Visibility :: Crate ( self . prev_span ) ;
5013+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5014+ return Ok ( vis)
5015+ } else if self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: In ) ) {
5016+ // `pub(in path)`
5017+ self . bump ( ) ; // `(`
5018+ self . bump ( ) ; // `in`
5019+ let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ; // `path`
5020+ let vis = Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
5021+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5022+ return Ok ( vis)
5023+ } else if self . look_ahead ( 2 , |t| t == & token:: CloseDelim ( token:: Paren ) ) &&
5024+ self . look_ahead ( 1 , |t| t. is_keyword ( keywords:: Super ) ||
5025+ t. is_keyword ( keywords:: SelfValue ) ) {
5026+ // `pub(self)` or `pub(super)`
5027+ self . bump ( ) ; // `(`
5028+ let path = self . parse_path ( PathStyle :: Mod ) ?. default_to_global ( ) ; // `super`/`self`
5029+ let vis = Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } ;
5030+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?; // `)`
5031+ return Ok ( vis)
5032+ }
5033+ }
5034+
5035+ Ok ( Visibility :: Public )
50285036 }
50295037
50305038 /// Parse defaultness: DEFAULT or nothing
@@ -5499,7 +5507,7 @@ impl<'a> Parser<'a> {
54995507
55005508 let lo = self . span . lo ;
55015509
5502- let visibility = self . parse_visibility ( true ) ?;
5510+ let visibility = self . parse_visibility ( ) ?;
55035511
55045512 if self . eat_keyword ( keywords:: Use ) {
55055513 // USE ITEM
@@ -5774,7 +5782,7 @@ impl<'a> Parser<'a> {
57745782 fn parse_foreign_item ( & mut self ) -> PResult < ' a , Option < ForeignItem > > {
57755783 let attrs = self . parse_outer_attributes ( ) ?;
57765784 let lo = self . span . lo ;
5777- let visibility = self . parse_visibility ( true ) ?;
5785+ let visibility = self . parse_visibility ( ) ?;
57785786
57795787 if self . check_keyword ( keywords:: Static ) {
57805788 // FOREIGN STATIC ITEM
0 commit comments