Repository navigation
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
auto-reduced (treereduce-rust):
macro_rules! exported {
() => {
#[macro_export]
macro_rules! exported {
() => {};
}
};
}
use inner1::*;
mod inner1 {
pub macro exported() {}
}
exported!();
mod inner1 {
pub macro exported() {}
}original:
#![feature(decl_macro)]
macro_rules! exported { () => {
#[macro_export]
macro_rules! exported {
() => ()
}
}}
macro_rules! define_panic { () => {
#[macro_export]
macro_rules! panic {
() => ()
}
}}
macro_rules! define_include { () => {
#[macro_export]
define_include! include {
() => ()
}
}}
use inner1::*;
mod inner1 {
pub macro exported() {}
}
exported!(); //~ ERROR `exported` is ambiguous
mod inner2 {
define_exported!();
}
fn main() {
panic!(); //~ ERROR `panic` is ambiguous
}
mod inner1 {
pub macro exported() {}
}
mod inner4 {
define_include!();
}
include!(); //~ ERROR `include` is ambiguousVersion information
rustc 1.92.0-nightly (96fe3c31c 2025-10-22)
binary: rustc
commit-hash: 96fe3c31c2ec385f3d3263346bcdde3d118cdaf6
commit-date: 2025-10-22
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.3
Possibly related line of code:
rust/compiler/rustc_resolve/src/lib.rs
Lines 2221 to 2233 in 96fe3c3
| // Scoping for `macro_rules` behaves like scoping for `let` at module level, in general. | |
| // | |
| // panic on index should be impossible, the only name_bindings passed in should be from | |
| // `resolve_ident_in_scope_set` which will always refer to a local binding from an | |
| // import or macro definition | |
| let macro_rules = &self.binding_parent_modules[¯o_rules]; | |
| let modularized = &self.binding_parent_modules[&modularized]; | |
| macro_rules.nearest_parent_mod() == modularized.nearest_parent_mod() | |
| && modularized.is_ancestor_of(*macro_rules) | |
| } | |
| fn extern_prelude_get_item<'r>( | |
| mut self: CmResolver<'r, 'ra, 'tcx>, |
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc
Program output
error[E0428]: the name `inner1` is defined multiple times
--> /tmp/icemaker_global_tempdir.IHNZJtiZqw9U/rustc_testrunner_tmpdir_reporting.o9ajPEvQOkST/mvce.rs:18:1
|
12 | mod inner1 {
| ---------- previous definition of the module `inner1` here
...
18 | mod inner1 {
| ^^^^^^^^^^ `inner1` redefined here
|
= note: `inner1` must be defined only once in the type namespace of this module
thread 'rustc' (1387835) panicked at compiler/rustc_resolve/src/lib.rs:2227:55:
no entry found for key
stack backtrace:
0: 0x7f73eb220083 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6e40e136e4c75713
1: 0x7f73eb801b98 - core::fmt::write::h44a6b5f73be4b8ea
2: 0x7f73eb1d4003 - std::io::Write::write_fmt::hfb879e147e8c721c
3: 0x7f73eb1e56e2 - std::sys::backtrace::BacktraceLock::print::h1beb9e695c8aaf93
4: 0x7f73eb1eb7b9 - std::panicking::default_hook::{{closure}}::hf5989796a97777f7
5: 0x7f73eb1eb2e3 - std::panicking::default_hook::hb2e00ecc05dfa218
6: 0x7f73ea1f75a7 - std[b944056449750609]::panicking::update_hook::<alloc[9e3a1fe8dcc7efa7]::boxed::Box<rustc_driver_impl[73351eb39aec07fc]::install_ice_hook::{closure#1}>>::{closure#0}
7: 0x7f73eb1ebbdf - std::panicking::panic_with_hook::hfbbd9cbbc4400f8d
8: 0x7f73eb1eb99a - std::panicking::panic_handler::{{closure}}::h8aea969f9752b935
9: 0x7f73eb1e5829 - std::sys::backtrace::__rust_end_short_backtrace::hdfb91b09c7ddecee
10: 0x7f73eb1c621d - __rustc[e7db3b1e3415d0cf]::rust_begin_unwind
11: 0x7f73e8178000 - core::panicking::panic_fmt::he1d8389956e4a47c
12: 0x7f73e8c528db - core::option::expect_failed::hde891a1dd012bc04
13: 0x7f73ead772c7 - <rustc_resolve[8d0e4f7d0c721c63]::Resolver>::disambiguate_macro_rules_vs_modularized
14: 0x7f73ebeea68b - <rustc_resolve[8d0e4f7d0c721c63]::Resolver>::resolve_ident_in_scope_set
15: 0x7f73ebeecc4c - <rustc_resolve[8d0e4f7d0c721c63]::Resolver>::resolve_crate::{closure#0}
16: 0x7f73ebeeb04b - <rustc_resolve[8d0e4f7d0c721c63]::Resolver>::resolve_crate
17: 0x7f73ec2e2ad5 - rustc_interface[69c6c6fb57a49f0e]::passes::configure_and_expand
18: 0x7f73ec957a55 - rustc_interface[69c6c6fb57a49f0e]::passes::resolver_for_lowering_raw
19: 0x7f73ec9577cd - rustc_query_impl[934bb46c38eb598f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[934bb46c38eb598f]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2ef50a8f98010f6a]::query::erase::Erased<[u8; 16usize]>>
20: 0x7f73ec9577a7 - <rustc_query_impl[934bb46c38eb598f]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[9c1f01dbaa90fd55]::ops::function::FnOnce<(rustc_middle[2ef50a8f98010f6a]::ty::context::TyCtxt, ())>>::call_once
21: 0x7f73ec8e48df - rustc_query_system[b483a988b60022bb]::query::plumbing::try_execute_query::<rustc_query_impl[934bb46c38eb598f]::DynamicConfig<rustc_query_system[b483a988b60022bb]::query::caches::SingleCache<rustc_middle[2ef50a8f98010f6a]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[934bb46c38eb598f]::plumbing::QueryCtxt, false>
22: 0x7f73ec8e443c - rustc_query_impl[934bb46c38eb598f]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
23: 0x7f73ecab9331 - <rustc_interface[69c6c6fb57a49f0e]::passes::create_and_enter_global_ctxt<core[9c1f01dbaa90fd55]::option::Option<rustc_interface[69c6c6fb57a49f0e]::queries::Linker>, rustc_driver_impl[73351eb39aec07fc]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[9c1f01dbaa90fd55]::ops::function::FnOnce<(&rustc_session[adfd771fcb344a00]::session::Session, rustc_middle[2ef50a8f98010f6a]::ty::context::CurrentGcx, alloc[9e3a1fe8dcc7efa7]::sync::Arc<rustc_data_structures[5cfd80b0ac44ebb6]::jobserver::Proxy>, &std[b944056449750609]::sync::once_lock::OnceLock<rustc_middle[2ef50a8f98010f6a]::ty::context::GlobalCtxt>, &rustc_data_structures[5cfd80b0ac44ebb6]::sync::worker_local::WorkerLocal<rustc_middle[2ef50a8f98010f6a]::arena::Arena>, &rustc_data_structures[5cfd80b0ac44ebb6]::sync::worker_local::WorkerLocal<rustc_hir[c87451248e39a5fc]::Arena>, rustc_driver_impl[73351eb39aec07fc]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
24: 0x7f73ec9a9b62 - rustc_interface[69c6c6fb57a49f0e]::interface::run_compiler::<(), rustc_driver_impl[73351eb39aec07fc]::run_compiler::{closure#0}>::{closure#1}
25: 0x7f73ec8fd13a - std[b944056449750609]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[69c6c6fb57a49f0e]::util::run_in_thread_with_globals<rustc_interface[69c6c6fb57a49f0e]::util::run_in_thread_pool_with_globals<rustc_interface[69c6c6fb57a49f0e]::interface::run_compiler<(), rustc_driver_impl[73351eb39aec07fc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
26: 0x7f73ec8fce1e - <<std[b944056449750609]::thread::Builder>::spawn_unchecked_<rustc_interface[69c6c6fb57a49f0e]::util::run_in_thread_with_globals<rustc_interface[69c6c6fb57a49f0e]::util::run_in_thread_pool_with_globals<rustc_interface[69c6c6fb57a49f0e]::interface::run_compiler<(), rustc_driver_impl[73351eb39aec07fc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[9c1f01dbaa90fd55]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
27: 0x7f73ec9032ef - std::sys::thread::unix::Thread::new::thread_start::hbdf0c690ab65ca60
28: 0x7f73e62969cb - <unknown>
29: 0x7f73e631aa0c - <unknown>
30: 0x0 - <unknown>
error: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: please make sure that you have updated to the latest nightly
note: rustc 1.92.0-nightly (96fe3c31c 2025-10-22) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0428`.
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
matthiaskrgr commentedon Oct 22, 2025
Regression in nightly-2025-10-09
this happens since #147412 cc @yaahc
yaahc commentedon Oct 27, 2025
Relevant state at time of crash
rustc log
So it's the macro_export's path-based scope binding in the crate root that is causing the ambiguity, that's surprising. I wonder why the 2.0 macro is necessary in the minimized example. I see it's spans showing up in the associated ambiguity error in the NameBindingData for
modularized, but as far as I understand, the impact of that should be that rustc will emit an error when a name is resolved through that name binding data when it reports the usage of the import. To influence this error it would need to impactresolve_ident_in_scope_setwhich is where this error is coming from. The only way I could see it coming into play there is if it had some sort of impact onvisit_scopeswhere it changed which resolution was theinnermost_resbut both resolutions in this case are separate resolutions, so innermost must be themacro_rulesresolution.yaahc commentedon Oct 27, 2025
I think I have a theory
my guess is that when we allocate a new ambiguity binding we end up not breaking the mapping between the primary_binding and the parent module via binding_parent_module. We end up looking the parent module up via the ambiguity binding instead of the primary binding and find that the key doesn't have an entry.
So if I'm right we could fix this by making an additional entry in the list for the new ambiguity binding whenever we make one or we could try looking up the parent module through the primary binding in
disambiguate_...when we see that the name binding we're using is an ambiguity binding.cc @petrochenkov lmk if that sounds right. I'll test out the theory tomorrow.
reddevilmidzy commentedon Feb 1, 2026
fixed: #149681
Rollup merge of rust-lang#152732 - Kivooeo:add-regression-test-1, r=T…
Rollup merge of rust-lang#152732 - Kivooeo:add-regression-test-1, r=T…
Rollup merge of rust-lang#152732 - Kivooeo:add-regression-test-1, r=T…
Rollup merge of rust-lang#152732 - Kivooeo:add-regression-test-1, r=T…
Unrolled build for #152732
Rollup merge of #152732 - Kivooeo:add-regression-test-1, r=TaKO8Ki
Rollup merge of #152732 - Kivooeo:add-regression-test-1, r=TaKO8Ki
Rollup merge of #152732 - Kivooeo:add-regression-test-1, r=TaKO8Ki
Rollup merge of #152732 - Kivooeo:add-regression-test-1, r=TaKO8Ki