diff options
| author | bohan <bohan-zhang@foxmail.com> | 2024-04-24 11:28:45 +0800 |
|---|---|---|
| committer | bohan <bohan-zhang@foxmail.com> | 2024-05-11 00:13:27 +0800 |
| commit | f70f9000362e4d207a6c7d0d63f3b11272878ccc (patch) | |
| tree | 640b09652502ac9d6baee29645066c840fc78629 /compiler/rustc_parse/src/parser/path.rs | |
| parent | cf774742b6029e0c2e00654975c001d192063b5b (diff) | |
| download | rust-f70f9000362e4d207a6c7d0d63f3b11272878ccc.tar.gz rust-f70f9000362e4d207a6c7d0d63f3b11272878ccc.zip | |
ignore generics args in attribute paths
Diffstat (limited to 'compiler/rustc_parse/src/parser/path.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index b97ec8c613d..3636a357978 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -160,7 +160,7 @@ impl<'a> Parser<'a> { style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, Path> { - let reject_generics_if_mod_style = |parser: &Parser<'_>, path: &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 { @@ -178,21 +178,26 @@ impl<'a> Parser<'a> { .map(|arg| arg.span()) .collect::<Vec<_>>(); parser.dcx().emit_err(errors::GenericsInPath { span }); + // Ignore these arguments to prevent unexpected behaviors. + let segments = path + .segments + .iter() + .map(|segment| PathSegment { ident: segment.ident, id: segment.id, args: None }) + .collect(); + Path { segments, ..path } + } else { + path } }; - maybe_whole!(self, NtPath, |path| { - reject_generics_if_mod_style(self, &path); - path.into_inner() - }); + maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner())); if let token::Interpolated(nt) = &self.token.kind { if let token::NtTy(ty) = &nt.0 { 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); + return Ok(reject_generics_if_mod_style(self, path)); } } } |
