Verus 日本語訳 誤訳を知らせる
Verus ガイドVerus の構文
  1. Verus の概要
  2. はじめに
  3. コマンドラインで始める
  4. VS Code で始める
  5. verus! マクロ
  6. 基本的な仕様
  7. 事前条件(requires 節)
  8. 仕様のための式と演算子
  9. 整数型
  10. 等価性
  11. 仕様コード、証明コード、実行可能コード
  12. spec 関数
  13. proof 関数
  14. spec 関数と proof 関数の比較
  15. ゴーストコードと exec コード
  16. const 宣言
  17. すべてをまとめる
  18. 再帰とループ
  19. 再帰関数、decreases、燃料
  20. 再帰的な exec 関数と proof 関数、帰納法による証明
  21. 軽量な停止性検査
  22. ループと不変条件
  23. break を伴うループ
  24. for ループ
  25. イテレータ
  26. 辞書式の decreases 節と相互再帰
  27. データ型: 構造体と列挙型
  28. 構造体
  29. 列挙型
  30. ライブラリ
  31. 仕様ライブラリ: Seq、Set、ISet、Map、IMap
  32. 実行可能ライブラリ: Vec
  33. spec クロージャ
  34. 量化子
  35. forall とトリガー
  36. 複数の変数、複数のトリガー、マッチングループ
  37. exists と choose
  38. forall と exists についての証明
  39. 例: 二分探索
  40. broadcast で証明環境に常時有効な事実を加える
  41. 証明を作り上げる
  42. assert と assume を使って証明を作り上げる
  43. ループ不変条件を考え出す
  44. オーバーフローが起きないことを証明する
  45. SMT による求解と自動化
  46. 整数: 非線形算術
  47. ビットベクトルとビット演算
  48. 外延性による等価性
  49. 証明の性能を管理する方法と、それが重要な理由
  50. 検証の性能を測る
  51. 量化子のプロファイリング
  52. モジュール、隠蔽、opaque、reveal
  53. assert(...) by { ... } で局所的な証明を隠す
  54. 計算による構造化された証明
  55. 計算による証明
  56. SMT ソルバーのインスタンスを別に起動する
  57. 証明を小さな部分に分ける
  58. LLM を使って Verus プロジェクトの開発を助ける
  59. LLM を使って Verus の証明を書く作業を助ける
  60. チェックリスト: 証明がうまくいかないときにすること
  61. 変更、参照、借用
  62. 可変参照
  63. 可変参照についてのアサーション
  64. トレイト
  65. 独自の型のためのイテレータの仕様
  66. 有限イテレータのイテレータ仕様を実装する
  67. 無限イテレータのイテレータ仕様を実装する
  68. 高階の実行可能関数
  69. 関数を値として渡す
  70. クロージャ
  71. 文字列
  72. unsafe なコードと複雑な所有権
  73. 内部可変性
  74. ポインタとセル
  75. 並行性
  76. 論理的アトミック性
  77. アトミックな仕様
  78. 線形化点を発動する
  79. 論理的にアトミックな関数を呼び出す
  80. コンテナライブラリを検証する
  81. 単純な二分探索木
  82. 型不変条件で整形式性をカプセル化する
  83. ジェネリックにする
  84. Clone の実装
  85. コンテナの中の可変参照
  86. 例のソースコード全文
  87. 未検証コードとのやり取り
  88. 検証済みコードから未検証コードを呼び出す
  89. 未検証コードから検証済みコードを呼び出す
  90. 検証済みプログラムの保証を理解する
  91. Verus が保証すること
  92. 仮定と、信頼される構成要素
  93. メモリ安全性は検証を条件とする
  94. 未検証コードから検証済みコードを呼び出す
  95. Verus の IDE 対応
  96. Singular のインストールと設定
  97. プロジェクトのセットアップと開発
  98. Cargo 経由で Verus を使う
  99. Rustdoc による文書化
  100. ゴースト消去
  101. 対応している Rust の機能
  102. Verus の構文
  103. 変数のモード
  104. コミュニティ提供の拡張機能
  105. exec_spec_verified! マクロと exec_spec_unverified! マクロで spec 関数から実行可能コードを作る
  106. 実行可能コードのための Verus の属性
  107. 実行可能コードに対する spec 関数を自動的に作る
  108. 仕様言語
  109. 型の数学的な解釈
  110. spec 式
  111. 演算子の優先順位
  112. Rust のサブセット
  113. spec コードにおける算術
  114. ビット演算子
  115. as による型強制
  116. spec 等価性(==)
  117. 外延的等価性(=~= と =~~=)
  118. 前置の and/or(&&& と |||)
  119. 連鎖演算子
  120. 含意(==>、<==、<==>)
  121. spec の量化子(forall、exists)
  122. 〜を満たすもの(choose)
  123. トリガー注釈
  124. ビュー関数 @
  125. spec のインデックス演算子 []
  126. has 演算子
  127. is 演算子
  128. matches 演算子
  129. decreases_to!
  130. assert
  131. assume
  132. assert ... by
  133. assert forall ... by
  134. assert ... by(...)
  135. reveal、reveal_with_fuel、hide
  136. reveal_strlit
  137. bit_vector 証明器モード
  138. 非線形ソルバー
  139. integer_ring ソルバー
  140. compute モード
  141. exec 関数のシグネチャ
  142. proof 関数のシグネチャ
  143. spec 関数のシグネチャ
  144. returns
  145. opens_invariants
  146. 巻き戻しのシグネチャ
  147. recommends
  148. シグネチャの継承
  149. FnOnce の仕様
  150. 外部トレイトの仕様
  151. decreases ... when ... via ...
  152. 型不変条件
  153. 属性
  154. assume_specification
  155. 「global」指示
  156. static 項目
  157. 共用体
  158. ポインタとセル
  159. record フラグ
  160. 基本的なライブラリ

