Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion kani-compiler/src/kani_middle/stubbing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ fn generic_args_len_without_self(args: &GenericArgs) -> usize {
return len;
}
let has_self = args.0.iter().any(|arg| {
if let TyKind::Param(param_ty) = arg.expect_ty().kind() {
if let Some(ty) = arg.ty()
&& let TyKind::Param(param_ty) = ty.kind()
{
param_ty.name == "Self"
} else {
false
Expand Down
1 change: 1 addition & 0 deletions tests/expected/stubbing-const-generics/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION:- SUCCESSFUL
28 changes: 28 additions & 0 deletions tests/expected/stubbing-const-generics/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Z stubbing
//! Check that Kani supports stubbing methods for structs with const generics.
//! This was previously crashing:
//! https://github.com/model-checking/kani/issues/4322

struct Foo<const C: usize> {
_a: [i32; C],
x: bool,
}

impl<const C: usize> Foo<C> {
fn foo(&self) -> bool {
self.x
}
}

pub fn bar<const C: usize>(x: &Foo<C>) -> bool {
false
}

#[kani::proof]
#[kani::stub(Foo::foo, bar)]
fn main() {
let f = Foo { _a: [1, 2, 3], x: true };
assert!(!f.foo());
}
Loading