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: broken mir: Unsize coercion, but &Foo<[impl Sized; 2]> isn't coercible to &Foo<[i32]> #130921

Closed
matthiaskrgr opened this issue Sep 27, 2024 · 2 comments · Fixed by #130989
Closed
Assignees
Labels
C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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):

struct Foo<T: ?Sized>(T);

fn hello() -> Foo<[impl Sized; 2]> {
    if false {
        let x = hello();
        let _: &Foo<[i32]> = &x;
    }
    todo!()
}

fn main() {}

original:

//! Test that we allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.

//@check-pass

struct Foo<T: ?Sized>(T);

fn hello() -> Foo<[impl Sized; 2]> {
    if false {
        let x = hello();
        let _: &Foo<[i32]> = &x;
    }
    todo!()
}

fn main() {}

Version information

rustc 1.83.0-nightly (58420a065 2024-09-26)
binary: rustc
commit-hash: 58420a065b68ecb3eec03b942740c761cdadd5c4
commit-date: 2024-09-26
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zvalidate-mir

Program output

thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:95:25:
broken MIR in Item(DefId(0:7 ~ mvce[a0e5]::hello)) (after pass CheckPackedRef) at bb3[6]:
Unsize coercion, but `&Foo<[impl Sized; 2]>` isn't coercible to `&Foo<[i32]>`
stack backtrace:
   0:     0x779f92ef932a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc01b1e3b789021f1
   1:     0x779f936037e6 - core::fmt::write::h38a5961bdd5b3dc6
   2:     0x779f947b9351 - std::io::Write::write_fmt::h75845be5c66e3907
   3:     0x779f92ef9182 - std::sys::backtrace::BacktraceLock::print::h21efe0eb9e7b049a
   4:     0x779f92efb6a1 - std::panicking::default_hook::{{closure}}::h6c21fed0cb7e9367
   5:     0x779f92efb4d4 - std::panicking::default_hook::h9e2e0cbe276a53ae
   6:     0x779f91fc747f - std[50bb54db316076bd]::panicking::update_hook::<alloc[340315532d8f25b]::boxed::Box<rustc_driver_impl[78eb03903cc8530b]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x779f92efbdb8 - std::panicking::rust_panic_with_hook::hfbcff0eadb238eff
   8:     0x779f92efbb8a - std::panicking::begin_panic_handler::{{closure}}::hb7eba6f77080c2fe
   9:     0x779f92ef97d9 - std::sys::backtrace::__rust_end_short_backtrace::h84faa42f1eba9998
  10:     0x779f92efb84c - rust_begin_unwind
  11:     0x779f9083ad90 - core::panicking::panic_fmt::h7aa430c333e0611a
  12:     0x779f8fef9ca3 - <rustc_mir_transform[4760ffa5a52f429a]::validate::CfgChecker>::fail::<alloc[340315532d8f25b]::string::String>
  13:     0x779f8fef80b9 - <rustc_mir_transform[4760ffa5a52f429a]::validate::Validator as rustc_mir_transform[4760ffa5a52f429a]::pass_manager::MirPass>::run_pass
  14:     0x779f918e65d0 - rustc_mir_transform[4760ffa5a52f429a]::pass_manager::validate_body
  15:     0x779f936056ea - rustc_mir_transform[4760ffa5a52f429a]::mir_built
  16:     0x779f936052c9 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>
  17:     0x779f939af1fa - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::VecCache<rustc_span[7e302be0cc7ac1bb]::def_id::LocalDefId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  18:     0x779f939aed0d - rustc_query_impl[93eab92cd2f605dc]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  19:     0x779f93632add - rustc_mir_transform[4760ffa5a52f429a]::ffi_unwind_calls::has_ffi_unwind_calls
  20:     0x779f93632489 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::has_ffi_unwind_calls::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>
  21:     0x779f93f9ab18 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::VecCache<rustc_span[7e302be0cc7ac1bb]::def_id::LocalDefId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  22:     0x779f93f9a701 - rustc_query_impl[93eab92cd2f605dc]::query_impl::has_ffi_unwind_calls::get_query_non_incr::__rust_end_short_backtrace
  23:     0x779f90c8db5f - rustc_mir_transform[4760ffa5a52f429a]::mir_promoted
  24:     0x779f939f9b52 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 16usize]>>
  25:     0x779f939f9e21 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::VecCache<rustc_span[7e302be0cc7ac1bb]::def_id::LocalDefId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  26:     0x779f945fcd50 - rustc_query_impl[93eab92cd2f605dc]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  27:     0x779f945fce43 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>
  28:     0x779f939af1fa - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::VecCache<rustc_span[7e302be0cc7ac1bb]::def_id::LocalDefId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  29:     0x779f939aec53 - rustc_query_impl[93eab92cd2f605dc]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  30:     0x779f93e6e4b3 - rustc_middle[8ef0708b6f5be0d2]::query::plumbing::query_get_at::<rustc_query_system[5291c0f4a5531c79]::query::caches::VecCache<rustc_span[7e302be0cc7ac1bb]::def_id::LocalDefId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>>
  31:     0x779f943fa8cd - rustc_hir_analysis[b7559335049578b7]::collect::type_of::type_of_opaque
  32:     0x779f943fa725 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>
  33:     0x779f9362f8f8 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::DefIdCache<rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  34:     0x779f9472b576 - rustc_query_impl[93eab92cd2f605dc]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  35:     0x779f93c76940 - rustc_middle[8ef0708b6f5be0d2]::query::plumbing::query_get_at::<rustc_query_system[5291c0f4a5531c79]::query::caches::DefIdCache<rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>>
  36:     0x779f9113aa05 - rustc_hir_analysis[b7559335049578b7]::collect::type_of::type_of
  37:     0x779f93630bf0 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>
  38:     0x779f9362f8f8 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::DefIdCache<rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  39:     0x779f9362f4b1 - rustc_query_impl[93eab92cd2f605dc]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  40:     0x779f93c76940 - rustc_middle[8ef0708b6f5be0d2]::query::plumbing::query_get_at::<rustc_query_system[5291c0f4a5531c79]::query::caches::DefIdCache<rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 8usize]>>>
  41:     0x779f91124fce - rustc_hir_analysis[b7559335049578b7]::check::wfcheck::check_well_formed
  42:     0x779f93df8827 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>
  43:     0x779f93df8ab4 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::VecCache<rustc_hir[618c7451a68f5b8e]::hir_id::OwnerId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  44:     0x779f93df8806 - rustc_query_impl[93eab92cd2f605dc]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  45:     0x779f93df95d7 - rustc_hir_analysis[b7559335049578b7]::check::wfcheck::check_mod_type_wf
  46:     0x779f93df9415 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>
  47:     0x779f943307bb - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::DefaultCache<rustc_span[7e302be0cc7ac1bb]::def_id::LocalModDefId, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  48:     0x779f9433056d - rustc_query_impl[93eab92cd2f605dc]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  49:     0x779f939ab755 - rustc_hir_analysis[b7559335049578b7]::check_crate
  50:     0x779f939a8405 - rustc_interface[a3c2c6b96d6e2376]::passes::run_required_analyses
  51:     0x779f941736de - rustc_interface[a3c2c6b96d6e2376]::passes::analysis
  52:     0x779f941736b1 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[93eab92cd2f605dc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>
  53:     0x779f944797ee - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::<rustc_query_impl[93eab92cd2f605dc]::DynamicConfig<rustc_query_system[5291c0f4a5531c79]::query::caches::SingleCache<rustc_middle[8ef0708b6f5be0d2]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[93eab92cd2f605dc]::plumbing::QueryCtxt, false>
  54:     0x779f944794cf - rustc_query_impl[93eab92cd2f605dc]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  55:     0x779f94314c5e - rustc_interface[a3c2c6b96d6e2376]::interface::run_compiler::<core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>, rustc_driver_impl[78eb03903cc8530b]::run_compiler::{closure#0}>::{closure#1}
  56:     0x779f943e3b90 - std[50bb54db316076bd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a3c2c6b96d6e2376]::util::run_in_thread_with_globals<rustc_interface[a3c2c6b96d6e2376]::util::run_in_thread_pool_with_globals<rustc_interface[a3c2c6b96d6e2376]::interface::run_compiler<core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>, rustc_driver_impl[78eb03903cc8530b]::run_compiler::{closure#0}>::{closure#1}, core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>>::{closure#0}, core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>>
  57:     0x779f943e41fa - <<std[50bb54db316076bd]::thread::Builder>::spawn_unchecked_<rustc_interface[a3c2c6b96d6e2376]::util::run_in_thread_with_globals<rustc_interface[a3c2c6b96d6e2376]::util::run_in_thread_pool_with_globals<rustc_interface[a3c2c6b96d6e2376]::interface::run_compiler<core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>, rustc_driver_impl[78eb03903cc8530b]::run_compiler::{closure#0}>::{closure#1}, core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>>::{closure#0}, core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a4850dfd24cc2e4a]::result::Result<(), rustc_span[7e302be0cc7ac1bb]::ErrorGuaranteed>>::{closure#1} as core[a4850dfd24cc2e4a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  58:     0x779f943e45eb - std::sys::pal::unix::thread::Thread::new::thread_start::h505722cf52959d28
  59:     0x779f95a6139d - <unknown>
  60:     0x779f95ae649c - <unknown>
  61:                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.83.0-nightly (58420a065 2024-09-26) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [mir_built] building MIR for `hello`
#1 [has_ffi_unwind_calls] checking if `hello` contains FFI-unwind calls
end of query stack

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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 Sep 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 27, 2024
@matthiaskrgr
Copy link
Member Author

another one from #116684

#![feature(type_alias_impl_trait)]

fn rpit() -> impl Sized {}

pub type Tait = impl Sized;

pub fn foo() -> Box<dyn std::future::Future<Output = Tait>> {
    Box::new(async {
        let _out: Tait = rpit();
        _out
    })
}
``

@compiler-errors compiler-errors self-assigned this Sep 27, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 27, 2024
@matthiaskrgr
Copy link
Member Author

another one that is a bit smaller than the original example:

fn hello() -> [impl Sized; 2] {
    if false {
        let x = hello();
        let _: &[i32] = &x;
    }
    todo!()
}

@matthiaskrgr matthiaskrgr added S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. and removed 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 Sep 29, 2024
@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 Oct 9, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 10, 2024
…stebank

Don't check unsize goal in MIR validation when opaques remain

Similarly to `mir_assign_valid_types`, let's just skip when there are opaques. Fixes rust-lang#130921.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Oct 10, 2024
…stebank

Don't check unsize goal in MIR validation when opaques remain

Similarly to `mir_assign_valid_types`, let's just skip when there are opaques. Fixes rust-lang#130921.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 16, 2024
…stebank

Don't check unsize goal in MIR validation when opaques remain

Similarly to `mir_assign_valid_types`, let's just skip when there are opaques. Fixes rust-lang#130921.
Urgau added a commit to Urgau/rust that referenced this issue Oct 16, 2024
…stebank

Don't check unsize goal in MIR validation when opaques remain

Similarly to `mir_assign_valid_types`, let's just skip when there are opaques. Fixes rust-lang#130921.
@bors bors closed this as completed in b6a085a Oct 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 16, 2024
Rollup merge of rust-lang#130989 - compiler-errors:unsize-opaque, r=estebank

Don't check unsize goal in MIR validation when opaques remain

Similarly to `mir_assign_valid_types`, let's just skip when there are opaques. Fixes rust-lang#130921.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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.

4 participants