Skip to content

Loop contracts in closures and coroutines #3599

Description

@qinheping

Requested feature: Currently loop contracts implementation in #3151 doesn't support loop contracts in closures and coroutines. We want to allow loop contracts be correctly applied in closures and coroutines.
Use case:
Link to relevant documentation (Rust reference, Nomicon, RFC): #3167

Test case:

fn main() {
let mut x: u8 = 11;

let mut res = ||->u8 {    
    #[kani::loop_invariant(x >= 2)]
    while x > 2 {
        x = x - 1;
    }
    x
};

    assert!(res() == 2);
}

Activity

  1. added
    [C] Feature / Enhancement
    on Oct 14, 2024
  2. self-assigned this
    on Oct 24, 2024
  3. added
    Z-Contracts
    on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Z-Contracts[C] Feature / Enhancement

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions