rust-lang / rust

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

ICE. `!base.layout().is_sized()` #127737

Open matthiaskrgr opened 1 month ago

matthiaskrgr commented 1 month ago

auto-reduced (treereduce-rust):

pub trait TestTrait {
    type MyType;
    fn func() -> Option<Self>
    where
        Self: Sized;
}

impl<T> dyn TestTrait<MyType = T>
where
    Self: Sized,
{
    pub fn other_func() -> Option<Self> {
        match Self::func() {
            Some(me) => Some(me),
            None => None,
        }
    }
}

original:

//@ compile-flags: --crate-type=lib -Zmir-opt-level=2
//@ build-pass
// ^-- Must be build-pass, because check-pass will not run const prop.

pub trait TestTrait {
    type MyType;
    fn func() -> Option<Self>
    where
        Self: Sized;
}

impl<T> dyn TestTrait<MyType = T>
where
    Self: Sized,
{
    pub fn other_func() -> Option<Self> {
        match Self::func() {
            Some(me) => Some(me),
            None => None,
        }
    }
}

Version information

rustc 1.81.0-nightly (f8e4ac076 2024-07-14)
binary: rustc
commit-hash: f8e4ac0760216724f69b1ebc369bf03da56a7520
commit-date: 2024-07-14
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 --crate-type=lib

Program output

