@@ -3587,7 +3587,7 @@ impl<'a> Parser<'a> {
35873587 }
35883588
35893589 fn parse_pat_range_end ( & mut self ) -> PResult < ' a , P < Expr > > {
3590- if self . is_path_start ( ) {
3590+ if self . token . is_path_start ( ) {
35913591 let lo = self . span . lo ;
35923592 let ( qself, path) = if self . eat_lt ( ) {
35933593 // Parse a qualified path
@@ -3605,12 +3605,6 @@ impl<'a> Parser<'a> {
36053605 }
36063606 }
36073607
3608- fn is_path_start ( & self ) -> bool {
3609- ( self . token == token:: Lt || self . token == token:: ModSep
3610- || self . token . is_ident ( ) || self . token . is_path ( ) )
3611- && !self . token . is_keyword ( keywords:: True ) && !self . token . is_keyword ( keywords:: False )
3612- }
3613-
36143608 /// Parse a pattern.
36153609 pub fn parse_pat ( & mut self ) -> PResult < ' a , P < Pat > > {
36163610 maybe_whole ! ( self , NtPat ) ;
@@ -3661,7 +3655,7 @@ impl<'a> Parser<'a> {
36613655 // Parse box pat
36623656 let subpat = self . parse_pat ( ) ?;
36633657 pat = PatKind :: Box ( subpat) ;
3664- } else if self . is_path_start ( ) {
3658+ } else if self . token . is_path_start ( ) {
36653659 // Parse pattern starting with a path
36663660 if self . token . is_plain_ident ( ) && self . look_ahead ( 1 , |t| * t != token:: DotDotDot &&
36673661 * t != token:: OpenDelim ( token:: Brace ) &&
@@ -4930,7 +4924,7 @@ impl<'a> Parser<'a> {
49304924
49314925 let mut attrs = self . parse_outer_attributes ( ) ?;
49324926 let lo = self . span . lo ;
4933- let vis = self . parse_visibility ( true ) ?;
4927+ let vis = self . parse_visibility ( ) ?;
49344928 let defaultness = self . parse_defaultness ( ) ?;
49354929 let ( name, node) = if self . eat_keyword ( keywords:: Type ) {
49364930 let name = self . parse_ident ( ) ?;
@@ -5242,7 +5236,7 @@ impl<'a> Parser<'a> {
52425236 |p| {
52435237 let attrs = p. parse_outer_attributes ( ) ?;
52445238 let lo = p. span . lo ;
5245- let vis = p. parse_visibility ( false ) ?;
5239+ let vis = p. parse_visibility ( ) ?;
52465240 let ty = p. parse_ty_sum ( ) ?;
52475241 Ok ( StructField {
52485242 span : mk_sp ( lo, p. span . hi ) ,
@@ -5283,24 +5277,28 @@ impl<'a> Parser<'a> {
52835277 /// Parse an element of a struct definition
52845278 fn parse_struct_decl_field ( & mut self ) -> PResult < ' a , StructField > {
52855279 let attrs = self . parse_outer_attributes ( ) ?;
5286- let vis = self . parse_visibility ( true ) ?;
5280+ let vis = self . parse_visibility ( ) ?;
52875281 self . parse_single_struct_field ( vis, attrs)
52885282 }
52895283
5290- fn parse_visibility ( & mut self , allow_restricted : bool ) -> PResult < ' a , Visibility > {
5284+ fn parse_visibility ( & mut self ) -> PResult < ' a , Visibility > {
52915285 if !self . eat_keyword ( keywords:: Pub ) {
52925286 Ok ( Visibility :: Inherited )
5293- } else if !allow_restricted || !self . eat ( & token:: OpenDelim ( token:: Paren ) ) {
5287+ } else if !self . check ( & token:: OpenDelim ( token:: Paren ) ) ||
5288+ !self . look_ahead ( 1 , |t| t. is_path_start ( ) ) {
52945289 Ok ( Visibility :: Public )
5295- } else if self . eat_keyword ( keywords:: Crate ) {
5296- let span = self . last_span ;
5297- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5298- Ok ( Visibility :: Crate ( span) )
52995290 } else {
5300- let path = self . with_res ( Restrictions :: ALLOW_MODULE_PATHS ,
5301- |this| this. parse_path ( NoTypesAllowed ) ) ?;
5302- self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5303- Ok ( Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } )
5291+ self . bump ( ) ;
5292+ if self . eat_keyword ( keywords:: Crate ) {
5293+ let span = self . last_span ;
5294+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5295+ Ok ( Visibility :: Crate ( span) )
5296+ } else {
5297+ let path = self . with_res ( Restrictions :: ALLOW_MODULE_PATHS ,
5298+ |this| this. parse_path ( NoTypesAllowed ) ) ?;
5299+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
5300+ Ok ( Visibility :: Restricted { path : P ( path) , id : ast:: DUMMY_NODE_ID } )
5301+ }
53045302 }
53055303 }
53065304
@@ -5763,7 +5761,7 @@ impl<'a> Parser<'a> {
57635761
57645762 let lo = self . span . lo ;
57655763
5766- let visibility = self . parse_visibility ( true ) ?;
5764+ let visibility = self . parse_visibility ( ) ?;
57675765
57685766 if self . eat_keyword ( keywords:: Use ) {
57695767 // USE ITEM
@@ -6013,7 +6011,7 @@ impl<'a> Parser<'a> {
60136011 fn parse_foreign_item ( & mut self ) -> PResult < ' a , Option < ForeignItem > > {
60146012 let attrs = self . parse_outer_attributes ( ) ?;
60156013 let lo = self . span . lo ;
6016- let visibility = self . parse_visibility ( true ) ?;
6014+ let visibility = self . parse_visibility ( ) ?;
60176015
60186016 if self . check_keyword ( keywords:: Static ) {
60196017 // FOREIGN STATIC ITEM
0 commit comments