formalmethods.dev

§ 5.3 · Rust · proptest + the type system

Rust

types make some properties unrepresentable; proptest hunts the rest.

Rust's type system is a theorem prover you already use: an enum State { Idle, Paid, Vend } is a proof that no fourth state exists — a property enforced by construction, no test needed.

proptest covers what types cannot: temporal behaviour across generated runs, same shape as Hypothesis. For concurrency specifically, loom exhaustively explores the interleavings — which is a model checker wearing a macro.

in Rust

prop_assert!(owed >= 0) — with runs from proptest::collection::vec

as LTL · expected violatedG (coin -> F dispense)
tests/vend.rs
// tests/vend.rs — properties as macros; traces as generated Vecs.
use proptest::prelude::*;

proptest! {
    #[test]
    fn coins_are_answered(run in proptest::collection::vec(
        "coin|dispense|timeout", 0..12)) {
        let mut owed = 0i64;
        for e in &run {
            match e.as_str() {
                "coin" => owed += 1,
                "dispense" => owed -= 1,
                _ => {}
            }
            prop_assert!(owed >= 0);
        }
    }
}
the artifact · The minimal failing run proptest reports: a coin, then silence. check_ltl confirms it violates `G (coin -> F dispense)` position by position, with the truth table as the proof.
012pos
coin
timeout
exposed over mcpcheck_ltl
view the JSON-RPC body · POST to /api/mcp
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "check_ltl",
    "arguments": {
      "formula": "G (coin -> F dispense)",
      "trace": [
        [
          "coin"
        ],
        [
          "timeout"
        ],
        [
          "timeout"
        ]
      ]
    }
  }
}
how the lab helps · skills guide + mcp against Rust
read_skills_guide

The guide's Step 1 pattern table is how an agent turns a Rust comment like “the lock must be free before acquiring” into G (acquire -> free) — grammar and precedence, no translation guesswork.

model_check

loom explores interleavings; agents feed the explored schedule as a Kripke artifact to model_check and get the lasso counterexample — the exact interleaving that deadlocks — as a failing test.

explain_concept

When a proptest failure is temporal but the team speaks Rust, agents pull the matching chapter (model-checking, property-based-testing) for the vocabulary to file the issue precisely.

Model checking and proptest compose: loom is literally a bounded model checker for Send/Sync interleavings — verdicts labelled done/incomplete, same honesty as ours.

Rust convention: property tests live in tests/, types carry the invariants they can, comments cite the LTL clause for the rest.

field guide · Model checking · Property-based testing & falsification