``` thread 'rustc' panicked at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/compiler/rustc_const_eval/src/interpret/projection.rs:166:13: assertion failed: !base.layout().is_sized() stack backtrace: 0: 0x723ebf105865 - std::backtrace_rs::backtrace::libunwind::trace::hd38d957c3cc252d2 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x723ebf105865 - std::backtrace_rs::backtrace::trace_unsynchronized::h1872a55102afa6eb at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x723ebf105865 - std::sys::backtrace::_print_fmt::h20dc7ce96546708c at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/sys/backtrace.rs:65:5 3: 0x723ebf105865 - ::fmt::hc05f0077a6d9d85d at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/sys/backtrace.rs:40:26 4: 0x723ebf1550eb - core::fmt::rt::Argument::fmt::hc83d8497f7eca888 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/core/src/fmt/rt.rs:173:76 5: 0x723ebf1550eb - core::fmt::write::h018b5020a31eaee4 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/core/src/fmt/mod.rs:1182:21 6: 0x723ebf0fa3cf - std::io::Write::write_fmt::ha03f1960d314b86c at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/io/mod.rs:1827:15 7: 0x723ebf108051 - std::sys::backtrace::BacktraceLock::print::hb613464fb9731709 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/sys/backtrace.rs:43:9 8: 0x723ebf108051 - std::panicking::default_hook::{{closure}}::h535fcea069b87644 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/panicking.rs:269:22 9: 0x723ebf107d2c - std::panicking::default_hook::h8a985a1bbf049349 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/panicking.rs:296:9 10: 0x723ebb5ec589 - std[7a47f84281342453]::panicking::update_hook::>::{closure#0} 11: 0x723ebf108a1f - as core::ops::function::Fn>::call::h0580c9dd81c802de at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/alloc/src/boxed.rs:2084:9 12: 0x723ebf108a1f - std::panicking::rust_panic_with_hook::hdb4c410c90ba309a at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/panicking.rs:808:13 13: 0x723ebf108613 - std::panicking::begin_panic_handler::{{closure}}::hd6b26adc9172d33b at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/panicking.rs:667:13 14: 0x723ebf105d29 - std::sys::backtrace::__rust_end_short_backtrace::h3a27e3f65f32503b at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/sys/backtrace.rs:168:18 15: 0x723ebf1082d4 - rust_begin_unwind at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/panicking.rs:665:5 16: 0x723ebf1516a3 - core::panicking::panic_fmt::ha0ad70cf2f26aad8 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/core/src/panicking.rs:74:14 17: 0x723ebf15172c - core::panicking::panic::h6e669894f5b53db5 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/core/src/panicking.rs:148:5 18: 0x723ebe4411b7 - >::project_field::.cold 19: 0x723ebbe1e851 - ::assign_constant::{closure#0} 20: 0x723ebbd479eb - ::for_each_projection_value::::assign_constant::{closure#0}, ::assign_constant::{closure#1}> 21: 0x723ebbd47a6c - ::for_each_projection_value::::assign_constant::{closure#0}, ::assign_constant::{closure#1}> 22: 0x723ebbe1e806 - ::assign_constant 23: 0x723ebbdd6ba0 - ::assign_operand 24: 0x723ebbe1cc4d - ::run_pass 25: 0x723ebcc01cbb - rustc_mir_transform[a9e991cd80486376]::pass_manager::run_passes_inner 26: 0x723ebd15eed6 - rustc_mir_transform[a9e991cd80486376]::optimized_mir 27: 0x723ebdaab21b - rustc_query_impl[a0d93f3a76d1e236]::plumbing::__rust_begin_short_backtrace::> 28: 0x723ebced50e3 - rustc_query_system[967e3c5480e09d8a]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[a0d93f3a76d1e236]::plumbing::QueryCtxt, false> 29: 0x723ebced48e0 - rustc_query_impl[a0d93f3a76d1e236]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace 30: 0x723ebd3f4023 - rustc_middle[b63224948423896b]::query::plumbing::query_get_at::>> 31: 0x723ebd3f9aa1 - ::encode_crate_root 32: 0x723ebdc7e31e - rustc_metadata[e0a5a3ee2c4f394f]::rmeta::encoder::encode_metadata 33: 0x723ebdc7c3f4 - rustc_metadata[e0a5a3ee2c4f394f]::fs::encode_and_write_metadata 34: 0x723ebdc7b083 - ::codegen_and_build_linker 35: 0x723ebd9c0676 - rustc_interface[f891d35c33df0120]::interface::run_compiler::, rustc_driver_impl[a19efe568a6a6683]::run_compiler::{closure#0}>::{closure#1} 36: 0x723ebd99cc09 - std[7a47f84281342453]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[a19efe568a6a6683]::run_compiler::{closure#0}>::{closure#1}, core[5c27b473aec29ed1]::result::Result<(), rustc_span[8a5224f023f17529]::ErrorGuaranteed>>::{closure#0}, core[5c27b473aec29ed1]::result::Result<(), rustc_span[8a5224f023f17529]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5c27b473aec29ed1]::result::Result<(), rustc_span[8a5224f023f17529]::ErrorGuaranteed>> 37: 0x723ebd99c9ba - <::spawn_unchecked_, rustc_driver_impl[a19efe568a6a6683]::run_compiler::{closure#0}>::{closure#1}, core[5c27b473aec29ed1]::result::Result<(), rustc_span[8a5224f023f17529]::ErrorGuaranteed>>::{closure#0}, core[5c27b473aec29ed1]::result::Result<(), rustc_span[8a5224f023f17529]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5c27b473aec29ed1]::result::Result<(), rustc_span[8a5224f023f17529]::ErrorGuaranteed>>::{closure#2} as core[5c27b473aec29ed1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 38: 0x723ebf1128cb - as core::ops::function::FnOnce>::call_once::hf9b8e00cff207f55 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/alloc/src/boxed.rs:2070:9 39: 0x723ebf1128cb - as core::ops::function::FnOnce>::call_once::hd33bea353aae3a46 at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/alloc/src/boxed.rs:2070:9 40: 0x723ebf1128cb - std::sys::pal::unix::thread::Thread::new::thread_start::hb95383f957b5020b at /rustc/f8e4ac0760216724f69b1ebc369bf03da56a7520/library/std/src/sys/pal/unix/thread.rs:108:17 41: 0x723eb80a6ded - 42: 0x723eb812a0dc - 43: 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.81.0-nightly (f8e4ac076 2024-07-14) running on x86_64-unknown-linux-gnu note: compiler flags: -Z mir-opt-level=5 --crate-type lib -Z dump-mir-dir=dir query stack during panic: #0 [optimized_mir] optimizing MIR for `::other_func` end of query stack ```

matthiaskrgr commented 1 month ago

127087 cc @cjgillot