File tree 1 file changed +24
-10
lines changed
compiler/rustc_parse/src/parser
1 file changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -139,19 +139,32 @@ impl<'a> Parser<'a> {
139
139
style : PathStyle ,
140
140
ty_generics : Option < & Generics > ,
141
141
) -> PResult < ' a , Path > {
142
- maybe_whole ! ( self , NtPath , |path| {
142
+ let reject_generics_if_mod_style = |parser : & Parser < ' _ > , path : & Path | {
143
+ // Ensure generic arguments don't end up in attribute paths, such as:
144
+ //
145
+ // macro_rules! m {
146
+ // ($p:path) => { #[$p] struct S; }
147
+ // }
148
+ //
149
+ // m!(inline<u8>); //~ ERROR: unexpected generic arguments in path
150
+ //
143
151
if style == PathStyle :: Mod && path. segments . iter ( ) . any ( |segment| segment. args . is_some ( ) )
144
152
{
145
- self . struct_span_err(
146
- path. segments
147
- . iter( )
148
- . filter_map( |segment| segment. args. as_ref( ) )
149
- . map( |arg| arg. span( ) )
150
- . collect:: <Vec <_>>( ) ,
151
- "unexpected generic arguments in path" ,
152
- )
153
- . emit( ) ;
153
+ parser
154
+ . struct_span_err (
155
+ path. segments
156
+ . iter ( )
157
+ . filter_map ( |segment| segment. args . as_ref ( ) )
158
+ . map ( |arg| arg. span ( ) )
159
+ . collect :: < Vec < _ > > ( ) ,
160
+ "unexpected generic arguments in path" ,
161
+ )
162
+ . emit ( ) ;
154
163
}
164
+ } ;
165
+
166
+ maybe_whole ! ( self , NtPath , |path| {
167
+ reject_generics_if_mod_style( self , & path) ;
155
168
path
156
169
} ) ;
157
170
@@ -160,6 +173,7 @@ impl<'a> Parser<'a> {
160
173
if let ast:: TyKind :: Path ( None , path) = & ty. kind {
161
174
let path = path. clone ( ) ;
162
175
self . bump ( ) ;
176
+ reject_generics_if_mod_style ( self , & path) ;
163
177
return Ok ( path) ;
164
178
}
165
179
}
You can’t perform that action at this time.
0 commit comments