Repository navigation
Description
Summary
Since #4820, kani autoharness ICEs on any crate that declares a body-less #[rustc_intrinsic] carrying #[rustc_comptime]. core does, so autoharness over the standard library aborts during codegen:
error: internal compiler error: Kani unexpectedly panicked at panicked at
/rustc-dev/8925ea358a0f265ca61026aadc7ecc506c545cbe/compiler/rustc_mir_transform/src/lib.rs:797:24:
do not use `optimized_mir` for constants: Const { allow_const_fn_promotion: false }
This blocks model-checking/verify-rust-std#687, the bump to nightly-2026-08-21. #4820 removed the E0080 abort that previously blocked the same four CI jobs there (Kani List, Kani Metrics, autoharness verification, autoharness-analyzer); this ICE now blocks exactly those four instead.
Minimal reproducer
Eight lines, no const generics involved:
// repro.rs
#![feature(intrinsics, rustc_attrs)]
// Declared exactly as `core::intrinsics::size_of` is on nightly-2026-08-21.
#[rustc_nounwind]
#[rustc_intrinsic]
#[rustc_comptime]
pub fn size_of<T>() -> usize;$ kani autoharness -Z autoharness repro.rs --only-codegen
error: internal compiler error: Kani unexpectedly panicked at panicked at .../rustc_mir_transform/src/lib.rs:797:24:
do not use `optimized_mir` for constants: Const { allow_const_fn_promotion: false }Reproduced on 783e7f7 (current main) with nightly-2026-08-21. Reverting to a pre-#4820 commit makes the same file compile cleanly.
Root cause
has_const_generic_precondition (kani-compiler/src/kani_middle/codegen_units.rs) guards its MIR fetch with is_mir_available, then calls optimized_mir:
if !tcx.is_mir_available(def_id) {
continue;
}
// ...
let body = tcx.optimized_mir(def_id);is_mir_available is not a sufficient guard. rustc's optimized_mir provider asserts the def has no const body context, and for a #[rustc_comptime] intrinsic tcx.hir_body_const_context(..) returns Some(ConstContext::Const { .. }) while is_mir_available is still true. The CTFE MIR for such a def must be fetched with mir_for_ctfe instead.
#[rustc_comptime] is what makes this new: it did not exist on the toolchain #4820 was developed against, which is why the ICE did not show up in the PR's own testing.
I instrumented the loop locally to print the def path and the pusher. The offending def is the seed candidate itself, not a transitive callee — seed == culprit for all nine cases in core:
seed="intrinsics::size_of" culprit="intrinsics::size_of" kind=Fn ctx=Const { allow_const_fn_promotion: false }
seed="intrinsics::align_of" culprit="intrinsics::align_of" kind=Fn ctx=Const { .. }
seed="intrinsics::needs_drop" culprit="intrinsics::needs_drop" kind=Fn ctx=Const { .. }
seed="intrinsics::offset_of" culprit="intrinsics::offset_of" kind=Fn ctx=Const { .. }
seed="intrinsics::field_offset" culprit="intrinsics::field_offset" kind=Fn ctx=Const { .. }
seed="intrinsics::type_id" culprit="intrinsics::type_id" kind=Fn ctx=Const { .. }
seed="intrinsics::type_name" culprit="intrinsics::type_name" kind=Fn ctx=Const { .. }
seed="intrinsics::variant_count" culprit="intrinsics::variant_count" kind=Fn ctx=Const { .. }
seed="any::TypeId::trait_info_of" culprit="any::TypeId::trait_info_of" kind=AssocFn ctx=Const { .. }
So the transitive-search machinery is not implicated; the very first iteration panics on the candidate.
Note on ordering
These candidates are ones autoharness discards anyway. With the panic suppressed, the reproducer reports:
| Crate | Skipped Function | Reason for Skipping |
| lib | size_of::<i32> | The function does not have a body |
So has_const_generic_precondition runs before the existing body check rejects the candidate. Running the const-precondition search after that check would avoid this class of ICE entirely, independently of the optimized_mir guard — which may be the more robust fix.
Suggested fix
Either or both:
- In
has_const_generic_precondition, usemir_for_ctfewhendef_id.as_local()has aConstContext::Const { .. }/ConstContext::Static(_)body context, andoptimized_mirotherwise. Replacing theis_mir_availableguard alone is not enough, since it returnstruefor these defs. - Order the precondition search after the body-availability check in
skip_reason, so body-less candidates never reach it.
A regression test mirroring the reproducer above would pin this: a #[rustc_comptime] intrinsic declaration is a one-line addition to the existing cargo_autoharness_generics script test.
Why this matters for the standard library
verify-rust-std pins Kani by commit and runs autoharness over library/ in CI. With main as of 783e7f7 those jobs cannot complete, so the toolchain bump to nightly-2026-08-21 — and the metrics and autoharness coverage that depend on it — stays blocked. Unlike the E0080 issue (#4794) there is no repo-side workaround: --exclude-pattern selects what is verified, not what is codegen'd, and the panic happens during candidate selection over core.
Activity
Autoharness: skip `#[rustc_comptime]` functions
Fetch a candidate's MIR with the provider that serves its body kind (m…