rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.57k stars 12.74k forks source link

ICE: broken mir: Unsize coercion, but `&Foo<[impl Sized; 2]>` isn't coercible to `&Foo<[i32]>` #130921

Closed matthiaskrgr closed 4 weeks ago

matthiaskrgr commented 1 month ago

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 - ::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::>::{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 - ::fail:: 13: 0x779f8fef80b9 - ::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::> 17: 0x779f939af1fa - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::> 21: 0x779f93f9ab18 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::> 25: 0x779f939f9e21 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::> 28: 0x779f939af1fa - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::>> 31: 0x779f943fa8cd - rustc_hir_analysis[b7559335049578b7]::collect::type_of::type_of_opaque 32: 0x779f943fa725 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::> 33: 0x779f9362f8f8 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::>> 36: 0x779f9113aa05 - rustc_hir_analysis[b7559335049578b7]::collect::type_of::type_of 37: 0x779f93630bf0 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::> 38: 0x779f9362f8f8 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::>> 41: 0x779f91124fce - rustc_hir_analysis[b7559335049578b7]::check::wfcheck::check_well_formed 42: 0x779f93df8827 - rustc_query_impl[93eab92cd2f605dc]::plumbing::__rust_begin_short_backtrace::> 43: 0x779f93df8ab4 - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::> 47: 0x779f943307bb - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::> 53: 0x779f944797ee - rustc_query_system[5291c0f4a5531c79]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[78eb03903cc8530b]::run_compiler::{closure#0}>::{closure#1} 56: 0x779f943e3b90 - std[50bb54db316076bd]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - 60: 0x779f95ae649c - 61: 0x0 - 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 commented 1 month ago

another one from https://github.com/rust-lang/rust/issues/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
    })
}
``
matthiaskrgr commented 1 month ago

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!()
}