kani icon indicating copy to clipboard operation
kani copied to clipboard

Create custom derive macro for Arbitrary type.

Open celinval opened this issue 4 years ago • 1 comments

Requested feature: Create a proc_macro that allows users to annotate their structs and enums with #[derive(Invariant)] Use case: Allow users to easily generate implementation of the Invariant types for their custom structs and enums whenever the invariant of their types is the combination of their field's invariant. Link to relevant documentation (Rust reference, Nomicon, RFC): Is this a breaking change? No

Test case:

#[derive(Invariant)]
enum Operation {
    Sum,
    Sub,
}

fn main() {
    let op : Operation = rmc::any();
    let v1 : i32 = rmc::any();
    let v2: i32 = rmc::any();
    calculate(v1, v2, op);
}

This should generate something like:

unsafe impl Invariant for Operation {
    fn is_valid(&self) -> bool {
        matches!(*self, Operation::Sum | Operation::Sub);
    }
}

celinval avatar Jan 05 '22 00:01 celinval

Since we have deprecated Invariant, I'm updating this issue to create a derive macro for Arbitrary.

celinval avatar Jul 28 '22 18:07 celinval