You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
While this issue is not a direct bug in Kani, it impacts the usability of Kani in scenarios involving pointers to dyn Trait. Specifically, in challenge 3 of the verify-rust-std repository, we encountered this issue while verifying function contracts for <dyn Trait> pointee types.
Consider the following example:
This code runs successfully and calls the byte_offset method on a pointer to dyn TestTrait. However, when trying to annotate this method using the #[kani::proof_for_contract] attribute, as shown below:
Failed to resolve `<*const dyn TestTrait>::byte_offset`for`proof_for_contract`: Expected a type, but found trait object paths `dyn TestTrait`
Analysis
The issue appears to stem from a limitation in Rust, where attributes can only accept constant expressions and cannot handle dynamic dispatch. Since dyn Trait involves dynamic dispatch, Rust cannot resolve it in the attribute's context.
To work around this, we have adopted the following approach:
Instead of annotating the method with pointers to dyn Trait, we annotate it with its concrete base type:
Description
While this issue is not a direct bug in Kani, it impacts the usability of Kani in scenarios involving pointers to
dyn Trait
. Specifically, in challenge 3 of theverify-rust-std
repository, we encountered this issue while verifying function contracts for<dyn Trait>
pointee types.Consider the following example:
This code runs successfully and calls the
byte_offset
method on a pointer todyn TestTrait
. However, when trying to annotate this method using the#[kani::proof_for_contract]
attribute, as shown below:#[kani::proof_for_contract(<*const dyn TestTrait>::byte_offset)]
The following compilation error occurs:
Analysis
The issue appears to stem from a limitation in Rust, where attributes can only accept constant expressions and cannot handle dynamic dispatch. Since
dyn Trait
involves dynamic dispatch, Rust cannot resolve it in the attribute's context.To work around this, we have adopted the following approach:
dyn Trait
, we annotate it with its concrete base type:#[kani::proof_for_contract(<*const TestStruct>::byte_offset)]
While this workaround works, it diverges from the intent of verifying the contract directly for
<*const dyn Trait>::byte_offset
.Questions
dyn Trait
?The text was updated successfully, but these errors were encountered: