ignore generics args in attribute paths
This commit is contained in:
parent
cf774742b6
commit
f70f900036
10 changed files with 70 additions and 48 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue