File tree Expand file tree Collapse file tree 1 file changed +24
-10
lines changed
compiler/rustc_parse/src/parser Expand file tree Collapse file tree 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> {
139139 style : PathStyle ,
140140 ty_generics : Option < & Generics > ,
141141 ) -> 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+ //
143151 if style == PathStyle :: Mod && path. segments . iter ( ) . any ( |segment| segment. args . is_some ( ) )
144152 {
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 ( ) ;
154163 }
164+ } ;
165+
166+ maybe_whole ! ( self , NtPath , |path| {
167+ reject_generics_if_mod_style( self , & path) ;
155168 path
156169 } ) ;
157170
@@ -160,6 +173,7 @@ impl<'a> Parser<'a> {
160173 if let ast:: TyKind :: Path ( None , path) = & ty. kind {
161174 let path = path. clone ( ) ;
162175 self . bump ( ) ;
176+ reject_generics_if_mod_style ( self , & path) ;
163177 return Ok ( path) ;
164178 }
165179 }
You can’t perform that action at this time.
0 commit comments