Skip to content

ICE: assertion failed: layout.is_sized() with feature(adt_const_params) #137582

Open
@cushionbadak

Description

@cushionbadak

Code

#![feature(adt_const_params)]

mod lib {
    pub type Matrix = [&'static u32];

    const EMPTY_MATRIX: Matrix = [[0; 4]; 4];

    pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
        _p: (),
    }

    impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {}
}

fn main() {}
Original Code (Mutant from Fuzzing)

#![feature(adt_const_params, generic_const_exprs)]
#![allow(incomplete_features)]

mod lib {
    const N_ISLANDS: usize = 4;
    const N_BRIDGES: usize = 7;
    const BRIDGES: [(usize, usize); 7] = [(0, 1), (0, 1), (0, 2), (0, 3), (0, 3), (1, 2), (2, 3)];

    pub type Matrix = [&'static u32];

    const EMPTY_MATRIX: Matrix = [[0; N_ISLANDS]; N_ISLANDS];

    const fn build(mut matrix: Matrix, (to, from): (usize, usize)) -> Matrix {
        matrix[to][from] += 1;
        matrix[from][to] += 1;
        matrix
    }

    pub const fn walk(mut matrix: Matrix, from: usize, to: usize) -> Matrix {
        matrix[from][to] -= 1;
        matrix[to][from] -= 1;
        matrix
    }

    const fn to_matrix(bridges: [(usize, usize); N_BRIDGES]) -> Matrix {
        let matrix = EMPTY_MATRIX;

        let matrix = build(matrix, bridges[0]);
        let matrix = build(matrix, bridges[1]);
        let matrix = build(matrix, bridges[2]);
        let matrix = build(matrix, bridges[3]);
        let matrix = build(matrix, bridges[4]);
        let matrix = build(matrix, bridges[5]);
        let matrix = build(matrix, bridges[6]);

        matrix
    }

    const BRIDGE_MATRIX: [[usize; N_ISLANDS]; N_ISLANDS] = to_matrix(BRIDGES);

    pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
        _p: (),
    }

    impl Walk<0, BRIDGE_MATRIX> {
        pub const fn new() -> Self {
            Self { _p: () }
        }
    }

    impl<const CURRENT: usize, const REMAINING: Matrix> Walk<CURRENT, REMAINING> {
        pub fn proceed_to<const NEXT: usize>(
            self,
        ) -> Walk<NEXT, { walk(REMAINING, CURRENT, NEXT) }> {
            B {v1: 22,
                         v2: [23, 24, 25],
                         v3: vec![26, 27, 28],
                         v4: C { f: 29 },
                         v5: Box::new(C { f: 30 }),
                         v6: Some(C { f: 31 })}
        }
    }

    pub struct Trophy {
        _p: (),
    }

    impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {
        pub fn collect_prize(self) -> Trophy {
            Trophy { _p: () }
        }
    }
}

pub use lib::{Trophy, Walk};

fn main() {
    let _: Result<(i32, i8), ()> = Ok(1, 2);
    //~^ ERROR enum variant takes 1 argument but 2 arguments were supplied
    let _: Option<(i32, i8, &'static str)> = Some(1, 2, "hi");
    //~^ ERROR enum variant takes 1 argument but 3 arguments were supplied
    let _: Option<()> = Some();
    //~^ ERROR enum variant takes 1 argument but 0 arguments were supplied

    let _: Option<(i32,)> = Some(3);
    //~^ ERROR mismatched types

    let _: Option<(i32,)> = Some((3));
    //~^ ERROR mismatched types

    two_ints(1, 2); //~ ERROR function takes 1 argument

    with_generic(3, 4); //~ ERROR function takes 1 argument
}


// /home/jb/workspace/seeds_250219/fixed/97007.rs

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (617aad8c2 2025-02-24)
binary: rustc
commit-hash: 617aad8c2e8783f6df8e5d1f8bb1e4bcdc70aa7b
commit-date: 2025-02-24
host: x86_64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

error[E0277]: the size for values of type `[&'static u32]` cannot be known at compilation time
 --> ACD1.rs:6:25
  |
6 |     const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
  |                         ^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[&'static u32]`

error[E0308]: mismatched types
 --> ACD1.rs:6:35
  |
6 |     const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
  |                                   ^^^^^^ expected `&u32`, found `[{integer}; 4]`

error[E0308]: mismatched types
 --> ACD1.rs:6:34
  |
6 |     const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
  |                                  ^^^^^^^^^^^ expected `[&u32]`, found `[&u32; 4]`

error[E0741]: `[&'static u32]` can't be used as a const parameter type
 --> ACD1.rs:8:60
  |
8 |     pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
  |                                                            ^^^^^^


thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/eval_queries.rs:49:5:
assertion failed: layout.is_sized()
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/eval_queries.rs:49:5:
assertion failed: layout.is_sized()
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 2 frames ...]
   4: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
   5: rustc_const_eval::const_eval::valtrees::eval_to_valtree
   6: <rustc_const_eval::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>)>>::call_once
      [... omitted 2 frames ...]
   7: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
   8: <rustc_middle::ty::context::TyCtxt>::const_eval_global_id_for_typeck
   9: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  10: rustc_trait_selection::traits::try_evaluate_const
  11: <rustc_trait_selection::traits::normalize::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
  12: <&rustc_middle::ty::list::RawList<(), rustc_middle::ty::generic_args::GenericArg> as rustc_type_ir::fold::TypeFoldable<rustc_middle::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
  13: <rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::try_super_fold_with::<rustc_trait_selection::traits::normalize::AssocTypeNormalizer>
  14: <rustc_infer::infer::at::At as rustc_trait_selection::traits::normalize::NormalizeExt>::normalize::<rustc_middle::ty::Ty>
  15: <rustc_hir_analysis::check::wfcheck::WfCheckingCtxt>::normalize::<rustc_middle::ty::Ty>
  16: rustc_hir_analysis::check::wfcheck::check_item
  17: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  18: <rustc_middle::hir::ModuleItems>::par_opaques::<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#4}>::{closure#0}
  19: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  20: rustc_hir_analysis::check_crate
  21: rustc_interface::passes::run_required_analyses
  22: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  23: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  24: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/Volumes/T7/workspace/250225 scratch/codes/rustc-ice-2025-02-25T04_07_11-34605.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `lib::<impl at ACD1.rs:12:5: 12:59>::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
#2 [check_well_formed] checking that `lib::<impl at ACD1.rs:12:5: 12:59>` is well-formed
#3 [check_mod_type_wf] checking that types are well-formed in module `lib`
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0277, E0308, E0741.
For more information about an error, try `rustc --explain E0277`.

Note

Similar Issues

I can find three open issues with layout.is_sized() query.

  1. ICE: assertion failed: layout.is_sized() #137186: It points to the same ICE location, but that has different query stack or feature.
  2. ICE: assertion failed: layout.is_sized() with feature(associated_const_equality) #127643: It points to the same ICE location & similar query stack, but requires different feature.
  3. ICE when creating a reference to an (extern?) value of an extern type in a static context #104685: It requires -Zextra-const-ub-checks option to trigger ICE, and has different query stack.

@rustbot label +F-adt_const_params

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions