From 0cbb00f89875c085181f1d55bbe46d39ec36be3f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 22 Nov 2021 19:43:51 -0800 Subject: Let qpath contain NtTy: <$:ty as $:ty>::rest --- compiler/rustc_parse/src/parser/path.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 7f8fadb33bd..04ede1f7e3b 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -155,6 +155,16 @@ impl<'a> Parser<'a> { path }); + if let token::Interpolated(nt) = &self.token.kind { + if let token::NtTy(ty) = &**nt { + if let ast::TyKind::Path(None, path) = &ty.kind { + let path = path.clone(); + self.bump(); + return Ok(path); + } + } + } + let lo = self.token.span; let mut segments = Vec::new(); let mod_sep_ctxt = self.token.span.ctxt(); -- cgit 1.4.1-3-g733a5 From 87a7defa8e08c971a30b152509c6c1ab9f718092 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 22 Nov 2021 20:16:28 -0800 Subject: Reject generic arguments on mod style interpolated path --- compiler/rustc_parse/src/parser/path.rs | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 04ede1f7e3b..e140b23f5d6 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -139,19 +139,32 @@ impl<'a> Parser<'a> { style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, Path> { - maybe_whole!(self, NtPath, |path| { + let reject_generics_if_mod_style = |parser: &Parser<'_>, path: &Path| { + // Ensure generic arguments don't end up in attribute paths, such as: + // + // macro_rules! m { + // ($p:path) => { #[$p] struct S; } + // } + // + // m!(inline); //~ ERROR: unexpected generic arguments in path + // if style == PathStyle::Mod && path.segments.iter().any(|segment| segment.args.is_some()) { - self.struct_span_err( - path.segments - .iter() - .filter_map(|segment| segment.args.as_ref()) - .map(|arg| arg.span()) - .collect::>(), - "unexpected generic arguments in path", - ) - .emit(); + parser + .struct_span_err( + path.segments + .iter() + .filter_map(|segment| segment.args.as_ref()) + .map(|arg| arg.span()) + .collect::>(), + "unexpected generic arguments in path", + ) + .emit(); } + }; + + maybe_whole!(self, NtPath, |path| { + reject_generics_if_mod_style(self, &path); path }); @@ -160,6 +173,7 @@ impl<'a> Parser<'a> { if let ast::TyKind::Path(None, path) = &ty.kind { let path = path.clone(); self.bump(); + reject_generics_if_mod_style(self, &path); return Ok(path); } } -- cgit 1.4.1-3-g733a5