Skip to content

ICE: Normalization of 'ty::ConstKind::Expr' is unimplemented #132960

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --crate-type=lib
#![feature(unsized_const_params)]
#![feature(adt_const_params, const_ptr_read, generic_const_exprs)]

use std::mem::ManuallyDrop;

const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
where
    [(); A.len()]:,
    [(); B.len()]:,
    [(); A.len() + B.len()]:,
{
    #[repr(C)]
    struct ConcatJoin<const N: usize, const M: usize> {
        left: [u8; N],
        right: [u8; M],
    }

    #[repr(C)]
    union ConcatJoiner<const N: usize, const M: usize>
    where
        [(); N + M]:,
    {
        whole: ManuallyDrop<[u8; N + M]>,
        split: ManuallyDrop<ConcatJoin<N, M>>,
    }

    const fn concat_arr<const M: usize, const N: usize>(a: [u8; M], b: [u8; N]) -> [u8; M + N] {
        unsafe {
            let joiner = ConcatJoiner {
                split: ManuallyDrop::new(ConcatJoin { left: a, right: b }),
            };
            let join = joiner.whole;
            ManuallyDrop::into_inner(join)
        }
    }

    struct Inner<const A: &'static str, const B: &'static str>;
    impl<const A: &'static str, const B: &'static str> Inner<A, B>
    where
        [(); A.len()]:,
        [(); B.len()]:,
        [(); A.len() + B.len()]:,
    {
        const ABSTR: &'static str = unsafe {
            std::str::from_utf8_unchecked(&concat_arr(
                A.as_ptr().cast().read(),
                B.as_ptr().cast().read(),
            ))
        };
    }

    Inner::<A, B>::ABSTR
}

const FOO: &str = "foo";
const BAR: &str = "bar";
const FOOBAR: &str = concat_strs::<FOO, BAR>();
original code

original:

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

use std::mem::ManuallyDrop;

const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
where
    [(); A.len()]:,
    [(); B.len()]:,
    [(); A.len() + B.len()]:,
{
    #[repr(C)]
    struct ConcatJoin<const N: usize, const M: usize> {
        left: [u8; N],
        right: [u8; M],
    }

    #[repr(C)]
    union ConcatJoiner<const N: usize, const M: usize>
    where
        [(); N + M]:,
    {
        whole: ManuallyDrop<[u8; N + M]>,
        split: ManuallyDrop<ConcatJoin<N, M>>,
    }

    const fn concat_arr<const M: usize, const N: usize>(a: [u8; M], b: [u8; N]) -> [u8; M + N]
    where
        [(); M + N]:,
    {
        unsafe {
            let joiner = ConcatJoiner {
                split: ManuallyDrop::new(ConcatJoin { left: a, right: b }),
            };
            let join = joiner.whole;
            ManuallyDrop::into_inner(join)
        }
    }

    struct Inner<const A: &'static str, const B: &'static str>;
    impl<const A: &'static str, const B: &'static str> Inner<A, B>
    where
        [(); A.len()]:,
        [(); B.len()]:,
        [(); A.len() + B.len()]:,
    {
        const ABSTR: &'static str = unsafe {
            std::str::from_utf8_unchecked(&concat_arr(
                A.as_ptr().cast::<[u8; A.len()]>().read(),
                B.as_ptr().cast::<[u8; B.len()]>().read(),
            ))
        };
    }

    Inner::<A, B>::ABSTR
}

const FOO: &str = "foo";
const BAR: &str = "bar";
const FOOBAR: &str = concat_strs::<FOO, BAR>();

Version information

rustc 1.84.0-nightly (6503543d1 2024-11-12)
binary: rustc
commit-hash: 6503543d11583d1686d4989847b2afbec8d9fdba
commit-date: 2024-11-12
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(unsized_const_params) --crate-type=lib

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.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:1:46
  |
1 | #![feature(adt_const_params, const_ptr_read, generic_const_exprs)]
  |                                              ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

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

warning: the feature `const_ptr_read` has been stable since 1.71.0 and no longer requires an attribute to enable
 --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:1:30
  |
1 | #![feature(adt_const_params, const_ptr_read, generic_const_exprs)]
  |                              ^^^^^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default

warning: type annotations needed
  --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:45:35
   |
45 |                 A.as_ptr().cast().read(),
   |                                   ^^^^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
   = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
   = note: `#[warn(tyvar_behind_raw_pointer)]` on by default

warning: type annotations needed
  --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:46:35
   |
46 |                 B.as_ptr().cast().read(),
   |                                   ^^^^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
   = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>

warning: function `concat_strs` is never used
 --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:5:10
  |
5 | const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
  |          ^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: associated constant `ABSTR` is never used
  --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:43:15
   |
37 | /     impl<const A: &'static str, const B: &'static str> Inner<A, B>
38 | |     where
39 | |         [(); A.len()]:,
40 | |         [(); B.len()]:,
41 | |         [(); A.len() + B.len()]:,
   | |_________________________________- associated constant in this implementation
42 |       {
43 |           const ABSTR: &'static str = unsafe {
   |                 ^^^^^

warning: constant `FOO` is never used
  --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:54:7
   |
54 | const FOO: &str = "foo";
   |       ^^^

warning: constant `BAR` is never used
  --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:55:7
   |
55 | const BAR: &str = "bar";
   |       ^^^

warning: constant `FOOBAR` is never used
  --> /tmp/icemaker_global_tempdir.M7QGlwHPHRjj/rustc_testrunner_tmpdir_reporting.Pgzdb9IPCHkV/mvce.rs:56:7
   |
56 | const FOOBAR: &str = concat_strs::<FOO, BAR>();
   |       ^^^^^^

warning: 10 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: Unevaluated `ty::Const` in MIR body
  |
  = note: delayed at /rustc/6503543d11583d1686d4989847b2afbec8d9fdba/compiler/rustc_middle/src/mir/consts.rs:328:40 - disabled backtrace

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.84.0-nightly (6503543d1 2024-11-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(unsized_const_params) --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@rustbot label +F-adt_const_params +F-const_ptr_read +F-generic_const_exprs +F-unsized_const_params

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`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