Verus の構文

以下のコードは、Verus の構文の大部分を例示しています。

#![allow(unused_imports)]

use verus_builtin::*;
use verus_builtin_macros::*;
use vstd::{modes::*, prelude::*, seq::*, *};

fn main() {}

const EXTERNAL_C: u8 = 7;

fn external_f(u: u8) -> u8 {
    u / 2
}

verus! {

/// functions may be declared exec (default), proof, or spec, which contain
/// exec code, proof code, and spec code, respectively.
///   - exec code: compiled, may have requires/ensures
///   - proof code: erased before compilation, may have requires/ensures
///   - spec code: erased before compilation, no requires/ensures, but may have recommends
/// exec and proof functions may name their return values inside parentheses, before the return type
fn my_exec_fun(x: u32, y: u32) -> (sum: u32)
    requires
        x < 100,
        y < 100,
    ensures
        sum < 200,
{
    x + y
}

proof fn my_proof_fun(x: int, y: int) -> (sum: int)
    requires
        x < 100,
        y < 100,
    ensures
        sum < 200,
{
    x + y
}

spec fn my_spec_fun(x: int, y: int) -> int
    recommends
        x < 100,
        y < 100,
{
    x + y
}

/// exec code cannot directly call proof functions or spec functions.
/// However, exec code can contain proof blocks (proof { ... }),
/// which contain proof code.
/// This proof code can call proof functions and spec functions.
fn test_my_funs(x: u32, y: u32)
    requires
        x < 100,
        y < 100,
{
    // my_proof_fun(x, y); // not allowed in exec code
    // let u = my_spec_fun(x, y); // not allowed exec code
    proof {
        let u = my_spec_fun(x as int, y as int);  // allowed in proof code
        my_proof_fun(u / 2, y as int);  // allowed in proof code
    }
}

/// spec functions with pub or pub(...) must specify whether the body of the function
/// should also be made publicly visible (open function) or not visible (closed function).
pub open spec fn my_pub_spec_fun1(x: int, y: int) -> int {
    // function and body visible to all
    x / 2 + y / 2
}

/* TODO
pub open(crate) spec fn my_pub_spec_fun2(x: u32, y: u32) -> u32 {
    // function visible to all, body visible to crate
    x / 2 + y / 2
}
*/

// TODO(main_new) pub(crate) is not being handled correctly
// pub(crate) open spec fn my_pub_spec_fun3(x: int, y: int) -> int {
//     // function and body visible to crate
//     x / 2 + y / 2
// }
pub closed spec fn my_pub_spec_fun4(x: int, y: int) -> int {
    // function visible to all, body visible to module
    x / 2 + y / 2
}

pub(crate) closed spec fn my_pub_spec_fun5(x: int, y: int) -> int {
    // function visible to crate, body visible to module
    x / 2 + y / 2
}

/// Recursive functions must have decreases clauses so that Verus can verify that the functions
/// terminate.
fn test_rec(x: u64, y: u64)
    requires
        0 < x < 100,
        y < 100 - x,
    decreases x,
{
    if x > 1 {
        test_rec(x - 1, y + 1);
    }
}

/// Multiple decreases clauses are ordered lexicographically, so that later clauses may
/// increase when earlier clauses decrease.
spec fn test_rec2(x: int, y: int) -> int
    decreases x, y,
{
    if y > 0 {
        1 + test_rec2(x, y - 1)
    } else if x > 0 {
        2 + test_rec2(x - 1, 100)
    } else {
        3
    }
}

/// To help prove termination, recursive spec functions may have embedded proof blocks
/// that can make assertions, use broadcasts, and call lemmas.
spec fn test_rec_proof_block(x: int, y: int) -> int
    decreases x,
{
    if x < 1 {
        0
    } else {
        proof {
            assert(x - 1 >= 0);
        }
        test_rec_proof_block(x - 1, y + 1) + 1
    }
}

/// Decreases and recommends may specify additional clauses:
///   - decreases .. "when" restricts the function definition to a condition
///     that makes the function terminate
///   - decreases .. "via" specifies a proof function that proves the termination
///     (although proof blocks are usually simpler; see above)
///   - recommends .. "when" specifies a proof function that proves the
///     recommendations of the functions invoked in the body
spec fn add0(a: nat, b: nat) -> nat
    recommends
        a > 0,
    via add0_recommends
{
    a + b
}

spec fn dec0(a: int) -> int
    decreases a,
    when a > 0
    via dec0_decreases
{
    if a > 0 {
        dec0(a - 1)
    } else {
        0
    }
}

#[via_fn]
proof fn add0_recommends(a: nat, b: nat) {
    // proof
}

#[via_fn]
proof fn dec0_decreases(a: int) {
    // proof
}

/// variables may be exec, tracked, or ghost
///   - exec: compiled
///   - tracked: erased before compilation, checked for lifetimes (advanced feature, discussed later)
///   - ghost: erased before compilation, no lifetime checking, can create default value of any type
/// Different variable modes may be used in different code modes:
///   - variables in exec code are always exec
///   - variables in proof code are ghost by default (tracked variables must be marked "tracked")
///   - variables in spec code are always ghost
/// For example:
fn test_my_funs2(
    a: u32,  // exec variable
    b: u32,  // exec variable
)
    requires
        a < 100,
        b < 100,
{
    let s = a + b;  // s is an exec variable
    proof {
        let u = a + b;  // u is a ghost variable
        my_proof_fun(u / 2, b as int);  // my_proof_fun(x, y) takes ghost parameters x and y
    }
}

/// assume and assert are treated as proof code even outside of proof blocks.
/// "assert by" may be used to provide proof code that proves the assertion.
#[verifier::opaque]
spec fn f1(i: int) -> int {
    i + 1
}

fn assert_by_test() {
    assert(f1(3) > 3) by {
        reveal(f1);  // reveal f1's definition just inside this block
    }
    assert(f1(3) > 3);
}

/// "assert by" can also invoke specialized provers for bit-vector reasoning or nonlinear arithmetic.
fn assert_by_provers(x: u32) {
    assert(x ^ x == 0u32) by (bit_vector);
    assert(2 <= x && x < 10 ==> x * x > x) by (nonlinear_arith);
}

/// "assert by" provers can also appear on function signatures to select a specific prover
/// for the function body.
proof fn lemma_mul_upper_bound(x: int, x_bound: int, y: int, y_bound: int)
    by (nonlinear_arith)
    requires
        x <= x_bound,
        y <= y_bound,
        0 <= x,
        0 <= y,
    ensures
        x * y <= x_bound * y_bound,
{
}

/// "assert by" can use nonlinear_arith with proof code,
/// where "requires" clauses selectively make facts available to the proof code.
proof fn test5_bound_checking(x: u32, y: u32, z: u32)
    requires
        x <= 0xffff,
        y <= 0xffff,
        z <= 0xffff,
{
    assert(x * z == mul(x, z)) by (nonlinear_arith)
        requires
            x <= 0xffff,
            z <= 0xffff,
    {
        assert(0 <= x * z);
        assert(x * z <= 0xffff * 0xffff);
    }
}

/// The syntax for forall and exists quantifiers is based on closures:
fn test_quantifier() {
    assert(forall|x: int, y: int| 0 <= x < 100 && 0 <= y < 100 ==> my_spec_fun(x, y) >= x);
    assert(my_spec_fun(10, 20) == 30);
    assert(exists|x: int, y: int| my_spec_fun(x, y) == 30);
}

/// "assert forall by" may be used to prove foralls:
fn test_assert_forall_by() {
    assert forall|x: int, y: int| f1(x) + f1(y) == x + y + 2 by {
        reveal(f1);
    }
    assert(f1(1) + f1(2) == 5);
    assert(f1(3) + f1(4) == 9);
    // to prove forall|...| P ==> Q, write assert forall|...| P implies Q by {...}
    assert forall|x: int| x < 10 implies f1(x) < 11 by {
        assert(x < 10);
        reveal(f1);
        assert(f1(x) < 11);
    }
    assert(f1(3) < 11);
}

/// To extract ghost witness values from exists, use choose:
fn test_choose() {
    assume(exists|x: int| f1(x) == 10);
    proof {
        let x_witness = choose|x: int| f1(x) == 10;
        assert(f1(x_witness) == 10);
    }
    assume(exists|x: int, y: int| f1(x) + f1(y) == 30);
    proof {
        let (x_witness, y_witness): (int, int) = choose|x: int, y: int| f1(x) + f1(y) == 30;
        assert(f1(x_witness) + f1(y_witness) == 30);
    }
}

/// To manually specify a trigger to use for the SMT solver to match on when instantiating a forall
/// or proving an exists, use #[trigger]:
fn test_single_trigger1() {
    // Use [my_spec_fun(x, y)] as the trigger
    assume(forall|x: int, y: int| f1(x) < 100 && f1(y) < 100 ==> #[trigger] my_spec_fun(x, y) >= x);
}

fn test_single_trigger2() {
    // Use [f1(x), f1(y)] as the trigger
    assume(forall|x: int, y: int| #[trigger]
        f1(x) < 100 && #[trigger] f1(y) < 100 ==> my_spec_fun(x, y) >= x);
}

/// To manually specify multiple triggers, use #![trigger]:
fn test_multiple_triggers() {
    // Use both [my_spec_fun(x, y)] and [f1(x), f1(y)] as triggers
    assume(forall|x: int, y: int|
        #![trigger my_spec_fun(x, y)]
        #![trigger f1(x), f1(y)]
        f1(x) < 100 && f1(y) < 100 ==> my_spec_fun(x, y) >= x);
}

/// Verus can often automatically choose a trigger if no manual trigger is given.
/// Use the command-line option --triggers to print the chosen triggers.
fn test_auto_trigger1() {
    // Verus automatically chose [my_spec_fun(x, y)] as the trigger.
    // (It considers this safer, i.e. likely to match less often, than the trigger [f1(x), f1(y)].)
    assume(forall|x: int, y: int| f1(x) < 100 && f1(y) < 100 ==> my_spec_fun(x, y) >= x);
}

/// If Verus prints a note saying that it automatically chose a trigger with low confidence,
/// you can supply manual triggers or use #![auto] to accept the automatically chosen trigger.
fn test_auto_trigger2() {
    // Verus chose [f1(x), f1(y)] as the trigger; go ahead and accept that
    assume(forall|x: int, y: int| #![auto] f1(x) < 100 && f1(y) < 100 ==> my_spec_fun(3, y) >= 3);
}

/// &&& and ||| are like && and ||, but have low precedence (lower than all other binary operators,
/// and lower than forall/exists/choose).
/// &&& must appear before each conjunct, rather than between the conjuncts (similarly for |||).
/// &&& must appear directly inside a block or at the end of a block.
spec fn simple_conjuncts(x: int, y: int) -> bool {
    &&& 1 < x
    &&& y > 9 ==> x + y < 50
    &&& x < 100
    &&& y < 100
}

spec fn complex_conjuncts(x: int, y: int) -> bool {
    let b = x < y;
    &&& b
    &&& if false {
        &&& b ==> b
        &&& !b ==> !b
    } else {
        ||| b ==> b
        ||| !b
    }
    &&& false ==> true
}

/// ==> associates to the right, while <== associates to the left.
/// <==> is nonassociative.
/// == is SMT equality.
/// != is SMT disequality.
pub(crate) proof fn binary_ops<A>(a: A, x: int) {
    assert(false ==> true);
    assert(true && false ==> false && false);
    assert(!(true && (false ==> false) && false));
    assert(false ==> false ==> false);
    assert(false ==> (false ==> false));
    assert(!((false ==> false) ==> false));
    assert(false <== false <== false);
    assert(!(false <== (false <== false)));
    assert((false <== false) <== false);
    assert(2 + 2 != 3);
    assert(a == a);
    assert(false <==> true && false);
}

/// In specs, <=, <, >=, and > may be chained together so that, for example, a <= b < c means
/// a <= b && b < c.  (Note on efficiency: if b is a complex expression,
/// Verus will automatically introduce a temporary variable under the hood so that
/// the expression doesn't duplicate b: {let x_b = b; a <= x_b && x_b < c}.)
proof fn chained_comparisons(i: int, j: int, k: int)
    requires
        0 <= i + 1 <= j + 10 < k + 7,
    ensures
        j < k,
{
}

/// In specs, e@ is an abbreviation for e.view()
/// Many types implement a view() method to get an abstract ghost view of a concrete type.
fn test_views() {
    let mut v: Vec<u8> = Vec::new();
    v.push(10);
    v.push(20);
    proof {
        let s: Seq<u8> = v@;  // v@ is equivalent to v.view()
        assert(s[0] == 10);
        assert(s[1] == 20);
    }
}

/// struct and enum declarations may be declared exec (default), tracked, or ghost,
/// and fields may be declared exec (default), tracked or ghost.
tracked struct TrackedAndGhost<T, G>(tracked T, ghost G);

/// Proof code may manipulate tracked variables directly.
/// Declarations of tracked variables must be explicitly marked as "tracked".
proof fn consume(tracked x: int) {
}

proof fn test_tracked(
    tracked w: int,
    tracked x: int,
    tracked y: int,
    z: int,
) -> tracked TrackedAndGhost<(int, int), int> {
    consume(w);
    let tracked tag: TrackedAndGhost<(int, int), int> = TrackedAndGhost((x, y), z);
    let tracked TrackedAndGhost((a, b), c) = tag;
    TrackedAndGhost((a, b), c)
}

/// Variables in exec code may be exec, ghost, or tracked.
fn test_ghost(x: u32, y: u32)
    requires
        x < 100,
        y < 100,
{
    let ghost u: int = my_spec_fun(x as int, y as int);
    let ghost mut v = u + 1;
    assert(v == x + y + 1);
    proof {
        v = v + 1;  // proof code may assign to ghost mut variables
    }
    let ghost w = {
        let temp = v + 1;
        temp + 1
    };
    assert(w == x + y + 4);
}

/// Variables in exec code may be exec, ghost, or tracked.
/// However, exec function parameters and return values are always exec.
/// In these places, the library types Ghost and Tracked are used
/// to wrap ghost values and tracked values.
/// Ghost and tracked expressions Ghost(expr) and Tracked(expr) create values of type Ghost<T>
/// and Tracked<T>, where expr is treated as proof code whose value is wrapped inside Ghost or Tracked.
/// The view x@ of a Ghost or Tracked x is the ghost or tracked value inside the Ghost or Tracked.
fn test_ghost_wrappers(x: u32, y: Ghost<u32>)
    requires
        x < 100,
        y@ < 100,
{
    // Ghost(...) expressions can create values of type Ghost<...>:
    let u: Ghost<int> = Ghost(my_spec_fun(x as int, y@ as int));
    let mut v: Ghost<int> = Ghost(u@ + 1);
    assert(v@ == x + y@ + 1);
    proof {
        v@ = v@ + 1;  // proof code may assign to the view of exec variables of type Ghost/Tracked
    }
    let w: Ghost<int> = Ghost(
        {
            // proof block that returns a ghost value
            let temp = v@ + 1;
            temp + 1
        },
    );
    assert(w@ == x + y@ + 4);
}

fn test_consume(t: Tracked<int>)
    requires
        t@ <= 7,
{
    proof {
        let tracked x = t.get();
        assert(x <= 7);
        consume(x);
    }
}

/// Ghost(...) and Tracked(...) patterns can unwrap Ghost<...> and Tracked<...> values:
fn test_ghost_unwrap(
    x: u32,
    Ghost(y): Ghost<u32>,
)  // unwrap so that y has typ u32, not Ghost<u32>
    requires
        x < 100,
        y < 100,
{
    // Ghost(u) pattern unwraps Ghost<...> values and gives u and v type int:
    let Ghost(u): Ghost<int> = Ghost(my_spec_fun(x as int, y as int));
    let Ghost(mut v): Ghost<int> = Ghost(u + 1);
    assert(v == x + y + 1);
    proof {
        v = v + 1;  // assign directly to ghost mut v
    }
    let Ghost(w): Ghost<int> = Ghost(
        {
            // proof block that returns a ghost value
            let temp = v + 1;
            temp + 1
        },
    );
    assert(w == x + y + 4);
}

struct S {}

/// Exec code can use "let ghost" and "let tracked" to create local ghost and tracked variables.
/// Exec code can extract individual ghost and tracked values from Ghost and Tracked wrappers
/// with "let ...Ghost(x)..." and "let ...Tracked(x)...".
fn test_ghost_tuple_match(t: (Tracked<S>, Tracked<S>, Ghost<int>, Ghost<int>)) -> Tracked<S> {
    let ghost g: (int, int) = (10, 20);
    assert(g.0 + g.1 == 30);
    let ghost (g1, g2) = g;
    assert(g1 + g2 == 30);
    // b1, b2: Tracked<S> and g3, g4: Ghost<int>
    let (Tracked(b1), Tracked(b2), Ghost(g3), Ghost(g4)) = t;
    Tracked(b2)
}

/// Exec code can use a Tracked(...) unwrapped parameter
/// to create a mutable ghost or tracked parameter:
fn test_tracked_mut(Tracked(g): Tracked<&mut int>)
    ensures
        *final(g) == *old(g) + 1,
{
    proof {
        *g = *g + 1;
    }
}

fn test_call_ghost_mut() {
    let tracked mut g = 10int;
    test_tracked_mut(Tracked(&mut g));
    assert(g == 11);
}

/// Spec functions are not checked for correctness (although they are checked for termination).
/// However, marking a spec function as "spec(checked)" enables lightweight "recommends checking"
/// inside the spec function.
spec(checked) fn my_spec_fun2(x: int, y: int) -> int
    recommends
        x < 100,
        y < 100,
{
    // Because of spec(checked), Verus checks that my_spec_fun's recommends clauses are satisfied here:
    my_spec_fun(x, y)
}

/// Spec functions may omit their body, in which case they are considered
/// uninterpreted (returning an arbitrary value of the return type depending on the input values).
/// This is safe, since spec functions (unlike proof and exec functions) may always
/// return arbitrary values of any type,
/// where the value may be special "bottom" value for otherwise uninhabited types.
uninterp spec fn my_uninterpreted_fun1(i: int, j: int) -> int;

uninterp spec fn my_uninterpreted_fun2(i: int, j: int) -> int
    recommends
        0 <= i < 10,
        0 <= j < 10,
;

/// Trait functions may have specifications
trait T {
    proof fn my_function_decl(&self, i: int, j: int) -> (r: int)
        requires
            0 <= i < 10,
            0 <= j < 10,
        ensures
            i <= r,
            j <= r,
    ;

    /// A trait function may have a default (provided) implementation,
    /// and this default may have additional ensures specified with default_ensures
    fn my_function_with_a_default(&self, i: u32, j: u32) -> (r: u32)
        requires
            0 <= i < 10,
            0 <= j < 10,
        ensures
            i <= r,
            j <= r,
        default_ensures
            i == r || j == r,
        {
            if i >= j { i } else { j }
        }
}

struct S1;
struct S2;

/// An impl can choose to use the default impl of my_function_with_a_default,
/// in which case the default_ensures applies to my_function_with_a_default
impl T for S1 {
    proof fn my_function_decl(&self, i: int, j: int) -> (r: int) {
        i + j
    }
}

/// An impl can choose not to use the default impl of my_function_with_a_default,
/// and instead provide its own impl, in which case the default_ensures is ignored
impl T for S2 {
    proof fn my_function_decl(&self, i: int, j: int) -> (r: int) {
        i + j
    }

    fn my_function_with_a_default(&self, i: u32, j: u32) -> (r: u32)
        ensures
            r == i + j,
    {
        i + j
    }
}

enum ThisOrThat {
    This(nat),
    That { v: int },
}

proof fn uses_is(t: ThisOrThat) {
    match t {
        ThisOrThat::This(..) => {
            assert(t is This);
            assert(t !is That);
        },
        ThisOrThat::That { .. } => {
            assert(t is That);
            assert(t !is This);
        },
    }
}

proof fn uses_arrow_matches_1(t: ThisOrThat)
    requires
        t is That ==> t->v == 3,
        t is This ==> t->0 == 4,
{
    assert(t matches ThisOrThat::This(k) ==> k == 4);
    assert(t matches ThisOrThat::That { v } ==> v == 3);
}

proof fn uses_arrow_matches_2(t: ThisOrThat)
    requires
        t matches ThisOrThat::That { v: a } && a == 3,
{
    assert(t is That && t->v == 3);
}

proof fn uses_spec_has(s: Set<int>, ms: vstd::multiset::Multiset<int>)
    requires
        s has 3,
        ms has 4,
{
    assert(s has 3);
    assert(s has 3 == s has 3);
    assert(ms has 4);
    assert(ms has 4 == ms has 4);
}

proof fn broadcast_use() {
    // you can use broadcase use on the module level, in proof functions,
    // in proof blocks, or in assert-by
    broadcast use vstd::seq_lib::group_seq_properties;
    // you can also use multiple broadcast lemmas at once
    broadcast use {
        vstd::multiset::group_multiset_properties,
        vstd::multiset::group_multiset_axioms,
    };
    // although we don't support a list of paths with common prefix like:
    // broadcast use vstd::multiset::{group_multiset_properties, group_multiset_axioms};

    assert forall|s: Seq<usize>, v: usize, x: usize|
        { s.contains(x) ==> s.push(v).contains(x) } by {
        broadcast use vstd::seq_lib::group_seq_properties;

    };
}

/// Specifications can be assumed for functions and constants from outside Verus.
/// Warning: such specifications are trusted to be correct, so they must be chosen carefully.
assume_specification[EXTERNAL_C] -> u8
    returns
        7u8,
;

assume_specification[external_f](u: u8) -> (r: u8)
    ensures
        r <= u,
;

fn test_external() {
    assert(EXTERNAL_C == 7);
    let x = external_f(10);
    assert(x <= 10);
}

} // verus!