Skip to content

Commit

Permalink
Reject generic arguments on mod style interpolated path
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 25, 2021
1 parent 0cbb00f commit 87a7def
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>); //~ 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::<Vec<_>>(),
"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::<Vec<_>>(),
"unexpected generic arguments in path",
)
.emit();
}
};

maybe_whole!(self, NtPath, |path| {
reject_generics_if_mod_style(self, &path);
path
});

Expand All @@ -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);
}
}
Expand Down

0 comments on commit 87a7def

Please sign in to comment.