Reject generic arguments on mod style interpolated path
This commit is contained in:
parent
0cbb00f898
commit
87a7defa8e
1 changed files with 24 additions and 10 deletions
|
@ -139,19 +139,32 @@ impl<'a> Parser<'a> {
|
||||||
style: PathStyle,
|
style: PathStyle,
|
||||||
ty_generics: Option<&Generics>,
|
ty_generics: Option<&Generics>,
|
||||||
) -> PResult<'a, Path> {
|
) -> 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<u8>); //~ ERROR: unexpected generic arguments in path
|
||||||
|
//
|
||||||
if style == PathStyle::Mod && path.segments.iter().any(|segment| segment.args.is_some())
|
if style == PathStyle::Mod && path.segments.iter().any(|segment| segment.args.is_some())
|
||||||
{
|
{
|
||||||
self.struct_span_err(
|
parser
|
||||||
path.segments
|
.struct_span_err(
|
||||||
.iter()
|
path.segments
|
||||||
.filter_map(|segment| segment.args.as_ref())
|
.iter()
|
||||||
.map(|arg| arg.span())
|
.filter_map(|segment| segment.args.as_ref())
|
||||||
.collect::<Vec<_>>(),
|
.map(|arg| arg.span())
|
||||||
"unexpected generic arguments in path",
|
.collect::<Vec<_>>(),
|
||||||
)
|
"unexpected generic arguments in path",
|
||||||
.emit();
|
)
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
maybe_whole!(self, NtPath, |path| {
|
||||||
|
reject_generics_if_mod_style(self, &path);
|
||||||
path
|
path
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -160,6 +173,7 @@ impl<'a> Parser<'a> {
|
||||||
if let ast::TyKind::Path(None, path) = &ty.kind {
|
if let ast::TyKind::Path(None, path) = &ty.kind {
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
self.bump();
|
self.bump();
|
||||||
|
reject_generics_if_mod_style(self, &path);
|
||||||
return Ok(path);
|
return Ok(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue