Skip to content

[ICE]: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(ValidationError encountered 0, but expected something greater or equal to 1 #155753

Description

@matthiaskrgr

Code

//@ compile-flags -Zmir-opt-level=3  -Clink-dead-code -Zvalidate-mir -Zextra-const-ub-checks  --emit=mir
use std::mem::ManuallyDrop;
use std::ptr;
struct BitVec<T> {
    pointer: ptr::NonNull<T>,
    capacity: usize,
}
impl<T> BitVec<T> {
    fn with_vec<F, R>(self, func: F) -> R
    where
        F: FnOnce(&ManuallyDrop<Vec<T>>) -> R,
    {
        let cap = self.capacity;
        let elts = 0;
        let vec = ManuallyDrop::new(unsafe { Vec::from_raw_parts(ptr::null_mut(), elts, cap) });
        let out = func(&vec);
        out
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.97.0-nightly (36ba2c771 2026-04-23)
binary: rustc
commit-hash: 36ba2c7712052d731a7082d0eba5ed3d9d56c133
commit-date: 2026-04-23
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Error output

<output>
Backtrace

warning: struct `BitVec` is never constructed
 --> code.rs:3:8
  |
3 | struct BitVec<T> {
  |        ^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: method `with_vec` is never used
 --> code.rs:8:8
  |
7 | impl<T> BitVec<T> {
  | ----------------- method in this implementation
8 |     fn with_vec<F, R>(self, func: F) -> R
  |        ^^^^^^^^


thread 'rustc' (971639) panicked at /rustc-dev/36ba2c7712052d731a7082d0eba5ed3d9d56c133/compiler/rustc_const_eval/src/util/check_validity_requirement.rs:201:41:
called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(ValidationError { orig_ty: pattern_type!(*const u8 is !null), path: None, msg: "encountered 0, but expected something greater or equal to 1", ptr_bytes_warning: false }), backtrace: InterpErrorBacktrace { backtrace: None } })
stack backtrace:
   0:     0x7f639141e9db - <<std[75ea15d2214b0ed8]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[2481842aaaac4afd]::fmt::Display>::fmt
   1:     0x7f6391a2d408 - core[2481842aaaac4afd]::fmt::write
   2:     0x7f6391435986 - <std[75ea15d2214b0ed8]::sys::stdio::unix::Stderr as std[75ea15d2214b0ed8]::io::Write>::write_fmt
   3:     0x7f63913f4c58 - std[75ea15d2214b0ed8]::panicking::default_hook::{closure#0}
   4:     0x7f6391412043 - std[75ea15d2214b0ed8]::panicking::default_hook
   5:     0x7f63903d301c - std[75ea15d2214b0ed8]::panicking::update_hook::<alloc[38765da0c132a06f]::boxed::Box<rustc_driver_impl[7a2168e1d29e28dc]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f6391412322 - std[75ea15d2214b0ed8]::panicking::panic_with_hook
   7:     0x7f63913f4d18 - std[75ea15d2214b0ed8]::panicking::panic_handler::{closure#0}
   8:     0x7f63913eba59 - std[75ea15d2214b0ed8]::sys::backtrace::__rust_end_short_backtrace::<std[75ea15d2214b0ed8]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f63913f677d - __rustc[8f3dd88aee2b0d44]::rust_begin_unwind
  10:     0x7f638e02569c - core[2481842aaaac4afd]::panicking::panic_fmt
  11:     0x7f638db5ee02 - core[2481842aaaac4afd]::result::unwrap_failed
  12:     0x7f6390350e71 - rustc_const_eval[b6a1f833c92620e1]::util::check_validity_requirement::validate_scalar_in_layout
  13:     0x7f6390865296 - <rustc_const_eval[b6a1f833c92620e1]::provide::{closure#3} as core[2481842aaaac4afd]::ops::function::FnOnce<(rustc_middle[c570919ef227af48]::ty::context::TyCtxt, rustc_middle[c570919ef227af48]::ty::consts::int::ScalarInt, rustc_middle[c570919ef227af48]::ty::Ty)>>::call_once
  14:     0x7f6390aa48b3 - <rustc_middle[c570919ef227af48]::ty::print::pretty::FmtPrinter as rustc_middle[c570919ef227af48]::ty::print::pretty::PrettyPrinter>::pretty_print_const_scalar_int
  15:     0x7f6392e913a6 - rustc_middle[c570919ef227af48]::mir::pretty::pretty_print_const_value_tcx
  16:     0x7f6392e91b8d - rustc_middle[c570919ef227af48]::mir::pretty::pretty_print_const_value_tcx
  17:     0x7f6392e90e00 - <rustc_middle[c570919ef227af48]::mir::consts::Const as core[2481842aaaac4afd]::fmt::Display>::fmt
  18:     0x7f6391a2d408 - core[2481842aaaac4afd]::fmt::write
  19:     0x7f6390a62b57 - <&alloc[38765da0c132a06f]::boxed::Box<rustc_middle[c570919ef227af48]::mir::syntax::ConstOperand> as core[2481842aaaac4afd]::fmt::Debug>::fmt
  20:     0x7f6391a2d408 - core[2481842aaaac4afd]::fmt::write
  21:     0x7f6390a9087e - <rustc_middle[c570919ef227af48]::mir::syntax::Operand as core[2481842aaaac4afd]::fmt::Debug>::fmt
  22:     0x7f638fc7e3cc - <core[2481842aaaac4afd]::fmt::builders::DebugStruct>::field
  23:     0x7f63909fc4c2 - rustc_middle[c570919ef227af48]::ty::context::tls::with::<<rustc_middle[c570919ef227af48]::mir::syntax::Rvalue as core[2481842aaaac4afd]::fmt::Debug>::fmt::{closure#3}, core[2481842aaaac4afd]::result::Result<(), core[2481842aaaac4afd]::fmt::Error>>
  24:     0x7f6390a8e316 - <rustc_middle[c570919ef227af48]::mir::syntax::Rvalue as core[2481842aaaac4afd]::fmt::Debug>::fmt
  25:     0x7f6391a2d408 - core[2481842aaaac4afd]::fmt::write
  26:     0x7f6390a777ed - <rustc_middle[c570919ef227af48]::mir::syntax::StatementKind as core[2481842aaaac4afd]::fmt::Debug>::fmt
  27:     0x7f6391a2d408 - core[2481842aaaac4afd]::fmt::write
  28:     0x7f6391a2d2d5 - alloc[38765da0c132a06f]::fmt::format::format_inner
  29:     0x7f6390a20840 - <rustc_middle[c570919ef227af48]::mir::pretty::MirWriter>::write_mir_fn
  30:     0x7f6390a0d09b - rustc_middle[c570919ef227af48]::mir::pretty::write_mir_pretty::{closure#0}
  31:     0x7f6390a423d9 - rustc_middle[c570919ef227af48]::mir::pretty::write_mir_pretty
  32:     0x7f638f704c94 - rustc_mir_transform[117acae470dacc9e]::dump_mir::emit_mir
  33:     0x7f6392b5c716 - rustc_interface[27fd4870d2d649e5]::interface::run_compiler::<(), rustc_driver_impl[7a2168e1d29e28dc]::run_compiler::{closure#0}>::{closure#1}
  34:     0x7f6392b2c004 - std[75ea15d2214b0ed8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[27fd4870d2d649e5]::util::run_in_thread_with_globals<rustc_interface[27fd4870d2d649e5]::util::run_in_thread_pool_with_globals<rustc_interface[27fd4870d2d649e5]::interface::run_compiler<(), rustc_driver_impl[7a2168e1d29e28dc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  35:     0x7f6392b2c6ed - <std[75ea15d2214b0ed8]::thread::lifecycle::spawn_unchecked<rustc_interface[27fd4870d2d649e5]::util::run_in_thread_with_globals<rustc_interface[27fd4870d2d649e5]::util::run_in_thread_pool_with_globals<rustc_interface[27fd4870d2d649e5]::interface::run_compiler<(), rustc_driver_impl[7a2168e1d29e28dc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[2481842aaaac4afd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7f6392b2d56c - <std[75ea15d2214b0ed8]::sys::thread::unix::Thread>::new::thread_start
  37:     0x7f638c6a597a - <unknown>
  38:     0x7f638c7292bc - <unknown>
  39:                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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/matthias/vcs/github/CRED/rustc-ice-2026-04-24T20_15_57-971629.txt` to your bug report

note: rustc 1.97.0-nightly (36ba2c771 2026-04-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 -C link-dead-code -Z validate-mir -Z extra-const-ub-checks

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions