Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions tests/crashes/123911.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/crashes/123912.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ known-bug: #97006
//@ compile-flags: -Zunpretty=hir

#![allow(unused)]
// issue#97006

macro_rules! m {
($attr_path: path) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/macros/genercs-in-path-with-prettry-hir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: unexpected generic arguments in path
--> $DIR/genercs-in-path-with-prettry-hir.rs:12:10
|
LL | m!(inline<u8>);
| ^^^^

error: aborting due to 1 previous error

15 changes: 15 additions & 0 deletions tests/ui/macros/genercs-in-path-with-prettry-hir.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
//@ compile-flags: -Zunpretty=hir

// issue#97006

macro_rules! m { ($attr_path: path) => { #[$attr_path] fn f() {} } }
#[

inline]
fn f() { }

fn main() { }
19 changes: 19 additions & 0 deletions tests/ui/macros/macro-expand-within-generics-in-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// issue#123911
// issue#123912

macro_rules! m {
($p: path) => {
#[$p]
struct S;
};
}

macro_rules! p {
() => {};
}

m!(generic<p!()>);
//~^ ERROR: unexpected generic arguments in path
//~| ERROR: cannot find attribute `generic` in this scope

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/macros/macro-expand-within-generics-in-path.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: unexpected generic arguments in path
--> $DIR/macro-expand-within-generics-in-path.rs:15:11
|
LL | m!(generic<p!()>);
| ^^^^^^

error: cannot find attribute `generic` in this scope
--> $DIR/macro-expand-within-generics-in-path.rs:15:4
|
LL | m!(generic<p!()>);
| ^^^^^^^

error: aborting due to 2 previous errors

1 change: 0 additions & 1 deletion tests/ui/span/macro-ty-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ fn main() {
foo::<>!(); //~ ERROR generic arguments in macro path
m!(Default<>);
//~^ ERROR unexpected generic arguments in path
//~^^ ERROR generic arguments in macro path
}
8 changes: 1 addition & 7 deletions tests/ui/span/macro-ty-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,5 @@ error: unexpected generic arguments in path
LL | m!(Default<>);
| ^^

error: generic arguments in macro path
--> $DIR/macro-ty-params.rs:12:15
|
LL | m!(Default<>);
| ^^

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors