Skip to content

resolve: no entry found for key #147958

Closed

Description

@matthiaskrgr

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 ambiguous

Version 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:

// 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[&macro_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`.

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Oct 22, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 22, 2025
  3. matthiaskrgr commented on Oct 22, 2025

    @matthiaskrgr
    MemberAuthor
    macro_rules! exported {
        () => {
            #[macro_export]
            macro_rules! exported {
                () => {};
            }
        };
    }
    use inner1::*;
    exported!();
    mod inner1 {
        pub macro exported() {}
    }

    Regression in nightly-2025-10-09
    this happens since #147412 cc @yaahc

  4. added
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    on Oct 22, 2025
  5. yaahc commented on Oct 27, 2025

    @yaahc
    Member

    Relevant state at time of crash

    rustc log

     rustc_resolve::disambiguate_macro_rules_vs_modularized
        macro_rules=NameBindingData {
            kind: Res(Def(Macro(MacroKinds(1)), DefId(0:3 ~ lib[4a59]::exported))),
            ambiguity: None,
            warn_ambiguity: false,
            expansion: expn0,
            span: ./src/lib.rs:1:1: 8:2 (#0),
            vis: Restricted(DefId(0:0 ~ lib[4a59]))
        },
        modularized=NameBindingData {
            kind: Import {
                binding: NameBindingData {
                    kind: Res(Def(Macro(MacroKinds(1)), DefId(0:7 ~ lib[4a59]::exported#1))),
                    ambiguity: None,
                    warn_ambiguity: false,
                    expansion: expn2,
                    span: ./src/lib.rs:4:9: 6:10 (#4),
                    vis: Public
                },
                import: ImportData {
                    kind: MacroExport,
                    root_id: NodeId(14),
                    use_span: ./src/lib.rs:4:9: 6:10 (#4),
                    use_span_with_attributes: ./src/lib.rs:4:9: 6:10 (#4),
                    has_attributes: false,
                    span: ./src/lib.rs:4:9: 6:10 (#4),
                    root_span: ./src/lib.rs:4:9: 6:10 (#4),
                    parent_scope: ParentScope {
                        module: Some(Def(Mod, DefId(0:0 ~ lib[4a59]))),
                        expansion: expn2,
                        macro_rules: Cell {
                            value: Binding(MacroRulesBinding {
                                binding: NameBindingData { kind: Res(Def(Macro(MacroKinds(1)), DefId(0:3 ~ lib[4a59]::exported))),
                                ambiguity: None,
                                warn_ambiguity: false,
                                expansion: expn0,
                                span: ./src/lib.rs:1:1: 8:2 (#0),
                                vis: Restricted(DefId(0:0 ~ lib[4a59])) },
                                parent_macro_rules_scope: Cell { value: Empty },
                                ident: exported#0 })
                            },
                        derives: []
                    },
                    module_path: [],
                    imported_module: CmCell(None),
                    vis: Public,
                    vis_span: ./src/lib.rs:4:9: 4:9 (#4)
                }
            },
            ambiguity: Some((NameBindingData {
                kind: Import {
                    binding: NameBindingData {
                        kind: Res(Def(Macro(MacroKinds(1)), DefId(0:6 ~ lib[4a59]::inner1::exported))),
                        ambiguity: None,
                        warn_ambiguity: false,
                        expansion: expn0,
                        span: ./src/lib.rs:12:5: 12:28 (#0),
                        vis:Public
                    },
                    import: ImportData {
                        kind: Glob {
                            max_vis: CmCell(Some(Restricted(DefId(0:0 ~ lib[4a59])))),
                            id: NodeId(10)
                        },
                        root_id: NodeId(10),
                        use_span: ./src/lib.rs:9:1: 9:15 (#0),
                        use_span_with_attributes: ./src/lib.rs:9:1: 9:15 (#0),
                        has_attributes: false,
                        span: ./src/lib.rs:9:5: 9:14 (#0),
                        root_span: ./src/lib.rs:9:5: 9:14 (#0),
                        parent_scope: ParentScope {
                            module: Some(Def(Mod, DefId(0:0 ~ lib[4a59]))),
                            expansion: expn0,
                            macro_rules: Cell {
                                value: Binding(MacroRulesBinding {
                                    binding: NameBindingData {
                                        kind: Res(Def(Macro(MacroKinds(1)), DefId(0:3 ~ lib[4a59]::exported))),
                                        ambiguity: None,
                                        warn_ambiguity: false,
                                        expansion: expn0,
                                        span: ./src/lib.rs:1:1: 8:2 (#0),
                                        vis: Restricted(DefId(0:0 ~ lib[4a59]))
                                    },
                                    parent_macro_rules_scope: Cell { value: Empty },
                                    ident: exported#0
                                })
                            },
                            derives: []
                        },
                        module_path: [Segment { ident: {{root}}#0, id: None, has_generic_args: false, has_lifetime_args: false, args_span: no-location (#0) }, Segment { ident: inner1#0, id: Some(NodeId(11)), has_generic_args: false, has_lifetime_args: false, args_span: no-location (#0) }],
                        imported_module: CmCell(Some(Module(Some(Def(Mod, DefId(0:5 ~ lib[4a59]::inner1)))))),
                        vis: Restricted(DefId(0:0 ~ lib[4a59])),
                        vis_span: ./src/lib.rs:9:1: 9:1 (#0)
                    }
                },
                ambiguity: None,
                warn_ambiguity: false,
                expansion: expn0,
                span: ./src/lib.rs:9:5: 9:14 (#0),
                vis: Restricted(DefId(0:0 ~ lib[4a59]))
            }, GlobVsExpanded)),
            warn_ambiguity: false,
            expansion: expn2,
            span: ./src/lib.rs:4:9:6:10 (#4),
            vis: Public
        }
    
    

    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 impact resolve_ident_in_scope_set which 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 on visit_scopes where it changed which resolution was the innermost_res but both resolutions in this case are separate resolutions, so innermost must be the macro_rules resolution.

  6. yaahc commented on Oct 27, 2025

    @yaahc
    Member

    I think I have a theory

        fn new_ambiguity_binding(
            &self,
            ambiguity_kind: AmbiguityKind,
            primary_binding: NameBinding<'ra>,
            secondary_binding: NameBinding<'ra>,
            warn_ambiguity: bool,
        ) -> NameBinding<'ra> {
            let ambiguity = Some((secondary_binding, ambiguity_kind));
            let data = NameBindingData { ambiguity, warn_ambiguity, ..*primary_binding };
            self.arenas.alloc_name_binding(data)
        }

    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.

  7. reddevilmidzy commented on Feb 1, 2026

    @reddevilmidzy
    Member

    fixed: #149681

  8. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 1, 2026
  9. added 3 commits that reference this issue on Feb 18, 2026
    bc61bd2
    53fbf71
    b162232
  10. added a commit that references this issue on Feb 18, 2026
    77e29b2
  11. added a commit that references this issue on Feb 18, 2026
    5a43551
  12. added a commit that references this issue on Feb 19, 2026
    b82cdd6
  13. added 2 commits that reference this issue on Mar 19, 2026
    7f3b89e
    7bf8dd6
  14. added a commit that references this issue on Mar 27, 2026
    21420f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.E-needs-testCall 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) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions