about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/parser/path.rs19
-rw-r--r--tests/crashes/123911.rs16
-rw-r--r--tests/crashes/123912.rs15
-rw-r--r--tests/ui/macros/genercs-in-path-with-prettry-hir.rs (renamed from tests/crashes/97006.rs)3
-rw-r--r--tests/ui/macros/genercs-in-path-with-prettry-hir.stderr8
-rw-r--r--tests/ui/macros/genercs-in-path-with-prettry-hir.stdout15
-rw-r--r--tests/ui/macros/macro-expand-within-generics-in-path.rs19
-rw-r--r--tests/ui/macros/macro-expand-within-generics-in-path.stderr14
-rw-r--r--tests/ui/span/macro-ty-params.rs1
-rw-r--r--tests/ui/span/macro-ty-params.stderr8
10 files changed, 70 insertions, 48 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));
                 }
             }
         }
diff --git a/tests/crashes/123911.rs b/tests/crashes/123911.rs
deleted file mode 100644
index 1a4d6a79512..00000000000
--- a/tests/crashes/123911.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-//@ known-bug: #123911
-
-macro_rules! m {
-    ($attr_path: path) => {
-        #[$attr_path]
-        fn f() {}
-    }
-}
-
-m!(inline<{
-    let a = CharCharFloat { a: 1 };
-    let b = rustrt::rust_dbg_abi_4(a);
-    println!("a: {}", b.a);
-}>);
-
-fn main() {}
diff --git a/tests/crashes/123912.rs b/tests/crashes/123912.rs
deleted file mode 100644
index 35216caabcd..00000000000
--- a/tests/crashes/123912.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//@ known-bug: #123912
-
-macro_rules! m {
-    ($attr_path: path) => {
-        #[$attr_path]
-        fn f() {}
-    }
-}
-
-m!(inline<{
-    let a = CharCharFloat { a: 1 };
-    println!("a: {}", a);
-}>);
-
-fn main() {}
diff --git a/tests/crashes/97006.rs b/tests/ui/macros/genercs-in-path-with-prettry-hir.rs
index c8dfa52ebee..84370fcebbc 100644
--- a/tests/crashes/97006.rs
+++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.rs
@@ -1,7 +1,6 @@
-//@ known-bug: #97006
 //@ compile-flags: -Zunpretty=hir
 
-#![allow(unused)]
+// issue#97006
 
 macro_rules! m {
     ($attr_path: path) => {
diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr b/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr
new file mode 100644
index 00000000000..8fcc7c6fbff
--- /dev/null
+++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr
@@ -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
+
diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout
new file mode 100644
index 00000000000..e9ee59abfae
--- /dev/null
+++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout
@@ -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() { }
diff --git a/tests/ui/macros/macro-expand-within-generics-in-path.rs b/tests/ui/macros/macro-expand-within-generics-in-path.rs
new file mode 100644
index 00000000000..017d5152221
--- /dev/null
+++ b/tests/ui/macros/macro-expand-within-generics-in-path.rs
@@ -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() {}
diff --git a/tests/ui/macros/macro-expand-within-generics-in-path.stderr b/tests/ui/macros/macro-expand-within-generics-in-path.stderr
new file mode 100644
index 00000000000..72026c41050
--- /dev/null
+++ b/tests/ui/macros/macro-expand-within-generics-in-path.stderr
@@ -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
+
diff --git a/tests/ui/span/macro-ty-params.rs b/tests/ui/span/macro-ty-params.rs
index cf28b0255d1..c7ce9b9faed 100644
--- a/tests/ui/span/macro-ty-params.rs
+++ b/tests/ui/span/macro-ty-params.rs
@@ -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
 }
diff --git a/tests/ui/span/macro-ty-params.stderr b/tests/ui/span/macro-ty-params.stderr
index 7023ef8cd1c..138cd2598a1 100644
--- a/tests/ui/span/macro-ty-params.stderr
+++ b/tests/ui/span/macro-ty-params.stderr
@@ -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