Skip to content

How to write spec for new type implementing Add? #1928

@TheodoreEhrenborg

Description

@TheodoreEhrenborg

Minimal example:

use vstd::prelude::*;

verus! {

pub struct Foo(u64);

impl core::ops::Add for Foo {
    type Output = Foo;

    fn add(self, other: Foo) -> Foo {
        assume(self.0 + other.0 < 1000); // To hide overflow error
        Foo(self.0 + other.0)
    }
}

fn main() {
}

} // verus!

Error message:

[rust_verify/src/verifier.rs:100:17] &note = "failed this postcondition"
[rust_verify/src/verifier.rs:100:17] &sp.as_string = "vstd/std_specs/ops.rs:70:25: 70:66 (#2446)"
error: postcondition not satisfied

verification results:: 1 verified, 1 errors
error: aborting due to 1 previous error

Version:

╰─>$ verus --version
Verus
  Version: 0.2025.10.05.bf8e97e
  Profile: release
  Platform: linux_x86_64
  Toolchain: 1.88.0-x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions