@@ -228,48 +228,61 @@ fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
228228
229229 let m = p. start ( ) ;
230230 p. bump ( T ! [ pub ] ) ;
231- if p. at ( T ! [ '(' ] ) {
232- match p. nth ( 1 ) {
233- // test crate_visibility
234- // pub(crate) struct S;
235- // pub(self) struct S;
236- // pub(super) struct S;
237-
238- // test_err crate_visibility_empty_recover
239- // pub() struct S;
240-
241- // test pub_parens_typepath
242- // struct B(pub (super::A));
243- // struct B(pub (crate::A,));
244- T ! [ crate ] | T ! [ self ] | T ! [ super ] | T ! [ ident] | T ! [ ')' ] if p. nth ( 2 ) != T ! [ : ] => {
245- // If we are in a tuple struct, then the parens following `pub`
246- // might be an tuple field, not part of the visibility. So in that
247- // case we don't want to consume an identifier.
248-
249- // test pub_tuple_field
250- // struct MyStruct(pub (u32, u32));
251- // struct MyStruct(pub (u32));
252- // struct MyStruct(pub ());
253- if !( in_tuple_field && matches ! ( p. nth( 1 ) , T ![ ident] | T ![ ')' ] ) ) {
254- p. bump ( T ! [ '(' ] ) ;
255- paths:: vis_path ( p) ;
256- p. expect ( T ! [ ')' ] ) ;
257- }
258- }
259- // test crate_visibility_in
260- // pub(in super::A) struct S;
261- // pub(in crate) struct S;
262- T ! [ in] => {
231+ opt_visibility_inner ( p, in_tuple_field) ;
232+ m. complete ( p, VISIBILITY ) ;
233+ true
234+ }
235+
236+ fn opt_visibility_inner ( p : & mut Parser < ' _ > , in_tuple_field : bool ) -> bool {
237+ if !p. at ( T ! [ '(' ] ) {
238+ return false ;
239+ }
240+
241+ match p. nth ( 1 ) {
242+ // test crate_visibility
243+ // pub(crate) struct S;
244+ // pub(self) struct S;
245+ // pub(super) struct S;
246+
247+ // test_err crate_visibility_empty_recover
248+ // pub() struct S;
249+
250+ // test pub_parens_typepath
251+ // struct B(pub (super::A));
252+ // struct B(pub (crate::A,));
253+ T ! [ crate ] | T ! [ self ] | T ! [ super ] | T ! [ ident] | T ! [ ')' ] if p. nth ( 2 ) != T ! [ : ] => {
254+ // If we are in a tuple struct, then the parens following `pub`
255+ // might be an tuple field, not part of the visibility. So in that
256+ // case we don't want to consume an identifier.
257+
258+ // test pub_tuple_field
259+ // struct MyStruct(pub (u32, u32));
260+ // struct MyStruct(pub (u32));
261+ // struct MyStruct(pub ());
262+ if !( in_tuple_field && matches ! ( p. nth( 1 ) , T ![ ident] | T ![ ')' ] ) ) {
263+ let m = p. start ( ) ;
263264 p. bump ( T ! [ '(' ] ) ;
264- p. bump ( T ! [ in] ) ;
265265 paths:: vis_path ( p) ;
266266 p. expect ( T ! [ ')' ] ) ;
267+ m. complete ( p, VISIBILITY_INNER ) ;
268+ return true ;
267269 }
268- _ => { }
269270 }
271+ // test crate_visibility_in
272+ // pub(in super::A) struct S;
273+ // pub(in crate) struct S;
274+ T ! [ in] => {
275+ let m = p. start ( ) ;
276+ p. bump ( T ! [ '(' ] ) ;
277+ p. bump ( T ! [ in] ) ;
278+ paths:: vis_path ( p) ;
279+ p. expect ( T ! [ ')' ] ) ;
280+ m. complete ( p, VISIBILITY_INNER ) ;
281+ return true ;
282+ }
283+ _ => { }
270284 }
271- m. complete ( p, VISIBILITY ) ;
272- true
285+ false
273286}
274287
275288fn opt_rename ( p : & mut Parser < ' _ > ) {
0 commit comments