generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 129
Enable contracts for const generic functions #3726
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7c35a47
Enable contracts for const generic functions
qinheping e73e327
Fix format
qinheping b420502
Merge branch 'main' into issues/3667
qinheping 2a27c9e
Fix typo
qinheping 922574a
Add redef only for contrats check mode
qinheping 7687a4a
Fix format
qinheping cae4a12
Fix test
qinheping 03704fb
Merge branch 'main' into issues/3667
qinheping 0f7351e
Generate redefs only once
qinheping 5791516
Fix format
qinheping 3daad1f
Move redefs to initialization of replace closure
qinheping 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
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
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
2 changes: 2 additions & 0 deletions
2
tests/expected/function-contract/const_generic_function.expected
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,2 @@ | ||
| ** 1 of | ||
| Failed Checks: Check that *dst is assignable |
27 changes: 27 additions & 0 deletions
27
tests/expected/function-contract/const_generic_function.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,27 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| // kani-flags: -Zfunction-contracts | ||
|
|
||
| //! Check that Kani contract can be applied to a constant generic function. | ||
| //! <https://github.com/model-checking/kani/issues/3667> | ||
|
|
||
| struct Foo<T> { | ||
| ptr: *const T, | ||
| } | ||
|
|
||
| impl<T: Sized> Foo<T> { | ||
| #[kani::requires(true)] | ||
| pub const unsafe fn bar(self, v: T) | ||
| where | ||
| T: Sized, | ||
| { | ||
| unsafe { core::ptr::write(self.ptr as *mut T, v) }; | ||
| } | ||
| } | ||
|
|
||
| #[kani::proof_for_contract(Foo::bar)] | ||
| fn check_const_generic_function() { | ||
| let x: u8 = kani::any(); | ||
| let foo: Foo<u8> = Foo { ptr: &x }; | ||
| unsafe { foo.bar(kani::any::<u8>()) }; | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.