about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-10-02 15:23:49 +0000
committerbors <bors@rust-lang.org>2025-10-02 15:23:49 +0000
commit5c7ae0c7ed184c603e5224604a9f33ca0e8e0b36 (patch)
tree680293a7177ccd6aa8287bb24249545861bb23e4
parent94ecb52bbeeccc990545d4ebc9e9c35dcaf285e3 (diff)
parenta7eed086b913d708c9f38ce9c833e403f00fc15d (diff)
downloadrust-5c7ae0c7ed184c603e5224604a9f33ca0e8e0b36.tar.gz
rust-5c7ae0c7ed184c603e5224604a9f33ca0e8e0b36.zip
Auto merge of #147196 - LorrensP-2158466:same-res-ambiguity-test, r=petrochenkov
Test: Ambigious bindings in same namespace with the same res

Add a test based on the discussion [here](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/542316157) and related to https://github.com/rust-lang/rust/issues/145575#issuecomment-3228868375.

This is the most reduced form I could create that passes on nightly but fails with rust-lang/rust#145108 (see [#gsoc > Project: Parallel Macro Expansion @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/542335131)).

Also not sure about the test names.

r? `@petrochenkov`
-rw-r--r--tests/ui/imports/auxiliary/same-res-ambigious-extern-fail.rs16
-rw-r--r--tests/ui/imports/auxiliary/same-res-ambigious-extern-macro.rs8
-rw-r--r--tests/ui/imports/auxiliary/same-res-ambigious-extern.rs11
-rw-r--r--tests/ui/imports/same-res-ambigious.fail.stderr20
-rw-r--r--tests/ui/imports/same-res-ambigious.nightly-fail.stderr20
-rw-r--r--tests/ui/imports/same-res-ambigious.rs11
6 files changed, 86 insertions, 0 deletions
diff --git a/tests/ui/imports/auxiliary/same-res-ambigious-extern-fail.rs b/tests/ui/imports/auxiliary/same-res-ambigious-extern-fail.rs
new file mode 100644
index 00000000000..61a8d8f0054
--- /dev/null
+++ b/tests/ui/imports/auxiliary/same-res-ambigious-extern-fail.rs
@@ -0,0 +1,16 @@
+//@ edition:2018
+//@ proc-macro: same-res-ambigious-extern-macro.rs
+
+macro_rules! globbing{
+    () => {
+        pub use same_res_ambigious_extern_macro::*;
+    }
+}
+
+#[macro_use] // this imports the `RustEmbed` macro with `pub(crate)` visibility
+extern crate same_res_ambigious_extern_macro;
+globbing! {} // this imports the same `RustEmbed` macro with `pub` visibility
+
+pub trait RustEmbed {}
+
+pub use RustEmbed as Embed;
diff --git a/tests/ui/imports/auxiliary/same-res-ambigious-extern-macro.rs b/tests/ui/imports/auxiliary/same-res-ambigious-extern-macro.rs
new file mode 100644
index 00000000000..4e9b8427092
--- /dev/null
+++ b/tests/ui/imports/auxiliary/same-res-ambigious-extern-macro.rs
@@ -0,0 +1,8 @@
+//@ edition: 2018
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro_derive(RustEmbed)]
+pub fn rust_embed_derive(_input: TokenStream) -> TokenStream {
+    TokenStream::new()
+}
diff --git a/tests/ui/imports/auxiliary/same-res-ambigious-extern.rs b/tests/ui/imports/auxiliary/same-res-ambigious-extern.rs
new file mode 100644
index 00000000000..5269dcd0b17
--- /dev/null
+++ b/tests/ui/imports/auxiliary/same-res-ambigious-extern.rs
@@ -0,0 +1,11 @@
+//@ edition:2018
+//@ proc-macro: same-res-ambigious-extern-macro.rs
+
+#[macro_use] // this imports the `RustEmbed` macro with `pub(crate)` visibility
+extern crate same_res_ambigious_extern_macro;
+// this imports the same `RustEmbed` macro with `pub` visibility
+pub use same_res_ambigious_extern_macro::*;
+
+pub trait RustEmbed {}
+
+pub use RustEmbed as Embed;
diff --git a/tests/ui/imports/same-res-ambigious.fail.stderr b/tests/ui/imports/same-res-ambigious.fail.stderr
new file mode 100644
index 00000000000..dfd7c5a5f94
--- /dev/null
+++ b/tests/ui/imports/same-res-ambigious.fail.stderr
@@ -0,0 +1,20 @@
+error[E0603]: derive macro `Embed` is private
+  --> $DIR/same-res-ambigious.rs:8:28
+   |
+LL | #[derive(ambigious_extern::Embed)]
+   |                            ^^^^^ private derive macro
+   |
+note: the derive macro `Embed` is defined here
+  --> $DIR/auxiliary/same-res-ambigious-extern-fail.rs:16:9
+   |
+LL | pub use RustEmbed as Embed;
+   |         ^^^^^^^^^
+help: import `Embed` directly
+   |
+LL - #[derive(ambigious_extern::Embed)]
+LL + #[derive(same_res_ambigious_extern_macro::RustEmbed)]
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0603`.
diff --git a/tests/ui/imports/same-res-ambigious.nightly-fail.stderr b/tests/ui/imports/same-res-ambigious.nightly-fail.stderr
new file mode 100644
index 00000000000..dfd7c5a5f94
--- /dev/null
+++ b/tests/ui/imports/same-res-ambigious.nightly-fail.stderr
@@ -0,0 +1,20 @@
+error[E0603]: derive macro `Embed` is private
+  --> $DIR/same-res-ambigious.rs:8:28
+   |
+LL | #[derive(ambigious_extern::Embed)]
+   |                            ^^^^^ private derive macro
+   |
+note: the derive macro `Embed` is defined here
+  --> $DIR/auxiliary/same-res-ambigious-extern-fail.rs:16:9
+   |
+LL | pub use RustEmbed as Embed;
+   |         ^^^^^^^^^
+help: import `Embed` directly
+   |
+LL - #[derive(ambigious_extern::Embed)]
+LL + #[derive(same_res_ambigious_extern_macro::RustEmbed)]
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0603`.
diff --git a/tests/ui/imports/same-res-ambigious.rs b/tests/ui/imports/same-res-ambigious.rs
new file mode 100644
index 00000000000..b5c13a15b7c
--- /dev/null
+++ b/tests/ui/imports/same-res-ambigious.rs
@@ -0,0 +1,11 @@
+//@ edition: 2018
+//@ revisions: fail pass
+//@[pass] check-pass
+//@[pass] aux-crate: ambigious_extern=same-res-ambigious-extern.rs
+//@[fail] aux-crate: ambigious_extern=same-res-ambigious-extern-fail.rs
+// see https://github.com/rust-lang/rust/pull/147196
+
+#[derive(ambigious_extern::Embed)] //[fail]~ ERROR: derive macro `Embed` is private
+struct Foo{}
+
+fn main(){}