Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE:assertion failed: import.imported_module.get().is_none() #125013

Closed
matthiaskrgr opened this issue May 11, 2024 · 2 comments · Fixed by #124840 or #126065
Closed

ICE:assertion failed: import.imported_module.get().is_none() #125013

matthiaskrgr opened this issue May 11, 2024 · 2 comments · Fixed by #124840 or #126065
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

This crashes with every edition except 2015 🤔

snippet:

use io::{self as std};
use std::ops::Deref::{self as io};

Version information

rustc 1.80.0-nightly (35c5e67c6 2024-05-11)
binary: rustc
commit-hash: 35c5e67c69cbde49b47fe537e296803b6a25b456
commit-date: 2024-05-11
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

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

Program output

thread 'rustc' panicked at compiler/rustc_resolve/src/imports.rs:926:21:
assertion failed: import.imported_module.get().is_none()
stack backtrace:
   0:     0x7d29815dfc45 - std::backtrace_rs::backtrace::libunwind::trace::hba6094fc6b596e2e
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7d29815dfc45 - std::backtrace_rs::backtrace::trace_unsynchronized::h3b202ba307e40438
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7d29815dfc45 - std::sys_common::backtrace::_print_fmt::h86408adb99a13f5c
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7d29815dfc45 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hbd6f80f0e5997f54
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7d298162ee0b - core::fmt::rt::Argument::fmt::hc498e90c1989f8fc
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/core/src/fmt/rt.rs:165:63
   5:     0x7d298162ee0b - core::fmt::write::ha011919bce0aa4f2
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/core/src/fmt/mod.rs:1157:21
   6:     0x7d29815d4a0f - std::io::Write::write_fmt::hc5d7335558d7c2f5
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/io/mod.rs:1835:15
   7:     0x7d29815dfa1e - std::sys_common::backtrace::_print::hb5e8494623fbcf06
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7d29815dfa1e - std::sys_common::backtrace::print::h944fe8485fd95854
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7d29815e2389 - std::panicking::default_hook::{{closure}}::hd7a32cc14f6b3aad
  10:     0x7d29815e20cd - std::panicking::default_hook::hce26d1b7cfeb1dbb
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/panicking.rs:298:9
  11:     0x7d297ded14af - std[51ea32a909324831]::panicking::update_hook::<alloc[77c3f3c3161b06c0]::boxed::Box<rustc_driver_impl[aad4619bae6cbfbd]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7d29815e2a86 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3bc218da95aac6f0
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/alloc/src/boxed.rs:2036:9
  13:     0x7d29815e2a86 - std::panicking::rust_panic_with_hook::h104a5f4852f71fae
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/panicking.rs:799:13
  14:     0x7d29815e27fb - std::panicking::begin_panic_handler::{{closure}}::hbe2cffd5894aac21
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/panicking.rs:656:13
  15:     0x7d29815e0109 - std::sys_common::backtrace::__rust_end_short_backtrace::h124d376bffe44b06
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7d29815e2567 - rust_begin_unwind
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/panicking.rs:652:5
  17:     0x7d298162b3d3 - core::panicking::panic_fmt::ha6a495494fa26de2
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/core/src/panicking.rs:72:14
  18:     0x7d298162b47c - core::panicking::panic::h43564003bddcc9c0
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/core/src/panicking.rs:146:5
  19:     0x7d2980257274 - <rustc_resolve[287ffcdb65d0abd4]::Resolver>::resolve_crate::{closure#0}
  20:     0x7d2980248ac0 - <rustc_resolve[287ffcdb65d0abd4]::Resolver>::resolve_crate
  21:     0x7d297f7be7c1 - rustc_interface[1af8fbac95f387b0]::passes::resolver_for_lowering_raw
  22:     0x7d297f7bda0d - rustc_query_impl[b785da3d31912d7f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b785da3d31912d7f]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1afb1a57a12263fe]::query::erase::Erased<[u8; 16usize]>>
  23:     0x7d297f7bd9ef - <rustc_query_impl[b785da3d31912d7f]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[7b5ea08294f46cd8]::ops::function::FnOnce<(rustc_middle[1afb1a57a12263fe]::ty::context::TyCtxt, ())>>::call_once
  24:     0x7d297ffa34c5 - rustc_query_system[42f095e9d6ad5ed8]::query::plumbing::try_execute_query::<rustc_query_impl[b785da3d31912d7f]::DynamicConfig<rustc_query_system[42f095e9d6ad5ed8]::query::caches::SingleCache<rustc_middle[1afb1a57a12263fe]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[b785da3d31912d7f]::plumbing::QueryCtxt, false>
  25:     0x7d297ffa3059 - rustc_query_impl[b785da3d31912d7f]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7d297fe3bffe - rustc_interface[1af8fbac95f387b0]::interface::run_compiler::<core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>, rustc_driver_impl[aad4619bae6cbfbd]::run_compiler::{closure#0}>::{closure#1}
  27:     0x7d297fe27d09 - std[51ea32a909324831]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1af8fbac95f387b0]::util::run_in_thread_with_globals<rustc_interface[1af8fbac95f387b0]::util::run_in_thread_pool_with_globals<rustc_interface[1af8fbac95f387b0]::interface::run_compiler<core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>, rustc_driver_impl[aad4619bae6cbfbd]::run_compiler::{closure#0}>::{closure#1}, core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>>::{closure#0}, core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>>
  28:     0x7d297fe27ab6 - <<std[51ea32a909324831]::thread::Builder>::spawn_unchecked_<rustc_interface[1af8fbac95f387b0]::util::run_in_thread_with_globals<rustc_interface[1af8fbac95f387b0]::util::run_in_thread_pool_with_globals<rustc_interface[1af8fbac95f387b0]::interface::run_compiler<core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>, rustc_driver_impl[aad4619bae6cbfbd]::run_compiler::{closure#0}>::{closure#1}, core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>>::{closure#0}, core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7b5ea08294f46cd8]::result::Result<(), rustc_span[f63607c00cb4b4d8]::ErrorGuaranteed>>::{closure#2} as core[7b5ea08294f46cd8]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7d29815ec8cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h47404fef54470e82
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/alloc/src/boxed.rs:2022:9
  30:     0x7d29815ec8cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h94736f8ab20acaae
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/alloc/src/boxed.rs:2022:9
  31:     0x7d29815ec8cb - std::sys::pal::unix::thread::Thread::new::thread_start::h3dd6ac2255354521
                               at /rustc/35c5e67c69cbde49b47fe537e296803b6a25b456/library/std/src/sys/pal/unix/thread.rs:108:17
  32:     0x7d298138b55a - <unknown>
  33:     0x7d2981408a3c - <unknown>
  34:                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.80.0-nightly (35c5e67c6 2024-05-11) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 11, 2024
@jieyouxu jieyouxu added A-resolve Area: Name resolution S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 11, 2024
@bvanjoi
Copy link
Contributor

bvanjoi commented May 12, 2024

Minimized:

mod a {
  pub mod b {
    pub mod c {
      pub trait D {} 
    }
  }
}

use a::*;

use e as b;
use b::c::D as e;

fn main() { }

bors added a commit to rust-lang-ci/rust that referenced this issue May 29, 2024
resolve: mark it undetermined if single import is not has any bindings

- Fixes rust-lang#124490
- Fixes rust-lang#125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root::a::b::c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? `@petrochenkov`
fmease added a commit to fmease/rust that referenced this issue Jun 4, 2024
resolve: mark it undetermined if single import is not has any bindings

- Fixes rust-lang#124490
- Fixes rust-lang#125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root::a::b::c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? `@petrochenkov`
@bors bors closed this as completed in 69a8c13 Jun 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2024
Rollup merge of rust-lang#124840 - bvanjoi:fix-124490, r=petrochenkov

resolve: mark it undetermined if single import is not has any bindings

- Fixes rust-lang#124490
- Fixes rust-lang#125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root::a::b::c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? ``@petrochenkov``
@matthiaskrgr
Copy link
Member Author

😅 while the "minimized" example is fixed, my original finding still crashes 🙃 cc @bvanjoi in case you would like to have a look again

@matthiaskrgr matthiaskrgr reopened this Jun 6, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jun 7, 2024
mark binding undetermined if target name exist and not obtained

- Fixes rust-lang#124490
- Fixes rust-lang#125013

Following up on rust-lang#124840, I think handling only `target_bindings` is sufficient.

r? `@petrochenkov`
@bors bors closed this as completed in 4bca296 Jun 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 8, 2024
Rollup merge of rust-lang#126065 - bvanjoi:fix-124490, r=petrochenkov

mark binding undetermined if target name exist and not obtained

- Fixes rust-lang#124490
- Fixes rust-lang#125013

Following up on rust-lang#124840, I think handling only `target_bindings` is sufficient.

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants