Repository navigation
Description
I was writing a proof_for_contract harness whose target type carries a const generic argument. Instead of a resolution error, kani-compiler panicked with an internal compiler error.
I tried this code:
// kani-flags: -Zfunction-contracts
struct Buf<const N: usize> {
data: [u8; N],
}
trait Get {
fn get(&self, i: usize) -> u8;
}
impl<const N: usize> Get for Buf<N> {
#[kani::requires(i < N)]
fn get(&self, i: usize) -> u8 {
self.data[i]
}
}
#[cfg(kani)]
mod verify {
use super::*;
#[kani::proof_for_contract(<Buf<4> as Get>::get)]
fn check_get() {
let buf = Buf { data: [kani::any(); 4] };
let i: usize = kani::any();
kani::assume(i < 4);
let _ = buf.get(i);
}
}using the following command line invocation:
kani s.rs -Zfunction-contracts
with Kani version: 0.68.0 (CBMC 6.11.0)
I expected to see this happen: a resolution error saying the const generic argument is not supported, the same way other unsupported paths are reported.
Instead, this happened:
error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:353:13: cannot find `N/#0` in param-env: ParamEnv {
caller_bounds: [],
}
thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:353:13:
Box<dyn Any>
stack backtrace:
3: <rustc_middle::ty::sty::ParamConst>::find_const_ty_from_env
7: rustc_traits::codegen::codegen_select_candidate
8: rustc_ty_utils::instance::resolve_instance_raw
9: <rustc_middle::ty::instance::Instance>::try_resolve
10: <rustc_public::mir::mono::Instance>::resolve
11: kani_compiler::kani_middle::resolve::resolve_in_trait_impl
at ./kani-compiler/src/kani_middle/resolve.rs:496:18
12: kani_compiler::kani_middle::resolve::resolve_fn_path
13: <kani_compiler::kani_middle::attributes::KaniAttributes>::resolve_path
Kani unexpectedly panicked during compilation.
(Absolute path prefixes, the thread id, and backtrace frames outside the relevant ones are elided; the frame numbers, the sty.rs:353 location, and the kani-compiler frames are verbatim.)
The const generic argument in the target path (Buf<4>) is left uninstantiated during path resolution. The free const parameter then reaches instance resolution (resolve_in_trait_impl, resolve.rs:496), where the compiler cannot find it in the param-env.
Related to #4084, which reports a resolution error (not a panic) for a free type parameter in the same resolver.
The real target this blocks is a proof_for_contract on a const-generic standard-library type, for example core::array::IntoIter<T, N>.
Activity