Skip to content

ICE: Error in drop elaboration not found by dropck. #137287

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

Closed
matthiaskrgr opened this issue Feb 19, 2025 · 1 comment · Fixed by #139379
Closed

ICE: Error in drop elaboration not found by dropck. #137287

matthiaskrgr opened this issue Feb 19, 2025 · 1 comment · Fixed by #139379
Assignees
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

mod defining_scope {
    use super::*;
    pub type Alias<T> = impl Sized;

    pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
        x
    }
}

struct Container<T: Trait<U>, U> {
    x: <T as Trait<U>>::Assoc,
}

trait Trait<T> {
    type Assoc;
}

impl<T> Trait<T> for T {
    type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {
    type Assoc = usize;
}

fn main() {
    let x: Box<u32> = defining_scope::cast::<()>(Container { x: 0 }).x;
}

original:

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// A regression test for #105787
#![feature(type_alias_impl_trait)]
mod defining_scope {
    use super::*;
    pub type Alias<T> = impl Sized;

    pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
        //[next]~^ ERROR type annotations needed
        x
    }
}

struct Container<T: Trait<U>, U> {
    x: <T as Trait<U>>::Assoc,
}

trait Trait<T> {
    type Assoc;
}

impl<T> Trait<T> for T {
    type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {

    type Assoc = usize;
}

fn main() {
    let x: Box<u32> = defining_scope::cast::<()>(Container { x: 0 }).x;
    println!("{}", *x);
}

Version information

rustc 1.87.0-nightly (ed49386d3 2025-02-19)
binary: rustc
commit-hash: ed49386d3aa3a445a9889707fd405df01723eced
commit-date: 2025-02-19
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

Ok(t) => t,
Err(_) => Ty::new_error(
self.tcx(),
self.elaborator
.body()
.tainted_by_errors
.expect("Error in drop elaboration not found by dropck."),
),
};
(tcx.mk_place_field(base_place, field, field_ty), subpath)
})
.collect()

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0658]: `impl Trait` in type aliases is unstable
 --> /tmp/icemaker_global_tempdir.xxzOQICcxqct/rustc_testrunner_tmpdir_reporting.zRTjmeRI0T4S/mvce.rs:3:25
  |
3 |     pub type Alias<T> = impl Sized;
  |                         ^^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
  = note: this compiler was built on 2025-02-19; consider upgrading it if it is out of date

error[E0119]: conflicting implementations of trait `Trait<_>`
  --> /tmp/icemaker_global_tempdir.xxzOQICcxqct/rustc_testrunner_tmpdir_reporting.zRTjmeRI0T4S/mvce.rs:21:1
   |
