about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2025-07-19 19:39:27 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2025-07-19 21:43:50 +0000
commit8f77d5463a7e6906b7ac44ee235969a7758ef1ed (patch)
treedc5ba7522ca2604158987daf6cb3863627077fb3 /tests
parent0d9592026226f5a667a0da60c13b955e0b486a07 (diff)
downloadrust-8f77d5463a7e6906b7ac44ee235969a7758ef1ed.tar.gz
rust-8f77d5463a7e6906b7ac44ee235969a7758ef1ed.zip
add non-regression test for issue 144168
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/resolve/underscore-bindings-disambiguators.rs27
-rw-r--r--tests/ui/resolve/underscore-bindings-disambiguators.stderr70
2 files changed, 97 insertions, 0 deletions
diff --git a/tests/ui/resolve/underscore-bindings-disambiguators.rs b/tests/ui/resolve/underscore-bindings-disambiguators.rs
new file mode 100644
index 00000000000..8c89b39f859
--- /dev/null
+++ b/tests/ui/resolve/underscore-bindings-disambiguators.rs
@@ -0,0 +1,27 @@
+// Regression test for issue #144168 where some `_` bindings were incorrectly only allowed once per
+// module, failing with "error[E0428]: the name `_` is defined multiple times".
+
+// This weird/complex setup is reduced from `zerocopy-0.8.25` where the issue was encountered.
+
+#![crate_type = "lib"]
+
+macro_rules! impl_for_transmute_from {
+    () => {
+        const _: () = {};
+    };
+}
+
+mod impls {
+    use super::*;
+    impl_for_transmute_from!();
+    impl_for_transmute_from!();
+    const _: () = todo!(); //~ ERROR: evaluation panicked
+    const _: () = todo!(); //~ ERROR: evaluation panicked
+    const _: () = todo!(); //~ ERROR: evaluation panicked
+    const _: () = todo!(); //~ ERROR: evaluation panicked
+    const _: () = todo!(); //~ ERROR: evaluation panicked
+}
+use X as Y; //~ ERROR: unresolved import
+use Z as W; //~ ERROR: unresolved import
+
+const _: () = todo!(); //~ ERROR: evaluation panicked
diff --git a/tests/ui/resolve/underscore-bindings-disambiguators.stderr b/tests/ui/resolve/underscore-bindings-disambiguators.stderr
new file mode 100644
index 00000000000..0c8081a0c56
--- /dev/null
+++ b/tests/ui/resolve/underscore-bindings-disambiguators.stderr
@@ -0,0 +1,70 @@
+error[E0432]: unresolved import `X`
+  --> $DIR/underscore-bindings-disambiguators.rs:24:5
+   |
+LL | use X as Y;
+   |     -^^^^^
+   |     |
+   |     no `X` in the root
+   |     help: a similar name exists in the module: `_`
+
+error[E0432]: unresolved import `Z`
+  --> $DIR/underscore-bindings-disambiguators.rs:25:5
+   |
+LL | use Z as W;
+   |     -^^^^^
+   |     |
+   |     no `Z` in the root
+   |     help: a similar name exists in the module: `_`
+
+error[E0080]: evaluation panicked: not yet implemented
+  --> $DIR/underscore-bindings-disambiguators.rs:18:19
+   |
+LL |     const _: () = todo!();
+   |                   ^^^^^^^ evaluation of `impls::_` failed here
+   |
+   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0080]: evaluation panicked: not yet implemented
+  --> $DIR/underscore-bindings-disambiguators.rs:19:19
+   |
+LL |     const _: () = todo!();
+   |                   ^^^^^^^ evaluation of `impls::_` failed here
+   |
+   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0080]: evaluation panicked: not yet implemented
+  --> $DIR/underscore-bindings-disambiguators.rs:20:19
+   |
+LL |     const _: () = todo!();
+   |                   ^^^^^^^ evaluation of `impls::_` failed here
+   |
+   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0080]: evaluation panicked: not yet implemented
+  --> $DIR/underscore-bindings-disambiguators.rs:21:19
+   |
+LL |     const _: () = todo!();
+   |                   ^^^^^^^ evaluation of `impls::_` failed here
+   |
+   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0080]: evaluation panicked: not yet implemented
+  --> $DIR/underscore-bindings-disambiguators.rs:22:19
+   |
+LL |     const _: () = todo!();
+   |                   ^^^^^^^ evaluation of `impls::_` failed here
+   |
+   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0080]: evaluation panicked: not yet implemented
+  --> $DIR/underscore-bindings-disambiguators.rs:27:15
+   |
+LL | const _: () = todo!();
+   |               ^^^^^^^ evaluation of `_` failed here
+   |
+   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 8 previous errors
+
+Some errors have detailed explanations: E0080, E0432.
+For more information about an error, try `rustc --explain E0080`.