Skip to content

ICE: layout_of: unexpected const: {const error} #138009

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(min_generic_const_args)]
#[repr(simd)]
struct T([isize; N]);

static X: T = T();

original:

//@ run-pass
#![target_feature(enable = "avx")]

#[repr(simd)]
struct T([isize; N]);

static X: T = T([0.0, 1.5, 0.0]);

fn main() {
    let _ = X;
}

Version information

rustc 1.87.0-nightly (fd17deacc 2025-03-04)
binary: rustc
commit-hash: fd17deacce374a4185c882795be162e17b557050
commit-date: 2025-03-04
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:

ty::ConstKind::Infer(_)
| ty::ConstKind::Bound(..)
| ty::ConstKind::Placeholder(_)
| ty::ConstKind::Error(_) => {
// `ty::ConstKind::Error` is handled at the top of `layout_of_uncached`
// (via `ty.error_reported()`).
bug!("layout_of: unexpected const: {ct:?}");
}
}
}
fn layout_of_uncached<'tcx>(
cx: &LayoutCx<'tcx>,

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(min_generic_const_args)

Program output

error[E0425]: cannot find value `N` in this scope
 --> /tmp/icemaker_global_tempdir.ROUzTbiGr8Hi/rustc_testrunner_tmpdir_reporting.GaMdaKkEqCKw/mvce.rs:2:18
  |
2 | struct T([isize; N]);
  |                  ^ not found in this scope
  |
help: you might be missing a const parameter
  |
2 | struct T<const N: /* Type */>([isize; N]);
  |         +++++++++++++++++++++

error[E0658]: SIMD types are experimental and possibly buggy
 --> /tmp/icemaker_global_tempdir.ROUzTbiGr8Hi/rustc_testrunner_tmpdir_reporting.GaMdaKkEqCKw/mvce.rs:1:1
  |
1 | #[repr(simd)]
  | ^^^^^^^^^^^^^
  |
  = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
  = help: add `#![feature(repr_simd)]` to the crate attributes to enable
  = note: this compiler was built on 2025-03-04; consider upgrading it if it is out of date

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>:1:9
  |
1 | feature(min_generic_const_args)
  |         ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.ROUzTbiGr8Hi/rustc_testrunner_tmpdir_reporting.GaMdaKkEqCKw/mvce.rs:4:19
  |
