Repository navigation
Make panic and assert const functions - #1590
Conversation
| pub fn check_something() { | ||
| let x: u8 = if kani::any() { 3 } else { 95 }; | ||
| if x > 100 { | ||
| my_const_fn(); |
There was a problem hiding this comment.
This call isn't reachable (x > 100 is always false). The test shows you can use panic! in a const fn but I think you want to also call it, right?
There was a problem hiding this comment.
The impetus for this was definitely a compile-time error, so maybe not
There was a problem hiding this comment.
Correct, I'm intentionally not calling it so that the test passes. As Ted pointed out, compilation currently fails. The purpose of the kani::any() is to make sure the compiler doesn't optimize the function out (so we still have to codegen it).
|
I updated the PR to make |
Description of changes:
Rust allows
panic!,assert!, andassert_eq!to be used inconstfunctions. Kani's override of thepanicandassertmacros is implemented via apanicand anassertfunction that are not marked as constant, which causes an error when those macros are used in a const function. This PR fixes the issue by addingconstto thepanicandassertfunctions.Resolved issues:
Resolves #1586
Call-outs:
Testing:
How is this change tested? Added two tests
Is this a refactor change? No
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.