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: `the naive layout isn't refined by the actual layout` #113952

Closed matthiaskrgr closed 1 year ago

matthiaskrgr commented 1 year ago

Code

enum E {
    S0 {
        s: String,
    },
    Bar = {
        let x = 1;
        3
    },
}

static C: E = E::S1 { u: 23 };

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (0308df23e 2023-07-21)
binary: rustc
commit-hash: 0308df23e621e783e31a27ca5beaa01b9df60d4a
commit-date: 2023-07-21
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

error[E0601]: `main` function not found in crate `treereduce`
  --> treereduce.out:11:31
   |
11 | static C: E = E::S1 { u: 23 };
   |                               ^ consider adding a `main` function to `treereduce.out`

warning: unused variable: `x`
 --> treereduce.out:6:13
  |
6 |         let x = 1;
  |             ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

error[E0732]: `#[repr(inttype)]` must be specified
 --> treereduce.out:1:1
  |
1 | enum E {
  | ^^^^^^

error[E0599]: no variant named `S1` found for enum `E`
  --> treereduce.out:11:18
   |
1  | enum E {
   | ------ variant `S1` not found here
...
11 | static C: E = E::S1 { u: 23 };
   |                  ^^ help: there is a variant with a similar name: `S0`
Backtrace

``` error: internal compiler error: compiler/rustc_ty_utils/src/layout_sanity_check.rs:25:9: the naive layout isn't refined by the actual layout: NaiveLayout { abi: Sized, niches: Maybe, size: Size(24 bytes), align: Align(8 bytes), exact: true, } TyAndLayout { ty: E, layout: Layout { size: Size(32 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes), }, abi: Aggregate { sized: true, }, fields: Arbitrary { offsets: [ Size(0 bytes), ], memory_index: [ 0, ], }, largest_niche: Some( Niche { offset: Size(0 bytes), value: Int( I64, false, ), valid_range: 0..=3, }, ), variants: Multiple { tag: Initialized { value: Int( I64, false, ), valid_range: 0..=3, }, tag_encoding: Direct, tag_field: 0, variants: [ Layout { size: Size(32 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes), }, abi: Aggregate { sized: true, }, fields: Arbitrary { offsets: [ Size(8 bytes), ], memory_index: [ 0, ], }, largest_niche: Some( Niche { offset: Size(8 bytes), value: Pointer( AddressSpace( 0, ), ), valid_range: 1..=18446744073709551615, }, ), variants: Single { index: 0, }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), }, Layout { size: Size(8 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), pref: Align(8 bytes), }, abi: Aggregate { sized: true, }, fields: Arbitrary { offsets: [], memory_index: [], }, largest_niche: None, variants: Single { index: 1, }, max_repr_align: None, unadjusted_abi_align: Align(1 bytes), }, ], }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), }, } thread 'rustc' panicked at 'Box', /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/compiler/rustc_errors/src/lib.rs:1663:9 stack backtrace: 0: 0x7fa228b62fc1 - std::backtrace_rs::backtrace::libunwind::trace::h8f154b6a796326e2 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7fa228b62fc1 - std::backtrace_rs::backtrace::trace_unsynchronized::hb8abeaf7dfb1c24b at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fa228b62fc1 - std::sys_common::backtrace::_print_fmt::h3f47e60290db41a5 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7fa228b62fc1 - ::fmt::h4552f2dd442a589d at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7fa228bc949c - core::fmt::rt::Argument::fmt::h78a6be6446bd82bd at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/core/src/fmt/rt.rs:138:9 5: 0x7fa228bc949c - core::fmt::write::hd14ae211f7dd66b2 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/core/src/fmt/mod.rs:1094:21 6: 0x7fa228b557ae - std::io::Write::write_fmt::hdc8c0b5c45666412 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/io/mod.rs:1714:15 7: 0x7fa228b62dd5 - std::sys_common::backtrace::_print::h381fcf6b91d9d880 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7fa228b62dd5 - std::sys_common::backtrace::print::hcfe75c5be0f60777 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7fa228b65e2a - std::panicking::panic_hook_with_disk_dump::{{closure}}::hfe5fad22482c9f6d at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/panicking.rs:278:22 10: 0x7fa228b65ac3 - std::panicking::panic_hook_with_disk_dump::hc822f132c197763d at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/panicking.rs:312:9 11: 0x7fa22bd928b9 - rustc_driver_impl[fead4037fc65a3e4]::install_ice_hook::{closure#0} 12: 0x7fa228b666d0 - as core::ops::function::Fn>::call::h549a9102e6ec42b3 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/alloc/src/boxed.rs:2021:9 13: 0x7fa228b666d0 - std::panicking::rust_panic_with_hook::h8adf1e4a5b603f89 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/panicking.rs:733:13 14: 0x7fa22c34e271 - std[bbbc53192af03470]::panicking::begin_panic::::{closure#0} 15: 0x7fa22c34c266 - std[bbbc53192af03470]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7fa22c3447a6 - std[bbbc53192af03470]::panicking::begin_panic:: 17: 0x7fa22c2c1f94 - ::bug:: 18: 0x7fa22c2c1e26 - ::bug:: 19: 0x7fa22c29c29c - rustc_middle[2e38e64f479fe5b8]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7fa22c29c0da - rustc_middle[2e38e64f479fe5b8]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7fa22c29c0a8 - rustc_middle[2e38e64f479fe5b8]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7fa22a7a8fa0 - rustc_middle[2e38e64f479fe5b8]::util::bug::bug_fmt 23: 0x7fa22a6f70ce - rustc_ty_utils[55ee87bc8b98e550]::layout::layout_of 24: 0x7fa229e0a8ce - rustc_query_impl[89227dfa721c8c03]::plumbing::__rust_begin_short_backtrace::> 25: 0x7fa22a6ebff1 - rustc_query_system[c0a52eceb1a71305]::query::plumbing::try_execute_query::, rustc_middle[2e38e64f479fe5b8]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[89227dfa721c8c03]::plumbing::QueryCtxt, false> 26: 0x7fa22a6ebbf3 - rustc_query_impl[89227dfa721c8c03]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace 27: 0x7fa22b133e73 - rustc_middle[2e38e64f479fe5b8]::query::plumbing::query_get_at::, rustc_middle[2e38e64f479fe5b8]::query::erase::Erased<[u8; 16usize]>>> 28: 0x7fa22b133429 - rustc_hir_analysis[4792b5973f634bb5]::check::check::check_static_inhabited 29: 0x7fa22b12183c - rustc_hir_analysis[4792b5973f634bb5]::check::check::check_mod_item_types 30: 0x7fa22ab4cb7c - rustc_query_impl[89227dfa721c8c03]::plumbing::__rust_begin_short_backtrace::> 31: 0x7fa22ab4cb5e - >::call_once 32: 0x7fa22a6bb66f - rustc_query_system[c0a52eceb1a71305]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[89227dfa721c8c03]::plumbing::QueryCtxt, false> 33: 0x7fa22b6fb1a2 - rustc_query_impl[89227dfa721c8c03]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace 34: 0x7fa22b230567 - ::for_each_module:: 35: 0x7fa22b22f1ff - rustc_hir_analysis[4792b5973f634bb5]::check_crate 36: 0x7fa22b22b4ba - rustc_interface[c9554cd0b74ea93d]::passes::analysis 37: 0x7fa22b27c82a - rustc_query_impl[89227dfa721c8c03]::plumbing::__rust_begin_short_backtrace::> 38: 0x7fa22b27c819 - >::call_once 39: 0x7fa22b432088 - rustc_query_system[c0a52eceb1a71305]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[89227dfa721c8c03]::plumbing::QueryCtxt, false> 40: 0x7fa22b431e17 - rustc_query_impl[89227dfa721c8c03]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 41: 0x7fa22afd3745 - ::enter::> 42: 0x7fa22afd2d72 - ::enter::, rustc_span[a321f1cb1523dd0b]::ErrorGuaranteed>> 43: 0x7fa22afcff64 - std[bbbc53192af03470]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[fead4037fc65a3e4]::run_compiler::{closure#1}>::{closure#0}, core[d7f3879bb305828b]::result::Result<(), rustc_span[a321f1cb1523dd0b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d7f3879bb305828b]::result::Result<(), rustc_span[a321f1cb1523dd0b]::ErrorGuaranteed>> 44: 0x7fa22afcf68e - <::spawn_unchecked_, rustc_driver_impl[fead4037fc65a3e4]::run_compiler::{closure#1}>::{closure#0}, core[d7f3879bb305828b]::result::Result<(), rustc_span[a321f1cb1523dd0b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d7f3879bb305828b]::result::Result<(), rustc_span[a321f1cb1523dd0b]::ErrorGuaranteed>>::{closure#1} as core[d7f3879bb305828b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 45: 0x7fa228b70dc5 - as core::ops::function::FnOnce>::call_once::h5a713c95dff49eb9 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/alloc/src/boxed.rs:2007:9 46: 0x7fa228b70dc5 - as core::ops::function::FnOnce>::call_once::h6c2630f276b49e94 at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/alloc/src/boxed.rs:2007:9 47: 0x7fa228b70dc5 - std::sys::unix::thread::Thread::new::thread_start::he7c79aaf88d71e7c at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys/unix/thread.rs:108:17 48: 0x7fa22890244b - 49: 0x7fa228985e40 - 50: 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 attach the file at `/tmp/im/new/rustc-ice-2023-07-22T08:57:27.488676915Z-3909743.txt` to your bug report query stack during panic: #0 [layout_of] computing layout of `E` #1 [check_mod_item_types] checking item types in top-level module #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 4 previous errors; 1 warning emitted Some errors have detailed explanations: E0599, E0601, E0732. For more information about an error, try `rustc --explain E0599`. ```

workingjubilee commented 1 year ago

This looks like an exact duplicate of https://github.com/rust-lang/rust/issues/113941 which is now fixed on master. Please confirm if this replicates on master.

matthiaskrgr commented 1 year ago

Regression in 557359f92512ca88b62a602ebda291f17a953002 #113166 cc @moulins

workingjubilee commented 1 year ago

Again, that was already reverted, please confirm if this replicates on master.

matthiaskrgr commented 1 year ago

Ah neat, yeah its already fixed on master :)