Skip to content

ICE import.imported_module.get().is_none() #147208

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024
use foo::bar::E::*;

use foo::bar::test_use::io as std_io;

fn main() {
    Foo(());

    {
        use ::std::io as std_io;
        use std_io::stdout;
    }
}

original:

//@ run-pass
//@ edition:2018

#![allow(unused_imports)]
#![allow("{} {} {}", crate::A, crate::foo::B, C)]

// Test that ambiguity errors are not emitted between `self::test` and
// `::test`, assuming the latter (crate) is not in `extern_prelude`.
mod test {
    pub struct Foo(pub ());
}
use foo::bar::E::*;

// Test that qualified paths can refer to both the external crate and local item.
mod std {
    pub struct Foo(pub ());
}
use foo::bar::test_use::io as std_io;
use self::std::io as local_io;

fn main() {
    Foo(());
    let _ = std_io::stdout(10);
    local_io(());

    {
        // Test that having `std_io` in a module scope and a non-module
        // scope is allowed, when both resolve to the same definition.
        use ::std::io as std_io;
        use std_io::stdout;
        let _ = stdout();
    }
}

Version information

rustc 1.92.0-nightly (42d009c0a 2025-09-30)
binary: rustc
commit-hash: 42d009c0a9be0f7020a03f85dd47faa00d6d7bdf
commit-date: 2025-09-30
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

Possibly related line of code:

suggestion,
module,
segment_name,
..
} => {
if no_ambiguity {
assert!(import.imported_module.get().is_none());
let module = if let Some(ModuleOrUniformRoot::Module(m)) = module {
m.opt_def_id()
} else {
None
};
let err = match self

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2024

Program output

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `foo`
 --> /tmp/icemaker_global_tempdir.oS6KtWNh40fo/rustc_testrunner_tmpdir_reporting.llLZgH6Tvfvh/mvce.rs:1:5
  |
1 | use foo::bar::E::*;
  |     ^^^ use of unresolved module or unlinked crate `foo`
  |
  = help: you might be missing a crate named `foo`


thread 'rustc' (660268) panicked at compiler/rustc_resolve/src/imports.rs:1028:21:
assertion failed: import.imported_module.get().is_none()
stack backtrace:
   0:     0x7fe63cb8b813 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h5942d615ecf52cff
   1:     0x7fe63d2020d8 - core::fmt::write::hfcfdaecc2b4bacd9
   2:     0x7fe63cb40341 - std::io::Write::write_fmt::hbebbf336882041da
   3:     0x7fe63cb517b2 - std::sys::backtrace::BacktraceLock::print::hfca1ae89b1026fe5
   4:     0x7fe63cb57649 - std::panicking::default_hook::{{closure}}::h8bf82644dd51dbf3
   5:     0x7fe63cb57173 - std::panicking::default_hook::h2a2bf2a808f9b820
   6:     0x7fe63bb81cb7 - std[a0926f9e2e67f956]::panicking::update_hook::<alloc[6166b3f20b6024c2]::boxed::Box<rustc_driver_impl[415322915ceb5efe]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7fe63cb57a6f - std::panicking::panic_with_hook::h6a8c06d504274cb1
   8:     0x7fe63cb577f6 - std::panicking::panic_handler::{{closure}}::h81e6b6ef82d36870
   9:     0x7fe63cb518f9 - std::sys::backtrace::__rust_end_short_backtrace::h864f48f212d4152d
  10:     0x7fe63cb3241d - __rustc[c95d600b28499d26]::rust_begin_unwind
  11:     0x7fe639c1f800 - core::panicking::panic_fmt::h83d6099a172f685a
  12:     0x7fe639649f7c - core::panicking::panic::hbd8b77f5ff3f73ce
  13:     0x7fe63d85f098 - <rustc_resolve[e24fe1197a042647]::Resolver>::resolve_crate::{closure#0}
  14:     0x7fe63d85651d - <rustc_resolve[e24fe1197a042647]::Resolver>::resolve_crate
  15:     0x7fe63dc96315 - rustc_interface[5a04a2cecc4e3deb]::passes::configure_and_expand
  16:     0x7fe63e388f2d - rustc_interface[5a04a2cecc4e3deb]::passes::resolver_for_lowering_raw
  17:     0x7fe63e388c8d - rustc_query_impl[f679df848a823e0a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f679df848a823e0a]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[30ae8ca99d8abeb9]::query::erase::Erased<[u8; 16usize]>>
  18:     0x7fe63e388c67 - <rustc_query_impl[f679df848a823e0a]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[d56fea445d2f84db]::ops::function::FnOnce<(rustc_middle[30ae8ca99d8abeb9]::ty::context::TyCtxt, ())>>::call_once
  19:     0x7fe63e27839f - rustc_query_system[e42291865ee56b50]::query::plumbing::try_execute_query::<rustc_query_impl[f679df848a823e0a]::DynamicConfig<rustc_query_system[e42291865ee56b50]::query::caches::SingleCache<rustc_middle[30ae8ca99d8abeb9]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[f679df848a823e0a]::plumbing::QueryCtxt, false>
  20:     0x7fe63e277efc - rustc_query_impl[f679df848a823e0a]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7fe63e40eafa - rustc_interface[5a04a2cecc4e3deb]::passes::create_and_enter_global_ctxt::<core[d56fea445d2f84db]::option::Option<rustc_interface[5a04a2cecc4e3deb]::queries::Linker>, rustc_driver_impl[415322915ceb5efe]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  22:     0x7fe63e3ffe4d - rustc_interface[5a04a2cecc4e3deb]::interface::run_compiler::<(), rustc_driver_impl[415322915ceb5efe]::run_compiler::{closure#0}>::{closure#1}
  23:     0x7fe63e321407 - std[a0926f9e2e67f956]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5a04a2cecc4e3deb]::util::run_in_thread_with_globals<rustc_interface[5a04a2cecc4e3deb]::util::run_in_thread_pool_with_globals<rustc_interface[5a04a2cecc4e3deb]::interface::run_compiler<(), rustc_driver_impl[415322915ceb5efe]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  24:     0x7fe63e3210e8 - <<std[a0926f9e2e67f956]::thread::Builder>::spawn_unchecked_<rustc_interface[5a04a2cecc4e3deb]::util::run_in_thread_with_globals<rustc_interface[5a04a2cecc4e3deb]::util::run_in_thread_pool_with_globals<rustc_interface[5a04a2cecc4e3deb]::interface::run_compiler<(), rustc_driver_impl[415322915ceb5efe]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[d56fea445d2f84db]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7fe63e3270ef - std::sys::thread::unix::Thread::new::thread_start::h8236924125f022df
  26:     0x7fe637c969cb - <unknown>
  27:     0x7fe637d1aa0c - <unknown>
  28:                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 (42d009c0a 2025-09-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

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 E0433`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-lowLow priorityS-has-bisectionStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions