From 8f77d5463a7e6906b7ac44ee235969a7758ef1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Sat, 19 Jul 2025 19:39:27 +0000 Subject: [PATCH] add non-regression test for issue 144168 --- .../underscore-bindings-disambiguators.rs | 27 +++++++ .../underscore-bindings-disambiguators.stderr | 70 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/ui/resolve/underscore-bindings-disambiguators.rs create mode 100644 tests/ui/resolve/underscore-bindings-disambiguators.stderr diff --git a/tests/ui/resolve/underscore-bindings-disambiguators.rs b/tests/ui/resolve/underscore-bindings-disambiguators.rs new file mode 100644 index 0000000000000..8c89b39f8590c --- /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 0000000000000..0c8081a0c5647 --- /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`.