Repository navigation
Description
I tried this code:
struct S<T> { x: [T; !0] }
pub fn f() -> usize {
std::mem::size_of::<S<u8>>()
}
fn main() {
let x = f();
}using the following command line invocation:
RUST_BACKTRACE=1 cargo kani autoharness -Z autoharness
with Kani version:
see below
I expected to see this happen: explanation
Instead, this happened: explanation
Kani Rust Verifier 0.68.0 (cargo plugin)
CBMC 6.11.0
Blocking waiting for file lock on package cache
Compiling cr v0.1.0 (/tmp/kan/cr)
warning: unused variable: `x`
--> src/main.rs:8:9
|
8 | let x = f();
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: field `x` is never read
--> src/main.rs:1:15
|
1 | struct S<T> { x: [T; !0] }
| - ^
| |
| field in this struct
|
= note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
warning: use of an unstable feature
--> <crate attribute>:1:12
|
1 | #![feature(register_tool)]
| ^^^^^^^^^^^^^
|
= note: requested on the command line with `--force-warn unstable-features`
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the target architecture
--> /home/runner/.rustup/toolchains/nightly-2026-08-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:1464:24
|
= note: evaluation of `<S<u8> as std::mem::SizedTypeProperties>::SIZE` failed here
thread 'rustc' (1836318) panicked at kani-compiler/src/kani_middle/reachability.rs:402:17:
internal error: entered unreachable code: Instance with polymorphic constant: `ConstOperand { span: Span { id: 96, repr: "/home/runner/.rustup/toolchains/nightly-2026-08-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:383:5: 383:37" }, user_ty: Some(0), const_: MirConst { kind: Unevaluated(UnevaluatedConst { def: ConstDef(DefId { id: 391, name: "std::mem::SizedTypeProperties::SIZE" }), args: GenericArgs([Type(Ty { id: 7, kind: RigidTy(Adt(AdtDef(DefId { id: 392, name: "cr::S" }), GenericArgs([Type(Ty { id: 8, kind: RigidTy(Uint(U8)) })]))) })]), promoted: None }), ty: Ty { id: 0, kind: RigidTy(Uint(Usize)) }, id: MirConstId(3, ThreadLocalIndex) } }`
stack backtrace:
error: internal compiler error: Kani unexpectedly panicked at panicked at kani-compiler/src/kani_middle/reachability.rs:402:17:
internal error: entered unreachable code: Instance with polymorphic constant: `ConstOperand { span: Span { id: 96, repr: "/home/runner/.rustup/toolchains/nightly-2026-08-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:383:5: 383:37" }, user_ty: Some(0), const_: MirConst { kind: Unevaluated(UnevaluatedConst { def: ConstDef(DefId { id: 391, name: "std::mem::SizedTypeProperties::SIZE" }), args: GenericArgs([Type(Ty { id: 7, kind: RigidTy(Adt(AdtDef(DefId { id: 392, name: "cr::S" }), GenericArgs([Type(Ty { id: 8, kind: RigidTy(Uint(U8)) })]))) })]), promoted: None }), ty: Ty { id: 0, kind: RigidTy(Uint(Usize)) }, id: MirConstId(3, ThreadLocalIndex) } }`.
0: __rustc::rust_begin_unwind
1: core::panicking::panic_fmt
2: <kani_compiler::kani_middle::reachability::MonoItemsFnCollector as rustc_public::mir::visit::MirVisitor>::visit_operand
3: <kani_compiler::kani_middle::reachability::MonoItemsCollector>::reachable_items
4: kani_compiler::kani_middle::reachability::collect_reachable_items
5: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend>::codegen_items
6: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::{closure#0}
7: rustc_public::compiler_interface::run::<rustc_public::rustc_internal::run<<kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::{closure#0}, alloc::boxed::Box<dyn core::any::Any>>::{closure#0}, alloc::boxed::Box<dyn core::any::Any>>
8: rustc_public::rustc_internal::run::<<kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::{closure#0}, alloc::boxed::Box<dyn core::any::Any>>
9: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
10: <rustc_interface::queries::Linker>::codegen_and_build_linker
11: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
12: <rustc_thread_pool::job::StackJob<rustc_thread_pool::latch::LatchRef<rustc_thread_pool::latch::LockLatch>, <rustc_thread_pool::registry::Registry>::in_worker_cold<<rustc_thread_pool::thread_pool::ThreadPool>::install<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#5}::{closure#0}::{closure#1}::{closure#0}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> as rustc_thread_pool::job::Job>::execute
13: <rustc_thread_pool::registry::WorkerThread>::wait_or_steal_until_cold
14: <rustc_thread_pool::registry::ThreadBuilder>::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Kani unexpectedly panicked during compilation.
Please file an issue here: https://github.com/model-checking/kani/issues/new?labels=bug&template=bug_report.md
[Kani] no current codegen item.
[Kani] no current codegen location.
error: could not compile `cr` (bin "cr") due to 1 previous error; 3 warnings emitted
error: Failed to compile `cr` due to an internal compiler error.: error: internal compiler error: Kani unexpectedly panicked at panicked at kani-compiler/src/kani_middle/reachability.rs:402:17:
internal error: entered unreachable code: Instance with polymorphic constant: `ConstOperand { span: Span { id: 96, repr: "/home/runner/.rustup/toolchains/nightly-2026-08-21-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:383:5: 383:37" }, user_ty: Some(0), const_: MirConst { kind: Unevaluated(UnevaluatedConst { def: ConstDef(DefId { id: 391, name: "std::mem::SizedTypeProperties::SIZE" }), args: GenericArgs([Type(Ty { id: 7, kind: RigidTy(Adt(AdtDef(DefId { id: 392, name: "cr::S" }), GenericArgs([Type(Ty { id: 8, kind: RigidTy(Uint(U8)) })]))) })]), promoted: None }), ty: Ty { id: 0, kind: RigidTy(Uint(Usize)) }, id: MirConstId(3, ThreadLocalIndex) } }`.
Metadata
Metadata
Assignees
Labels
[C] BugThis is a bug. Something isn't working.
Activity
feliperodri commentedon Sep 25, 2026
Triaged against
main(de756c9, nightly-2026-09-23, Kani 0.68.0). rustc now rejects the reproducer before Kani sees it:error[E0080]: values of the type[u8; usize::MAX]are too big for the target architecture. Checked bothkani code.rsandkani autoharness -Z autoharness code.rs. (The sibling issues #4840 and #4842, where an oversized array reaches Kani's layout query, do still reproduce.)Closing as no longer reproducible — please reopen if you can still hit it on
main.Make the model-checking#4814 regression test able to fail
Add the Cargo project files for the model-checking#4814 regression test
feliperodri commentedon Sep 30, 2026
Correction to my triage comment above: this still reproduces. I tested it as a single file (
kani autoharness), which reports the E0080 without reaching the reachability collector. As a Cargo project, as originally reported,cargo kani autoharness -Z autoharnessstill panics atreachability.rs:402("Instance with polymorphic constant") on currentmain. Reopening; #4818 fixes it, and its regression test is now a Cargo project for exactly this reason.Handle failed constant evaluation gracefully in reachability (model-c…