rust-lang / rust

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

ICE: coherence: `SizeOf MIR operator called for unsized type dyn Trait` #124894

Closed matthiaskrgr closed 1 month ago

matthiaskrgr commented 6 months ago

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]

pub trait IsTrue<const mem: bool> {}
impl<T> IsZST for T where (): IsTrue<{ std::mem::size_of::<T>() == 0 }> {}

pub trait IsZST {}

impl IsZST for IsZST {}

original:

#![feature(generic_const_exprs)]

pub trait IsTrue<const mem: bool> {}
impl<T> IsZST for T where (): IsTrue<{ std::mem::size_of::<T>() == 0 }> {}

pub trait IsZST {}

impl IsZST for IsZST where (IsZST): IsTrue<{ std::mem::feature() == 0 }> {}

fn func() -> impl T {
    || || {}
}

Version information

rustc 1.80.0-nightly (0f40f14b6 2024-05-07)
binary: rustc
commit-hash: 0f40f14b61430792cc0ea316f424685041e8443e
commit-date: 2024-05-07
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=coherence

Program output

``` warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> /tmp/icemaker_global_tempdir.38jH8PqIIyFH/rustc_testrunner_tmpdir_reporting.ZcVb1Wm0uNmv/mvce.rs:1:12 | 1 | #![feature(generic_const_exprs)] | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 for more information = note: `#[warn(incomplete_features)]` on by default error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.38jH8PqIIyFH/rustc_testrunner_tmpdir_reporting.ZcVb1Wm0uNmv/mvce.rs:8:24 | 8 | impl IsZST for IsZST {} | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.38jH8PqIIyFH/rustc_testrunner_tmpdir_reporting.ZcVb1Wm0uNmv/mvce.rs` warning: trait objects without an explicit `dyn` are deprecated --> /tmp/icemaker_global_tempdir.38jH8PqIIyFH/rustc_testrunner_tmpdir_reporting.ZcVb1Wm0uNmv/mvce.rs:8:16 | 8 | impl IsZST for IsZST {} | ^^^^^ | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `#[warn(bare_trait_objects)]` on by default help: if this is an object-safe trait, use `dyn` | 8 | impl IsZST for dyn IsZST {} | +++ help: alternatively use a blanket implementation to implement `IsZST` for all types that also implement `IsZST` | 8 | impl IsZST for T {} | ++++++++++ ~ error: internal compiler error: compiler/rustc_const_eval/src/interpret/step.rs:245:21: SizeOf MIR operator called for unsized type dyn IsZST --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/mem/mod.rs:313:5 | 313 | intrinsics::size_of::() | ^^^^^^^^^^^^^^^^^^^^^^^^^^ thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/step.rs:245:21: Box stack backtrace: 0: 0x74838d6fab35 - std::backtrace_rs::backtrace::libunwind::trace::h16226f415edd7020 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x74838d6fab35 - std::backtrace_rs::backtrace::trace_unsynchronized::hd074bfbed0466e66 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x74838d6fab35 - std::sys_common::backtrace::_print_fmt::h6bd81933b11821e3 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/sys_common/backtrace.rs:68:5 3: 0x74838d6fab35 - ::fmt::h65a05c4cbe1ebf40 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/sys_common/backtrace.rs:44:22 4: 0x74838d749cfb - core::fmt::rt::Argument::fmt::h033c76ea7ea75413 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/core/src/fmt/rt.rs:165:63 5: 0x74838d749cfb - core::fmt::write::h33ad7509b2338e1d at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/core/src/fmt/mod.rs:1157:21 6: 0x74838d6ef8ff - std::io::Write::write_fmt::hf66d49f3041f55e8 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/io/mod.rs:1835:15 7: 0x74838d6fa90e - std::sys_common::backtrace::_print::h2ca303a605610994 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/sys_common/backtrace.rs:47:5 8: 0x74838d6fa90e - std::sys_common::backtrace::print::h592d77d1173200d4 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/sys_common/backtrace.rs:34:9 9: 0x74838d6fd279 - std::panicking::default_hook::{{closure}}::h4da60be94553ec4b 10: 0x74838d6fcfbd - std::panicking::default_hook::h40234bfa16395ce9 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/panicking.rs:298:9 11: 0x74838a0bdb20 - std[8d7719e78985e352]::panicking::update_hook::>::{closure#0} 12: 0x74838d6fd976 - as core::ops::function::Fn>::call::hceeefca90c01e520 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/alloc/src/boxed.rs:2036:9 13: 0x74838d6fd976 - std::panicking::rust_panic_with_hook::h9534e82f08371dbb at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/panicking.rs:799:13 14: 0x74838a0ed2a4 - std[8d7719e78985e352]::panicking::begin_panic::::{closure#0} 15: 0x74838a0e9c56 - std[8d7719e78985e352]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x74838a0e5206 - std[8d7719e78985e352]::panicking::begin_panic:: 17: 0x74838a0f6431 - ::emit_producing_guarantee 18: 0x74838a018d18 - ::span_bug:: 19: 0x74838a038f2d - rustc_middle[bc0899ebf53e261d]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x74838a038f5a - rustc_middle[bc0899ebf53e261d]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x74838a02eeeb - rustc_middle[bc0899ebf53e261d]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x748388a1c7e7 - rustc_middle[bc0899ebf53e261d]::util::bug::span_bug_fmt:: 23: 0x74838bef19d2 - >::eval_rvalue_into_place 24: 0x7483895a2dec - rustc_const_eval[5b0cf469bb9ad215]::const_eval::eval_queries::eval_to_allocation_raw_provider 25: 0x74838ba6d6bc - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 26: 0x74838ba6ced9 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::, rustc_middle[bc0899ebf53e261d]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 27: 0x74838ba6caac - rustc_query_impl[f12a8811d86a62d9]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace 28: 0x74838ba6c636 - rustc_middle[bc0899ebf53e261d]::query::plumbing::query_get_at::, rustc_middle[bc0899ebf53e261d]::query::erase::Erased<[u8; 24usize]>>> 29: 0x74838ba7b66b - rustc_const_eval[5b0cf469bb9ad215]::const_eval::valtrees::eval_to_valtree 30: 0x74838ba7b5ff - )>>::call_once 31: 0x74838ba7b5b6 - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 32: 0x74838ba7b56f - )>>::call_once 33: 0x74838ba6cfb4 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::, rustc_middle[bc0899ebf53e261d]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 34: 0x74838b748c02 - rustc_query_impl[f12a8811d86a62d9]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace 35: 0x74838b7478f1 - rustc_middle[bc0899ebf53e261d]::query::plumbing::query_get_at::, rustc_middle[bc0899ebf53e261d]::query::erase::Erased<[u8; 24usize]>>> 36: 0x74838bdb3888 - ::const_eval_global_id_for_typeck 37: 0x74838bdb3e17 - ::const_eval_resolve_for_typeck 38: 0x74838a401cea - ::const_eval_resolve 39: 0x74838a3e166a - ::try_const_eval_resolve 40: 0x74838abf147c - ::try_const_eval_resolve 41: 0x74838bffb6fa - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#3} 42: 0x74838bff3561 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 43: 0x74838bfee732 - ::evaluate_goal_raw 44: 0x74838bfed9a4 - ::evaluate_root_goal 45: 0x74838bfecb20 - ::select_where_possible 46: 0x74838b7c3a5a - ::select_all_or_error 47: 0x74838b931c1e - rustc_trait_selection[2e2c9bd5c426cc94]::traits::coherence::overlap 48: 0x74838c07ae4b - ::insert 49: 0x748389131a38 - ::insert 50: 0x74838b48527c - rustc_trait_selection[2e2c9bd5c426cc94]::traits::specialize::specialization_graph_provider 51: 0x74838b484ddf - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 52: 0x74838b4877d7 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 53: 0x74838bb271b4 - rustc_query_impl[f12a8811d86a62d9]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace 54: 0x74838bd963c4 - rustc_hir_analysis[7f78c912bc544423]::coherence::coherent_trait 55: 0x74838bd960d1 - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 56: 0x74838b713758 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 57: 0x74838b7116df - rustc_query_impl[f12a8811d86a62d9]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace 58: 0x74838bab1aaa - rustc_hir_analysis[7f78c912bc544423]::check::wfcheck::check_well_formed 59: 0x74838baaf89d - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 60: 0x74838baaf040 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 61: 0x74838baaedbf - rustc_query_impl[f12a8811d86a62d9]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace 62: 0x74838baacd01 - rustc_hir_analysis[7f78c912bc544423]::check::wfcheck::check_mod_type_wf 63: 0x74838baacb47 - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 64: 0x74838bf1ce30 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 65: 0x74838bf1cbdb - rustc_query_impl[f12a8811d86a62d9]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace 66: 0x74838b9cd0dc - rustc_hir_analysis[7f78c912bc544423]::check_crate 67: 0x74838bdb9047 - rustc_interface[1dc2dcc2b864e855]::passes::analysis 68: 0x74838bdb8b87 - rustc_query_impl[f12a8811d86a62d9]::plumbing::__rust_begin_short_backtrace::> 69: 0x74838c1d0225 - rustc_query_system[6d5fb7023970bca8]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f12a8811d86a62d9]::plumbing::QueryCtxt, false> 70: 0x74838c1cff89 - rustc_query_impl[f12a8811d86a62d9]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 71: 0x74838c02e70e - rustc_interface[1dc2dcc2b864e855]::interface::run_compiler::, rustc_driver_impl[589f8a1b01aee9f6]::run_compiler::{closure#0}>::{closure#1} 72: 0x74838c00be49 - std[8d7719e78985e352]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[589f8a1b01aee9f6]::run_compiler::{closure#0}>::{closure#1}, core[b90f87831ee46a2c]::result::Result<(), rustc_span[fbdf81e3d6e3d53e]::ErrorGuaranteed>>::{closure#0}, core[b90f87831ee46a2c]::result::Result<(), rustc_span[fbdf81e3d6e3d53e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b90f87831ee46a2c]::result::Result<(), rustc_span[fbdf81e3d6e3d53e]::ErrorGuaranteed>> 73: 0x74838c00bbf8 - <::spawn_unchecked_, rustc_driver_impl[589f8a1b01aee9f6]::run_compiler::{closure#0}>::{closure#1}, core[b90f87831ee46a2c]::result::Result<(), rustc_span[fbdf81e3d6e3d53e]::ErrorGuaranteed>>::{closure#0}, core[b90f87831ee46a2c]::result::Result<(), rustc_span[fbdf81e3d6e3d53e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b90f87831ee46a2c]::result::Result<(), rustc_span[fbdf81e3d6e3d53e]::ErrorGuaranteed>>::{closure#2} as core[b90f87831ee46a2c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 74: 0x74838d7077bb - as core::ops::function::FnOnce>::call_once::h8236c067dabb3bba at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/alloc/src/boxed.rs:2022:9 75: 0x74838d7077bb - as core::ops::function::FnOnce>::call_once::h842b37a516a98fc8 at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/alloc/src/boxed.rs:2022:9 76: 0x74838d7077bb - std::sys::pal::unix::thread::Thread::new::thread_start::h82e010f2c7789ffb at /rustc/0f40f14b61430792cc0ea316f424685041e8443e/library/std/src/sys/pal/unix/thread.rs:108:17 77: 0x748386ea955a - 78: 0x748386f26a3c - 79: 0x0 - 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 (0f40f14b6 2024-05-07) running on x86_64-unknown-linux-gnu note: compiler flags: -Z next-solver=coherence -Z dump-mir-dir=dir query stack during panic: #0 [eval_to_allocation_raw] const-evaluating + checking `::{constant#0}` #1 [eval_to_valtree] evaluating type-level constant #2 [specialization_graph_of] building specialization graph of trait `IsZST` #3 [coherent_trait] coherence checking all impls of trait `IsZST` #4 [check_well_formed] checking that `` is well-formed #5 [check_mod_type_wf] checking that types are well-formed in top-level module #6 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0601`. ```

@rustbot label +F-generic_const_exprs

matthiaskrgr commented 6 months ago

121193 cc @compiler-errors