Repository navigation
Description
I tried this code:
trait Storage {
type Buffer: ?Sized;
}
struct Array<const N: usize>;
impl<const N: usize> Storage for Array<N> {
type Buffer = [(); N];
}
struct Slice;
impl Storage for Slice {
type Buffer = [()];
}
struct Wrap<S: Storage> {
_b: S::Buffer,
}
fn coerce<const N: usize>(this: &Wrap<Array<N>>) -> &Wrap<Slice>
where
Array<N>: Storage,
{
coerce_again(this)
}
fn coerce_again<const N: usize>(this: &Wrap<Array<N>>) -> &Wrap<Slice> {
this
}
fn main() {
let inner: Wrap<Array<1>> = Wrap { _b: [(); 1] };
let _: &Wrap<Slice> = coerce(&inner);
}using the following command line invocation:
cargo kani autoharness -Z autoharness
with Kani version:
Kani Rust Verifier 0.68.0 (cargo plugin)
CBMC 6.11.0
I expected to see this happen: explanation
Instead, this happened: explanation
Kani Rust Verifier 0.68.0 (cargo plugin)
CBMC 6.11.0
Compiling cr v0.1.0 (/tmp/kan/cr)
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: internal compiler error: Kani unexpectedly panicked at panicked at cprover_bindings/src/goto_program/expr.rs:972:9:
Error in struct_expr; must be given a struct_tag.
Pointer { typ: StructTag("tag-_136078986413824118984277104791759892003") }
{"data": Expr { value: Typecast(Expr { value: Symbol { identifier: "_RINvCs7tln7OEKTMa_2cr12coerce_againKj2_EB2_::1::var_1::this" }, typ: Pointer { typ: StructTag("tag-_92219347093390180359995506357870376475") }, location: None, size_of_annotation: None }), typ: Pointer { typ: StructTag("tag-_136078986413824118984277104791759892003") }, location: None, size_of_annotation: None }, "len": Expr { value: IntConstant(2), typ: CInteger(SizeT), location: None, size_of_annotation: None }}.
thread 'rustc' (1561375) panicked at cprover_bindings/src/goto_program/expr.rs:972:9:
Error in struct_expr; must be given a struct_tag.
Pointer { typ: StructTag("tag-_136078986413824118984277104791759892003") }
{"data": Expr { value: Typecast(Expr { value: Symbol { identifier: "_RINvCs7tln7OEKTMa_2cr12coerce_againKj2_EB2_::1::var_1::this" }, typ: Pointer { typ: StructTag("tag-_92219347093390180359995506357870376475") }, location: None, size_of_annotation: None }), typ: Pointer { typ: StructTag("tag-_136078986413824118984277104791759892003") }, location: None, size_of_annotation: None }, "len": Expr { value: IntConstant(2), typ: CInteger(SizeT), location: None, size_of_annotation: None }}
stack backtrace:
0: __rustc::rust_begin_unwind
1: core::panicking::panic_fmt
2: <cprover_bindings::goto_program::expr::Expr>::struct_expr
3: kani_compiler::codegen_cprover_gotoc::utils::utils::slice_fat_ptr
4: <kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_pointer_cast
5: <kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_rvalue_stable
6: <kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_statement
7: <kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::codegen_function
8: <std::thread::local::LocalKey<core::cell::RefCell<(core::option::Option<alloc::boxed::Box<dyn core::ops::function::Fn<(), Output = alloc::string::String>>>, core::option::Option<cprover_bindings::goto_program::location::Location>)>>>::with::<<kani_compiler::codegen_cprover_gotoc::context::goto_ctx::GotocCtx>::call_with_panic_debug_info<rustc_public::mir::mono::InstanceDef, <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend>::codegen_items::{closure#4}::{closure#4}, <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend>::codegen_items::{closure#4}::{closure#5}>::{closure#0}, ()>
9: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend>::codegen_items
10: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::{closure#0}
11: 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>>
12: 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>>
13: <kani_compiler::codegen_cprover_gotoc::compiler_interface::GotocCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
14: <rustc_interface::queries::Linker>::codegen_and_build_linker
15: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
16: <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
17: <rustc_thread_pool::registry::WorkerThread>::wait_or_steal_until_cold
18: <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] current codegen item: codegen_function: cr::coerce_again::<2>
_RINvCs7tln7OEKTMa_2cr12coerce_againKj2_EB2_
[Kani] current codegen location: Loc { file: "src/main.rs", function: None, start_line: 26, start_col: Some(1), end_line: 26, end_col: Some(71), pragmas: [] }
error: could not compile `cr` (bin "cr"); 1 warning emitted
Caused by:
process didn't exit successfully: `/home/matthias/.kani/kani-0.68.0/bin/kani-compiler --crate-name cr --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=317 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=070b91841e1a0e8b --out-dir /tmp/kan/cr/target/kani/x86_64-unknown-linux-gnu/debug/build/cr/ef7828976597afcb/out --target x86_64-unknown-linux-gnu -C incremental=/tmp/kan/cr/target/kani/x86_64-unknown-linux-gnu/debug/incremental -L dependency=/tmp/kan/cr/target/kani/debug/build/cr/ef7828976597afcb/out '-Cllvm-args=--reachability=all_fns --log-level=warn --assertion-reach-checks --enable-stubbing -Z autoharness -Z function-contracts -Z loop-contracts' -C overflow-checks=on -Z unstable-options -Z trim-diagnostic-paths=no -Z human_readable_cgu_names -Z always-encode-mir --cfg=kani -Z 'crate-attr=feature(register_tool)' -Z 'crate-attr=register_tool(kanitool)' --force-warn unstable_features --sysroot /home/matthias/.kani/kani-0.68.0 -L /home/matthias/.kani/kani-0.68.0/lib --extern 'force:kani' --extern 'noprelude,nounused:std=/home/matthias/.kani/kani-0.68.0/lib/libstd.rlib' -Ctarget-cpu=native -Zthreads=16 -C panic=abort -C symbol-mangling-version=v0 -Z panic_abort_tests=yes -Z mir-enable-passes=-RemoveStorageMarkers '--check-cfg=cfg(kani)' -Clinker=echo --kani-compiler -Cllvm-args=--check-version=0.68.0` (exit status: 101)
error: Failed to compile `cr` due to an internal compiler error.: error: internal compiler error: Kani unexpectedly panicked at panicked at cprover_bindings/src/goto_program/expr.rs:972:9:
Error in struct_expr; must be given a struct_tag.
Pointer { typ: StructTag("tag-_136078986413824118984277104791759892003") }
{"data": Expr { value: Typecast(Expr { value: Symbol { identifier: "_RINvCs7tln7OEKTMa_2cr12coerce_againKj2_EB2_::1::var_1::this" }, typ: Pointer { typ: StructTag("tag-_92219347093390180359995506357870376475") }, location: None, size_of_annotation: None }), typ: Pointer { typ: StructTag("tag-_136078986413824118984277104791759892003") }, location: None, size_of_annotation: None }, "len": Expr { value: IntConstant(2), typ: CInteger(SizeT), location: None, size_of_annotation: None }}.
Metadata
Metadata
Assignees
Labels
[C] BugThis is a bug. Something isn't working.
Activity
feliperodri commentedon Sep 20, 2026
@matthiaskrgr Thank you for reporting this issue and for giving autoharness a try. I'm suggesting a fix for it here: #4815 with more details about the issue.
matthiaskrgr commentedon Sep 20, 2026
bit smaller:
feliperodri commentedon Sep 20, 2026
@matthiaskrgr #4815 also works on the smaller example.
Normalize type projections when computing pointer metadata
Normalize type projections when computing pointer metadata (model-che…