4 | static X: T = T();
  |                   ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.ROUzTbiGr8Hi/rustc_testrunner_tmpdir_reporting.GaMdaKkEqCKw/mvce.rs`

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
 --> /tmp/icemaker_global_tempdir.ROUzTbiGr8Hi/rustc_testrunner_tmpdir_reporting.GaMdaKkEqCKw/mvce.rs:4:15
  |
4 | static X: T = T();
  |               ^-- argument #1 is missing
  |
note: tuple struct defined here
 --> /tmp/icemaker_global_tempdir.ROUzTbiGr8Hi/rustc_testrunner_tmpdir_reporting.GaMdaKkEqCKw/mvce.rs:2:8
  |
2 | struct T([isize; N]);
  |        ^
help: provide the argument
  |
4 | static X: T = T(/* value */);
  |                 +++++++++++

error: internal compiler error: compiler/rustc_ty_utils/src/layout.rs:173:13: layout_of: unexpected const: {const error}


thread 'rustc' panicked at compiler/rustc_ty_utils/src/layout.rs:173:13:
Box<dyn Any>
stack backtrace:
   0:     0x77fdd11dad94 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h38d103f25b5fc9da
   1:     0x77fdd1a057e2 - core::fmt::write::h51e5c982d87d838d
   2:     0x77fdd2cd4511 - std::io::Write::write_fmt::h24e7c9ef42bcecab
   3:     0x77fdd11dabf2 - std::sys::backtrace::BacktraceLock::print::h2f36236a0c89f5ad
   4:     0x77fdd11dd4d2 - std::panicking::default_hook::{{closure}}::hfa3a01d30bf38a16
   5:     0x77fdd11dd0c4 - std::panicking::default_hook::h73a43ec84dfb2d2e
   6:     0x77fdd032bdd7 - std[5b59e6f68f39e4a3]::panicking::update_hook::<alloc[a5cfa563521ef073]::boxed::Box<rustc_driver_impl[3a7877a37badcc56]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x77fdd11ddd43 - std::panicking::rust_panic_with_hook::h7086c047409dd55a
   8:     0x77fdd03683b1 - std[5b59e6f68f39e4a3]::panicking::begin_panic::<rustc_errors[e91cd7d082a11be2]::ExplicitBug>::{closure#0}
   9:     0x77fdd035c7c6 - std[5b59e6f68f39e4a3]::sys::backtrace::__rust_end_short_backtrace::<std[5b59e6f68f39e4a3]::panicking::begin_panic<rustc_errors[e91cd7d082a11be2]::ExplicitBug>::{closure#0}, !>
  10:     0x77fdd035c5a7 - std[5b59e6f68f39e4a3]::panicking::begin_panic::<rustc_errors[e91cd7d082a11be2]::ExplicitBug>
  11:     0x77fdd0371ec1 - <rustc_errors[e91cd7d082a11be2]::diagnostic::BugAbort as rustc_errors[e91cd7d082a11be2]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x77fdd094d656 - rustc_middle[20fb34f80dd5af75]::util::bug::opt_span_bug_fmt::<rustc_span[c14b644df6d3ab3c]::span_encoding::Span>::{closure#0}
  13:     0x77fdd0934f7a - rustc_middle[20fb34f80dd5af75]::ty::context::tls::with_opt::<rustc_middle[20fb34f80dd5af75]::util::bug::opt_span_bug_fmt<rustc_span[c14b644df6d3ab3c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x77fdd0934deb - rustc_middle[20fb34f80dd5af75]::ty::context::tls::with_context_opt::<rustc_middle[20fb34f80dd5af75]::ty::context::tls::with_opt<rustc_middle[20fb34f80dd5af75]::util::bug::opt_span_bug_fmt<rustc_span[c14b644df6d3ab3c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x77fdced45b50 - rustc_middle[20fb34f80dd5af75]::util::bug::bug_fmt
  16:     0x77fdd326f432 - rustc_ty_utils[3cda2ba246e4c872]::layout::extract_const_value.cold
  17:     0x77fdd2087928 - rustc_ty_utils[3cda2ba246e4c872]::layout::layout_of_uncached
  18:     0x77fdd207b74e - rustc_ty_utils[3cda2ba246e4c872]::layout::layout_of
  19:     0x77fdd207b6aa - rustc_query_impl[d10ddfe12c3a8e74]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10ddfe12c3a8e74]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 16usize]>>
  20:     0x77fdd207a64d - rustc_query_system[3033f91d22641c6f]::query::plumbing::try_execute_query::<rustc_query_impl[d10ddfe12c3a8e74]::DynamicConfig<rustc_query_system[3033f91d22641c6f]::query::caches::DefaultCache<rustc_middle[20fb34f80dd5af75]::ty::PseudoCanonicalInput<rustc_middle[20fb34f80dd5af75]::ty::Ty>, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[d10ddfe12c3a8e74]::plumbing::QueryCtxt, false>
  21:     0x77fdd207a264 - rustc_query_impl[d10ddfe12c3a8e74]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  22:     0x77fdd2c16a6f - rustc_middle[20fb34f80dd5af75]::query::plumbing::query_get_at::<rustc_query_system[3033f91d22641c6f]::query::caches::DefaultCache<rustc_middle[20fb34f80dd5af75]::ty::PseudoCanonicalInput<rustc_middle[20fb34f80dd5af75]::ty::Ty>, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 16usize]>>>
  23:     0x77fdd2c1668c - rustc_hir_analysis[dfda97e7ebe3f086]::check::check::check_static_inhabited
  24:     0x77fdd22216a0 - rustc_hir_analysis[dfda97e7ebe3f086]::check::check::check_item_type
  25:     0x77fdd2217f55 - rustc_hir_analysis[dfda97e7ebe3f086]::check::wfcheck::check_well_formed
  26:     0x77fdd221690d - rustc_query_impl[d10ddfe12c3a8e74]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10ddfe12c3a8e74]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 1usize]>>
  27:     0x77fdd22163c4 - rustc_query_system[3033f91d22641c6f]::query::plumbing::try_execute_query::<rustc_query_impl[d10ddfe12c3a8e74]::DynamicConfig<rustc_data_structures[b42f330dfa9d8410]::vec_cache::VecCache<rustc_span[c14b644df6d3ab3c]::def_id::LocalDefId, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[3033f91d22641c6f]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d10ddfe12c3a8e74]::plumbing::QueryCtxt, false>
  28:     0x77fdd2215e7f - rustc_query_impl[d10ddfe12c3a8e74]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  29:     0x77fdd221369d - rustc_hir_analysis[dfda97e7ebe3f086]::check::wfcheck::check_mod_type_wf
  30:     0x77fdd221349f - rustc_query_impl[d10ddfe12c3a8e74]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10ddfe12c3a8e74]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 1usize]>>
  31:     0x77fdd2a34556 - rustc_query_system[3033f91d22641c6f]::query::plumbing::try_execute_query::<rustc_query_impl[d10ddfe12c3a8e74]::DynamicConfig<rustc_query_system[3033f91d22641c6f]::query::caches::DefaultCache<rustc_span[c14b644df6d3ab3c]::def_id::LocalModDefId, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d10ddfe12c3a8e74]::plumbing::QueryCtxt, false>
  32:     0x77fdd2a342ff - rustc_query_impl[d10ddfe12c3a8e74]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  33:     0x77fdd20a608f - rustc_hir_analysis[dfda97e7ebe3f086]::check_crate
  34:     0x77fdd209fd9c - rustc_interface[2148282fb0834f58]::passes::run_required_analyses
  35:     0x77fdd28feefa - rustc_interface[2148282fb0834f58]::passes::analysis
  36:     0x77fdd28feed9 - rustc_query_impl[d10ddfe12c3a8e74]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d10ddfe12c3a8e74]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 0usize]>>
  37:     0x77fdd2a5290b - rustc_query_system[3033f91d22641c6f]::query::plumbing::try_execute_query::<rustc_query_impl[d10ddfe12c3a8e74]::DynamicConfig<rustc_query_system[3033f91d22641c6f]::query::caches::SingleCache<rustc_middle[20fb34f80dd5af75]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d10ddfe12c3a8e74]::plumbing::QueryCtxt, false>
  38:     0x77fdd2a525f9 - rustc_query_impl[d10ddfe12c3a8e74]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x77fdd2a79afd - rustc_interface[2148282fb0834f58]::passes::create_and_enter_global_ctxt::<core[436ac50667b45076]::option::Option<rustc_interface[2148282fb0834f58]::queries::Linker>, rustc_driver_impl[3a7877a37badcc56]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  40:     0x77fdd2af19e0 - rustc_interface[2148282fb0834f58]::interface::run_compiler::<(), rustc_driver_impl[3a7877a37badcc56]::run_compiler::{closure#0}>::{closure#1}
  41:     0x77fdd2920608 - std[5b59e6f68f39e4a3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2148282fb0834f58]::util::run_in_thread_with_globals<rustc_interface[2148282fb0834f58]::util::run_in_thread_pool_with_globals<rustc_interface[2148282fb0834f58]::interface::run_compiler<(), rustc_driver_impl[3a7877a37badcc56]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  42:     0x77fdd2920ef4 - <<std[5b59e6f68f39e4a3]::thread::Builder>::spawn_unchecked_<rustc_interface[2148282fb0834f58]::util::run_in_thread_with_globals<rustc_interface[2148282fb0834f58]::util::run_in_thread_pool_with_globals<rustc_interface[2148282fb0834f58]::interface::run_compiler<(), rustc_driver_impl[3a7877a37badcc56]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[436ac50667b45076]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x77fdd29222f7 - std::sys::pal::unix::thread::Thread::new::thread_start::hbb5e0f14d5ca8b98
  44:     0x77fdccaa370a - <unknown>
  45:     0x77fdccb27aac - <unknown>
  46:                0x0 - <unknown>

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.87.0-nightly (fd17deacc 2025-03-04) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(min_generic_const_args) -Z dump-mir-dir=dir

query stack during panic:
#0 [layout_of] computing layout of `T`
#1 [check_well_formed] checking that `X` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0061, E0425, E0601, E0658.
For more information about an error, try `rustc --explain E0061`.

@rustbot label +F-min_generic_const_args

Activity

  1. added
    C-bug
    I-ICE
    T-compiler
    on Mar 4, 2025
  2. added
    needs-triage
    F-gca_min_const_items
    on Mar 4, 2025
  3. matthiaskrgr commented on Mar 4, 2025

    @matthiaskrgr
    MemberAuthor

    bisects to #137852

  4. matthiaskrgr commented on Mar 8, 2025

    @matthiaskrgr
    MemberAuthor

    without features:

    #[repr(simd)]
    struct a<const b : [c; 3]>([;; ""]);
    #[derive(Copy, Clone)]
    struct a<const b : [c; 3]>;
  5. added
    S-bug-has-test
    on Mar 9, 2025
  6. removed
    needs-triage
    on Apr 10, 2025
  7. added 2 commits that reference this issue on Nov 16, 2026
    d3d1ff4
    ac30f1d
  8. added a commit that references this issue on Nov 16, 2026
    dbeeb95
  9. added a commit that references this issue on Nov 17, 2026
    752b781
  10. added a commit that references this issue on Nov 23, 2026
    cc5b297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugF-gca_min_const_itemsI-ICES-bug-has-testT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions