-
Notifications
You must be signed in to change notification settings - Fork 172
Resolve multi-candidate methods on impls defined outside the type's module #4778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kasimte
wants to merge
2
commits into
model-checking:main
Choose a base branch
from
kasimte:fix-impl-path-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/kani/FunctionContracts/cross_module_multiple_impls.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| // kani-flags: -Zfunction-contracts | ||
|
|
||
| // Check that Kani can verify contracts on methods where the base type has multiple | ||
| // same-named methods across impl blocks that live OUTSIDE the type's home module. This | ||
| // extends the same-module case in multiple_inherent_impls.rs (c.f. | ||
| // https://github.com/model-checking/kani/issues/3773) to the `<impl path::Type<Args>>` | ||
| // path form def_path_str renders when an impl's module differs from its self type's. | ||
| // One candidate's generic argument is a tuple type, exercising the | ||
| // tuple-vs-trait-object-bound paren distinction in that path's disambiguation; the `D` | ||
| // pair puts a trait object in the argument position, pinning the paren-strip itself | ||
| // (def_path_str renders that candidate as `<impl D<(dyn std::any::Any + 'static)>>`, | ||
| // which must match the bare `dyn` spelling below). | ||
| pub mod ty { | ||
| pub struct S<T>(pub T); | ||
| pub struct D<T: ?Sized>(pub u32, pub Box<T>); | ||
| } | ||
|
|
||
| pub mod ops { | ||
| use crate::ty::{D, S}; | ||
| use std::any::Any; | ||
|
|
||
| impl S<(u32, u64)> { | ||
| #[kani::requires(self.0.0.checked_mul(2).is_some() && self.0.1.checked_mul(2).is_some())] | ||
| pub fn double(self) -> (u32, u64) { | ||
| (self.0.0 * 2, self.0.1 * 2) | ||
| } | ||
| } | ||
|
|
||
| impl S<u64> { | ||
| #[kani::requires(self.0.checked_mul(2).is_some())] | ||
| pub fn double(self) -> u64 { | ||
| self.0 * 2 | ||
| } | ||
| } | ||
|
|
||
| impl D<dyn Any> { | ||
| #[kani::requires(self.0.checked_mul(2).is_some())] | ||
| pub fn double_tag(self) -> u32 { | ||
| self.0 * 2 | ||
| } | ||
| } | ||
|
|
||
| impl D<u32> { | ||
| #[kani::requires(self.0.checked_mul(2).is_some())] | ||
| pub fn double_tag(self) -> u32 { | ||
| self.0 * 2 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| mod verify { | ||
| use crate::ty::{D, S}; | ||
| use std::any::Any; | ||
|
|
||
| #[kani::proof_for_contract(S::<(u32, u64)>::double)] | ||
| fn verify_double_tuple_arg() { | ||
| let x: S<(u32, u64)> = S((2, 3)); | ||
| x.double(); | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(S::<u64>::double)] | ||
| fn verify_double_u64() { | ||
| let x: S<u64> = S(2); | ||
| x.double(); | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(D::<dyn std::any::Any + 'static>::double_tag)] | ||
| fn verify_double_tag_dyn() { | ||
| let x: D<dyn Any> = D(2, Box::new(5u32)); | ||
| x.double_tag(); | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(D::<u32>::double_tag)] | ||
| fn verify_double_tag_u32() { | ||
| let x: D<u32> = D(2, Box::new(5u32)); | ||
| x.double_tag(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in f3a28a3: extraction returns
Noneunless the depth-0 close consumes the self type's full generic list, so a truncated extraction is impossible (impl_self_type_fn_ptr_args_decline). For accuracy: through the full pipeline, arrow-bearing candidate paths already fail one stage earlier — the top-level::split leaves them unmatchable — so this is helper-level hardening; either way the outcome is the clean failed-to-resolve described in the body's call-out.