18 | impl<T> Trait<T> for T {
   | ---------------------- first implementation here
...
21 | impl<T> Trait<T> for defining_scope::Alias<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

warning: unused variable: `x`
  --> /tmp/icemaker_global_tempdir.xxzOQICcxqct/rustc_testrunner_tmpdir_reporting.zRTjmeRI0T4S/mvce.rs:26:9
   |
26 |     let x: Box<u32> = defining_scope::cast::<()>(Container { x: 0 }).x;
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default


thread 'rustc' panicked at compiler/rustc_mir_transform/src/elaborate_drop.rs:281:30:
Error in drop elaboration not found by dropck.
stack backtrace:
   0:     0x78aff5d9a8e4 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h8474fc63c522d8ef
   1:     0x78aff661a2ac - core::fmt::write::h807495cdc673c9ad
   2:     0x78aff758d291 - std::io::Write::write_fmt::ha095d9f81ce0ab0f
   3:     0x78aff5d9a742 - std::sys::backtrace::BacktraceLock::print::h6697e7571ddb1a7a
   4:     0x78aff5d9cf4e - std::panicking::default_hook::{{closure}}::h809b6cc791b58376
   5:     0x78aff5d9cb24 - std::panicking::default_hook::h552e31dd2ff71c94
   6:     0x78aff4ee8d17 - std[751aac3a1d4a21ec]::panicking::update_hook::<alloc[e70108a9cb6abf43]::boxed::Box<rustc_driver_impl[2db46e11a3788224]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x78aff5d9d7c3 - std::panicking::rust_panic_with_hook::h31b9a9fc06967d1a
   8:     0x78aff5d9d4ba - std::panicking::begin_panic_handler::{{closure}}::he085f2b5958febbd
   9:     0x78aff5d9ada9 - std::sys::backtrace::__rust_end_short_backtrace::h3acec7353f287c7e
  10:     0x78aff5d9d17d - rust_begin_unwind
  11:     0x78aff2a47050 - core::panicking::panic_fmt::h088f650de8922fae
  12:     0x78aff3d2b39b - core::option::expect_failed::hf1aea988650b4371
  13:     0x78aff7128eb8 - <rustc_mir_transform[5f9d0e5befb1dd62]::elaborate_drop::DropCtxt<rustc_mir_transform[5f9d0e5befb1dd62]::elaborate_drops::ElaborateDropsCtxt>>::elaborate_drop
  14:     0x78aff2ffbea8 - <rustc_mir_transform[5f9d0e5befb1dd62]::elaborate_drops::ElaborateDrops as rustc_mir_transform[5f9d0e5befb1dd62]::pass_manager::MirPass>::run_pass
  15:     0x78aff660979b - rustc_mir_transform[5f9d0e5befb1dd62]::run_analysis_to_runtime_passes
  16:     0x78aff69cf2d9 - rustc_mir_transform[5f9d0e5befb1dd62]::mir_drops_elaborated_and_const_checked
  17:     0x78aff69cef1f - rustc_query_impl[db8619f7f72bce84]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db8619f7f72bce84]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cad254c74eefe1b7]::query::erase::Erased<[u8; 8usize]>>
  18:     0x78aff69c42cc - rustc_query_system[61afea02fdc7dc5c]::query::plumbing::try_execute_query::<rustc_query_impl[db8619f7f72bce84]::DynamicConfig<rustc_data_structures[7f723801f239d808]::vec_cache::VecCache<rustc_span[3242d24a3aa68a91]::def_id::LocalDefId, rustc_middle[cad254c74eefe1b7]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[61afea02fdc7dc5c]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[db8619f7f72bce84]::plumbing::QueryCtxt, false>
  19:     0x78aff69c3d0c - rustc_query_impl[db8619f7f72bce84]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  20:     0x78aff69cc3e2 - rustc_interface[8d7befe99ce7adde]::passes::run_required_analyses
  21:     0x78aff758923a - rustc_interface[8d7befe99ce7adde]::passes::analysis
  22:     0x78aff7589219 - rustc_query_impl[db8619f7f72bce84]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[db8619f7f72bce84]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cad254c74eefe1b7]::query::erase::Erased<[u8; 0usize]>>
  23:     0x78aff7616883 - rustc_query_system[61afea02fdc7dc5c]::query::plumbing::try_execute_query::<rustc_query_impl[db8619f7f72bce84]::DynamicConfig<rustc_query_system[61afea02fdc7dc5c]::query::caches::SingleCache<rustc_middle[cad254c74eefe1b7]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[db8619f7f72bce84]::plumbing::QueryCtxt, false>
  24:     0x78aff7616553 - rustc_query_impl[db8619f7f72bce84]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  25:     0x78aff7648f3c - rustc_interface[8d7befe99ce7adde]::passes::create_and_enter_global_ctxt::<core[5038f2ec8886dbab]::option::Option<rustc_interface[8d7befe99ce7adde]::queries::Linker>, rustc_driver_impl[2db46e11a3788224]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  26:     0x78aff763c8ab - rustc_interface[8d7befe99ce7adde]::interface::run_compiler::<(), rustc_driver_impl[2db46e11a3788224]::run_compiler::{closure#0}>::{closure#1}
  27:     0x78aff7502dc8 - std[751aac3a1d4a21ec]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8d7befe99ce7adde]::util::run_in_thread_with_globals<rustc_interface[8d7befe99ce7adde]::util::run_in_thread_pool_with_globals<rustc_interface[8d7befe99ce7adde]::interface::run_compiler<(), rustc_driver_impl[2db46e11a3788224]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  28:     0x78aff75031f4 - <<std[751aac3a1d4a21ec]::thread::Builder>::spawn_unchecked_<rustc_interface[8d7befe99ce7adde]::util::run_in_thread_with_globals<rustc_interface[8d7befe99ce7adde]::util::run_in_thread_pool_with_globals<rustc_interface[8d7befe99ce7adde]::interface::run_compiler<(), rustc_driver_impl[2db46e11a3788224]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5038f2ec8886dbab]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x78aff7503baf - std::sys::pal::unix::thread::Thread::new::thread_start::ha52e702df20ec6b5
  30:     0x78aff16a370a - <unknown>
  31:     0x78aff1727aac - <unknown>
  32:                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.87.0-nightly (ed49386d3 2025-02-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors; 1 warning emitted

Some errors have detailed explanations: E0119, E0658.
For more information about an error, try `rustc --explain E0119`.

@rustbot label +F-type_alias_impl_trait

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. 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. labels Feb 19, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Feb 19, 2025
@compiler-errors
Copy link
Member

cc @matthewjasper

@Noratrieb Noratrieb added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 1, 2025
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Mar 9, 2025
@matthewjasper matthewjasper self-assigned this Apr 3, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 7, 2025
…ion, r=compiler-errors

Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes rust-lang#137287
Closes rust-lang#135668

r? compiler-errors
ChrisDenton added a commit to ChrisDenton/rust that referenced this issue Apr 13, 2025
…ion, r=compiler-errors

Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes rust-lang#137287
Closes rust-lang#135668

r? compiler-errors
ChrisDenton added a commit to ChrisDenton/rust that referenced this issue Apr 13, 2025
…ion, r=compiler-errors

Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes rust-lang#137287
Closes rust-lang#135668

r? compiler-errors
jhpratt added a commit to jhpratt/rust that referenced this issue Apr 13, 2025
…ion, r=compiler-errors

Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes rust-lang#137287
Closes rust-lang#135668

r? compiler-errors
@bors bors closed this as completed in 346d33a Apr 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 14, 2025
Rollup merge of rust-lang#139379 - matthewjasper:drop-elab-normalization, r=compiler-errors

Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes rust-lang#137287
Closes rust-lang#135668

r? compiler-errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants