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: !base.layout().is_sized() #123078

Closed
matthiaskrgr opened this issue Mar 26, 2024 · 10 comments · Fixed by #123579
Closed

ICE: !base.layout().is_sized() #123078

matthiaskrgr opened this issue Mar 26, 2024 · 10 comments · Fixed by #123579
Assignees
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority 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):

use std::mem;

#[repr(C)]

const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe {};

enum UninhDiscriminant {
    A,
    B(!),
    C,
    D(Copy),
}

const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };

// # other
original code

original:

// Strip out raw byte dumps to make comparison platform-independent:
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
//@ normalize-stderr-test "0x0+" -> "0x0"
#![feature(never_type)]
#![allow(invalid_value)]

use std::mem;

#[repr(transparent)]
#[derive(Copy, Clone)]
struct Wrap<T>(T);

#[derive(Copy, Clone)]
enum Never {}

// # simple enum with discriminant 0

#[repr(usize)]
#[derive(Copy, Clone)]
enum Enum {
    A = 0,
}

const GOOD_ENUM: Enum = unsafe { mem::transmute(0usize) };

const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
//~^ ERROR is undefined behavior

const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
//~^ ERROR evaluation of constant value failed

const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
//~^ ERROR evaluation of constant value failed

// # simple enum with discriminant 2

// (Potentially) invalid enum discriminant
#[repr(usize)]
#[derive(Copy, Clone)]
enum Enum2 {
    A = 2,
}

const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
//~^ ERROR is undefined behavior
const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
//~^ ERROR evaluation of constant value failed
// something wrapping the enum so that we test layout first, not enum
const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
//~^ ERROR evaluation of constant value failed

// Undef enum discriminant.
#[repr(C)]
union MaybeUninit<T: Copy> {
    uninit: (),
    init: T,
}
const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
//~^ ERROR evaluation of constant value failed
//~| uninitialized

// Pointer value in an enum with a niche that is not just 0.
const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
//~^ ERROR evaluation of constant value failed

// # valid discriminant for uninhabited variant

// An enum with uninhabited variants but also at least 2 inhabited variants -- so the uninhabited
// variants *do* have a discriminant.
enum UninhDiscriminant {
    A,
    B(!),
    C,
    D(Copy),
}

const GOOD_INHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(0u8) }; // variant A
const GOOD_INHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(2u8) }; // variant C

const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
//~^ ERROR is undefined behavior
const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
//~^ ERROR is undefined behavior

// # other

// Invalid enum field content (mostly to test printing of paths for enum tuple
// variants and tuples).
// Need to create something which does not clash with enum layout optimizations.
const BAD_OPTION_CHAR: Option<(usize, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
//~^ ERROR is undefined behavior

// All variants are uninhabited but also have data.
// Use `0` as constant to make behavior endianness-independent.
const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(0u64) };
//~^ ERROR evaluation of constant value failed
const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(0u64) };
//~^ ERROR evaluation of constant value failed

const TEST_ICE_89765: () = {
    // This is a regression test for https://github.com/rust-lang/rust/issues/89765.
    unsafe { std::mem::discriminant(&*(&() as *const () as *const Never)); };
    //~^ inside `TEST_ICE_89765`
};

fn main() {
}

Version information

rustc 1.79.0-nightly (35936c483 2024-03-25)
binary: rustc
commit-hash: 35936c4839dd272646394779d151e060d0f6b3ac
commit-date: 2024-03-25
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

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

Program output

error[E0412]: cannot find type `Enum2` in this scope
 --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:5:36
  |
5 | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe {};
  |                                    ^^^^^ not found in this scope
  |
help: you might be missing a type parameter
  |
5 | const BAD_ENUM2_OPTION_PTR<Enum2>: Option<Enum2> = unsafe {};
  |                           +++++++

error[E0658]: the `!` type is experimental
 --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:9:7
  |
9 |     B(!),
  |       ^
  |
  = note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
  = help: add `#![feature(never_type)]` to the crate attributes to enable
  = note: this compiler was built on 2024-03-25; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:14:84
   |
