@@ -19,6 +19,10 @@ pub(super) fn use_path(p: &mut Parser<'_>) {
1919 path ( p, Mode :: Use ) ;
2020}
2121
22+ pub ( super ) fn attr_path ( p : & mut Parser < ' _ > ) {
23+ path ( p, Mode :: Attr ) ;
24+ }
25+
2226pub ( crate ) fn type_path ( p : & mut Parser < ' _ > ) {
2327 path ( p, Mode :: Type ) ;
2428}
@@ -37,6 +41,7 @@ pub(crate) fn type_path_for_qualifier(
3741#[ derive( Clone , Copy , Eq , PartialEq ) ]
3842enum Mode {
3943 Use ,
44+ Attr ,
4045 Type ,
4146 Expr ,
4247}
@@ -93,12 +98,7 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
9398 p. error ( "expected `::`" ) ;
9499 }
95100 } else {
96- let empty = if first {
97- p. eat ( T ! [ :: ] ) ;
98- false
99- } else {
100- true
101- } ;
101+ let mut empty = if first { !p. eat ( T ! [ :: ] ) } else { true } ;
102102 match p. current ( ) {
103103 IDENT => {
104104 name_ref ( p) ;
@@ -114,10 +114,13 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
114114 _ => {
115115 let recover_set = match mode {
116116 Mode :: Use => items:: ITEM_RECOVERY_SET ,
117+ Mode :: Attr => {
118+ items:: ITEM_RECOVERY_SET . union ( TokenSet :: new ( & [ T ! [ ']' ] , T ! [ =] , T ! [ #] ] ) )
119+ }
117120 Mode :: Type => TYPE_PATH_SEGMENT_RECOVERY_SET ,
118121 Mode :: Expr => EXPR_PATH_SEGMENT_RECOVERY_SET ,
119122 } ;
120- p. err_recover ( "expected identifier" , recover_set) ;
123+ empty &= p. err_recover ( "expected identifier" , recover_set) ;
121124 if empty {
122125 // test_err empty_segment
123126 // use crate::;
@@ -132,7 +135,7 @@ fn path_segment(p: &mut Parser<'_>, mode: Mode, first: bool) {
132135
133136fn opt_path_type_args ( p : & mut Parser < ' _ > , mode : Mode ) {
134137 match mode {
135- Mode :: Use => { }
138+ Mode :: Use | Mode :: Attr => { }
136139 Mode :: Type => {
137140 // test typepathfn_with_coloncolon
138141 // type F = Start::(Middle) -> (Middle)::End;
0 commit comments