14 | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
   |                                                                                    ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs`

error[E0517]: attribute should be applied to a struct, enum, or union
 --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:3:8
  |
3 | #[repr(C)]
  |        ^
4 |
5 | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe {};
  | ------------------------------------------------------ not a struct, enum, or union

warning: trait objects without an explicit `dyn` are deprecated
  --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:11:7
   |
11 |     D(Copy),
   |       ^^^^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
   = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
   |
11 |     D(dyn Copy),
   |       +++

error[E0038]: the trait `Copy` cannot be made into an object
  --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:11:7
   |
11 |     D(Copy),
   |       ^^^^ `Copy` cannot be made into an object
   |
   = note: the trait cannot be made into an object because it requires `Self: Sized`
   = note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>

error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known at compilation time
  --> /tmp/icemaker_global_tempdir.vKOVyrYun5C7/rustc_testrunner_tmpdir_reporting.hFu1a4fPxKRm/mvce.rs:11:7
   |
11 |     D(Copy),
   |       ^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `(dyn Copy + 'static)`
   = note: no field of an enum variant may have a dynamically sized type
   = help: change the field's type to have a statically known size
help: borrowed types always have a statically known size
   |
11 |     D(&Copy),
   |       +
help: the `Box` type always has a statically known size and allocates its contents in the heap
   |
11 |     D(Box<Copy>),
   |       ++++    +

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:158:13:
assertion failed: !base.layout().is_sized()
stack backtrace:
   0:     0x75b6e602efd5 - std::backtrace_rs::backtrace::libunwind::trace::h358d27b0beb91d52
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x75b6e602efd5 - std::backtrace_rs::backtrace::trace_unsynchronized::hb23626f2832be2ef
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x75b6e602efd5 - std::sys_common::backtrace::_print_fmt::h12a2241e36ed88c8
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x75b6e602efd5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h00f4d0202e49b73c
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x75b6e608013b - core::fmt::rt::Argument::fmt::h50b99c7ac9b6f780
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/fmt/rt.rs:142:9
   5:     0x75b6e608013b - core::fmt::write::h052bbc034f024029
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/fmt/mod.rs:1153:17
   6:     0x75b6e6023d6f - std::io::Write::write_fmt::h8a7055241a914793
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/io/mod.rs:1843:15
   7:     0x75b6e602edae - std::sys_common::backtrace::_print::hc7429e59d20aef3d
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x75b6e602edae - std::sys_common::backtrace::print::h098f1297ce95d7fd
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x75b6e6031a29 - std::panicking::default_hook::{{closure}}::hfacad2d95a15b54f
  10:     0x75b6e6031793 - std::panicking::default_hook::h335f6dbc0bdf0870
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:292:9
  11:     0x75b6e29d127f - std[8986ecfb476bfa7d]::panicking::update_hook::<alloc[d5b01f14e800d591]::boxed::Box<rustc_driver_impl[4b2f8406c0f6a8ac]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x75b6e603212c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h981ebc744fbdca0e
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/alloc/src/boxed.rs:2029:9
  13:     0x75b6e603212c - std::panicking::rust_panic_with_hook::h1985d360b67b5f37
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:793:13
  14:     0x75b6e6031e9d - std::panicking::begin_panic_handler::{{closure}}::hf64883af21dee792
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:650:13
  15:     0x75b6e602f499 - std::sys_common::backtrace::__rust_end_short_backtrace::h48fdcafa2a5427ef
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x75b6e6031c07 - rust_begin_unwind
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:646:5
  17:     0x75b6e607c5d6 - core::panicking::panic_fmt::h01c5db37aea323f1
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/panicking.rs:72:14
  18:     0x75b6e607c67f - core::panicking::panic::haef388cfe0bf5f86
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/panicking.rs:141:5
  19:     0x75b6e3e40d39 - <rustc_const_eval[62a5e1dbaf8a1d0a]::interpret::eval_context::InterpCx<rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::machine::CompileTimeInterpreter>>::project_field::<rustc_const_eval[62a5e1dbaf8a1d0a]::interpret::operand::OpTy>
  20:     0x75b6e3e3ca50 - <rustc_const_eval[62a5e1dbaf8a1d0a]::interpret::validity::ValidityVisitor<rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::machine::CompileTimeInterpreter> as rustc_const_eval[62a5e1dbaf8a1d0a]::interpret::visitor::ValueVisitor<rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::machine::CompileTimeInterpreter>>::visit_value
  21:     0x75b6e3e3d0b2 - <rustc_const_eval[62a5e1dbaf8a1d0a]::interpret::validity::ValidityVisitor<rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::machine::CompileTimeInterpreter> as rustc_const_eval[62a5e1dbaf8a1d0a]::interpret::visitor::ValueVisitor<rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::machine::CompileTimeInterpreter>>::visit_value
  22:     0x75b6e49a19b0 - rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::eval_queries::eval_to_allocation_raw_provider
  23:     0x75b6e49a0380 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 24usize]>>
  24:     0x75b6e499d3d6 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::DefaultCache<rustc_middle[b97de266c643709b]::ty::ParamEnvAnd<rustc_middle[b97de266c643709b]::mir::interpret::GlobalId>, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  25:     0x75b6e499cfac - rustc_query_impl[a0c31ac015223081]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  26:     0x75b6e499cb0e - rustc_middle[b97de266c643709b]::query::plumbing::query_get_at::<rustc_query_system[97bff28321f2bac]::query::caches::DefaultCache<rustc_middle[b97de266c643709b]::ty::ParamEnvAnd<rustc_middle[b97de266c643709b]::mir::interpret::GlobalId>, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 24usize]>>>
  27:     0x75b6e499b03f - rustc_const_eval[62a5e1dbaf8a1d0a]::const_eval::eval_queries::eval_to_const_value_raw_provider
  28:     0x75b6e499afb6 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 24usize]>>
  29:     0x75b6e499d399 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::DefaultCache<rustc_middle[b97de266c643709b]::ty::ParamEnvAnd<rustc_middle[b97de266c643709b]::mir::interpret::GlobalId>, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  30:     0x75b6e499ceac - rustc_query_impl[a0c31ac015223081]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  31:     0x75b6e40ec2e9 - <rustc_middle[b97de266c643709b]::query::plumbing::TyCtxtEnsure>::const_eval_poly
  32:     0x75b6e3fcb775 - rustc_hir_analysis[56e3c688dc2c0c48]::check_crate
  33:     0x75b6e42a656a - rustc_interface[c38f70925b3e6389]::passes::analysis
  34:     0x75b6e42a60c7 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>
  35:     0x75b6e4ba8f03 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::SingleCache<rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  36:     0x75b6e4ba8c7f - rustc_query_impl[a0c31ac015223081]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x75b6e4a8c299 - rustc_interface[c38f70925b3e6389]::interface::run_compiler::<core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>, rustc_driver_impl[4b2f8406c0f6a8ac]::run_compiler::{closure#0}>::{closure#0}
  38:     0x75b6e4b62bd9 - std[8986ecfb476bfa7d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c38f70925b3e6389]::util::run_in_thread_with_globals<rustc_interface[c38f70925b3e6389]::util::run_in_thread_pool_with_globals<rustc_interface[c38f70925b3e6389]::interface::run_compiler<core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>, rustc_driver_impl[4b2f8406c0f6a8ac]::run_compiler::{closure#0}>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>
  39:     0x75b6e4b62a06 - <<std[8986ecfb476bfa7d]::thread::Builder>::spawn_unchecked_<rustc_interface[c38f70925b3e6389]::util::run_in_thread_with_globals<rustc_interface[c38f70925b3e6389]::util::run_in_thread_pool_with_globals<rustc_interface[c38f70925b3e6389]::interface::run_compiler<core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>, rustc_driver_impl[4b2f8406c0f6a8ac]::run_compiler::{closure#0}>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#1} as core[8cbc9b2d85f665a9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x75b6e603ba49 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6dc9de06dfc501ab
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/alloc/src/boxed.rs:2015:9
  41:     0x75b6e603ba49 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc5bbd99ced815c6f
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/alloc/src/boxed.rs:2015:9
  42:     0x75b6e603ba49 - std::sys::pal::unix::thread::Thread::new::thread_start::h0243db2ae6ac2b16
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys/pal/unix/thread.rs:108:17
  43:     0x75b6df8a955a - <unknown>
  44:     0x75b6df926a3c - <unknown>
  45:                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: rustc 1.79.0-nightly (35936c483 2024-03-25) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `BAD_UNINHABITED_VARIANT2`
#1 [eval_to_const_value_raw] simplifying constant for the type system `BAD_UNINHABITED_VARIANT2`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 6 previous errors; 1 warning emitted

Some errors have detailed explanations: E0038, E0277, E0412, E0517, E0601, E0658.
For more information about an error, try `rustc --explain E0038`.

@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 Mar 26, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2024
@matthiaskrgr
Copy link
Member Author

regression in #122493 cc @lukas-code

@lukas-code
Copy link
Contributor

#122493 makes this easier to trigger, but isn't the root cause. If you change it like this, it also ICEs on beta:

use std::mem;

#[repr(C)]

const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe {};

enum UninhDiscriminant {
    A,
    B(!),
    C,
-    D(Copy),
+    D(Copy, ()),
}

const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };

// # other

@lukas-code
Copy link
Contributor

lukas-code commented Mar 26, 2024

minimized:

struct S {
    a: [u8],
    b: ()
}

const C: S = unsafe { std::mem::transmute(()) };

@GrigorenkoPV
Copy link
Contributor

minimized:

struct S {
    a: [u8],
    b: ()
}

const C: S = unsafe { std:mem::transmute(()) };

There is a typo in std:mem, but it does not really matter.

searched nightlies: from nightly-2024-01-01 to nightly-2024-03-15
regressed nightly: nightly-2024-02-21
searched commit range: 3246e79...bb59453
regressed commit: cce6a6e (#121087, cc @oli-obk)

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc -vv --preserve --access=github --start=2024-01-01 --end=2024-03-15 --regress=ice 

@oli-obk
Copy link
Contributor

oli-obk commented Mar 26, 2024

Not a regression from #121087, just exposed more easily 😆 .

struct S {
    a: [u8],
    b: ()
}

const C: S = unsafe { std::mem::transmute(()) };
const _: [(); {
    C;
    0
}] = [];

has been ICEing much longer

@GrigorenkoPV
Copy link
Contributor

has been ICEing much longer

Damn, we need to go deeper. Judging by Godbolt, the regression is all the way back between 1.25 & 1.26.

It bisects to nightly-2018-03-15, which is 2789b06...521d91c. There are 34 merges in range, and god knows how many rollups.

@GrigorenkoPV
Copy link
Contributor

Did some git bisecting, it bisects to #46882 (cc @oli-obk once again).

Out of 110 commits in that PR, most seem to not build, so I cannot pinpoint the breakage point more precisely.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 26, 2024

lol, that's amazing. thanks!

@oli-obk oli-obk self-assigned this Mar 26, 2024
@oli-obk oli-obk added P-low Low priority A-const-eval Area: constant evaluation (mir interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 26, 2024
@jieyouxu
Copy link
Member

This line also seems funny

let _ = tcx.representability(item.owner_id.def_id);

does it straight up ignore the err guarantee if tcx.representability() is Representability::Infinite?

@fmease
Copy link
Member

fmease commented Mar 26, 2024

I love this thread <3 haha

@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 4, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 7, 2024
@bors bors closed this as completed in 5dc7fe4 Apr 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 7, 2024
Rollup merge of rust-lang#123579 - matthiaskrgr:I_Love_Tests, r=jieyouxu

add some more tests

Fixes rust-lang#115806
Fixes rust-lang#116710
Fixes rust-lang#123145
Fixes rust-lang#105488
Fixes rust-lang#122488
Fixes rust-lang#123078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority 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.

7 participants