#![feature(rustc_private)] #[macro_use] mod common; use common::*; const IMPORTS: &str = code_str! { #[allow(unused_imports)] use vstd::prelude::*; #[allow(unused_imports)] use vstd::contrib::exec_spec::*; #[allow(unused_imports)] use vstd::multiset::*; #[allow(unused_imports)] use std::collections::HashSet; #[allow(unused_imports)] use std::collections::HashMap; }; test_verify_one_file! { /// Tests basic enum compilation. #[test] test_exec_spec_enum IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub enum E1 { Blob(usize, usize), Seq(Seq>), } pub enum E2 { E1(E1), StructLike { a: u32, b: E1, }, Unit, } } } => Ok(()) } test_verify_one_file! { /// Tests basic struct compilation. #[test] test_exec_spec_struct IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { enum MyOption { Some(u32), None, } } exec_spec_verified! { pub struct S { a: u32, b: MyOption, } } } => Ok(()) } test_verify_one_file! { /// Tests that compiler generates exec code with good typing. #[test] test_exec_spec_typing IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn id_string(s: SpecString) -> SpecString { s } spec fn id_u32(i: u32) -> u32 { i } spec fn id_seq(s: Seq) -> Seq { s } struct S { b: SpecString, } spec fn get(s: S) -> SpecString { let b = s.b; let a = id_string(b); a } } } => Ok(()) } test_verify_one_file! { /// Tests compilation of literals. #[test] test_exec_spec_literals IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test1(sel: bool, s: Seq) -> Seq { let f = if sel { s } else { seq![""@] }; f } spec fn test2(sel: bool, s: Seq) -> Seq { let s1 = seq![""@]; let f = if sel { s } else { s1 }; f } spec fn test3() -> bool { true } spec fn test4() -> i32 { 123 } spec fn test5() -> SpecString { "hello"@ } spec fn test6() -> Seq { seq!['h', 'e', 'l', 'l', 'o'] } } } => Ok(()) } test_verify_one_file! { /// Tests basic arithemetic operations. #[test] test_exec_spec_arith IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn square(x: u32) -> u32 recommends x * x <= u32::MAX { (x * x) as u32 } spec fn complex(x: u32) -> u32 recommends u32::MIN <= x * x <= u32::MAX, u32::MIN <= x * x + x <= u32::MAX, u32::MIN <= x * x + x - 2 <= u32::MAX { (x * x + x - 2) as u32 } spec fn compare(x: i32, y: i32) -> bool { ||| x < y ||| x >= y ||| x == 1 ||| x != 1 ||| x != x - y } } } => Ok(()) } test_verify_one_file! { /// Tests string indexing. #[test] test_exec_spec_index1 IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test(s: SpecString, i: usize) -> char { if 0 <= i && i < s.len() { s[i as int] } else { ' ' } } } } => Ok(()) } test_verify_one_file! { /// Tests sequence indexing #[test] test_exec_spec_index2 IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test1(s: Seq>, i: usize, j: usize, n: usize) -> char { let c = if i < s.len() && j < s[i as int].len() && n < s[i as int][j as int].len() { s[i as int][j as int][n as int] } else { ' ' }; c } spec fn test2(s: Seq, i: usize) -> char { if i < s.len() { s[i as int] } else { ' ' } } } } => Ok(()) } test_verify_one_file! { /// Tests equality. #[test] test_exec_spec_equality IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test_eq1(i: usize, j: usize) -> bool { i == j } spec fn test_eq2(a: SpecString, b: SpecString) -> bool { a == b } spec fn test_eq3(a: Seq, b: Seq) -> bool { a == b } spec fn test_eq4(a: Seq, b: Seq) -> bool { a == b } spec fn test_eq5(a: Seq) -> bool { a == seq!["hello"@, "world"@] } spec fn test_eq6(a: Seq>, i: usize) -> bool recommends 0 <= i < a.len() { a[i as int] == seq!["hello"@, "world"@] } spec fn test_eq7(a: Map, b: Map) -> bool { a == b } spec fn test_eq8(a: Map>, b: Map>) -> bool { a == b } spec fn test_eq9(a: Set, b: Set) -> bool { a == b } spec fn test_eq10(a: Set>, b: Set>) -> bool { a == b } spec fn test_eq11(a: Multiset, b: Multiset) -> bool { a == b } spec fn test_eq12(a: Multiset>, b: Multiset>) -> bool { a == b } spec fn test_eq13(a: Option, b: Option) -> bool { a == b } spec fn test_eq14(a: Option>, b: Option>) -> bool { a == b } } } => Ok(()) } test_verify_one_file! { /// Tests match expressions. #[test] test_exec_spec_match IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { enum EitherString { Left { s1: SpecString, s2: SpecString }, Right(SpecString), } struct GoodString { s: SpecString, } struct BadString(char, char); spec fn test_match1(s: EitherString) -> SpecString { match s { EitherString::Left { s1, .. } => s1, EitherString::Right(x) => x, } } spec fn test_match2(s: EitherString) -> SpecString { match s { EitherString::Left { s1, s2: _ } => s1, _ => "ello"@, } } spec fn test_match3(s: GoodString) -> SpecString { match s { GoodString { s } => s, } } spec fn test_match4(s: BadString) -> char { match s { BadString(c1, ..) => c1, } } spec fn test_tuple_struct() -> char { test_match4(BadString('a', 'b')) } spec fn test_match5(s: BadString) -> char { match s { BadString(_, c2) => c2, } } } } => Ok(()) } test_verify_one_file! { /// Tests support for built-in [`Option`] type. #[test] test_exec_spec_option IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test_option1(s: Option) -> SpecString { match s { Some(s) => s, None => "hi"@, } } spec fn test_option2(s: Option) -> bool { &&& test_option1(s) == match s { Some(s) => s, None => "ww"@, } &&& s == Some("yes"@) } spec fn test_option3(s: Option) -> bool recommends s.is_some() { s.unwrap() == "yes"@ } spec fn test_option4(s: Option) -> SpecString { match s { Some(_) => s.unwrap(), None => "none"@, } } } } => Ok(()) } test_verify_one_file! { /// Tests support for built-in tuple types. #[test] test_exec_spec_tuple IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test_tuple1(a: u32, b: u32) -> (u32, u32) { (a, b) } spec fn test_tuple2(a: (SpecString, u32), b: (SpecString, u32)) -> bool { &&& a == b &&& (a.0, b.1) == (b.0, a.1) &&& test_tuple1(a.1, b.1) == test_tuple1(b.1, a.1) } spec fn test_tuple3(a: (SpecString, u32, u8), b: (SpecString, u32, u8)) -> bool { &&& a == b &&& (a.0, a.1, a.2) == (b.0, b.1, b.2) &&& test_tuple2((a.0, a.1), (b.0, b.1)) } spec fn test_tuple4(a: (SpecString, u32, u8, bool), b: (SpecString, u32, u8, bool)) -> bool { &&& a == b &&& (a.0, a.1, a.2, a.3) == (b.0, b.1, b.2, a.3) &&& test_tuple3((a.0, a.1, a.2), (b.0, b.1, b.2)) } } } => Ok(()) } test_verify_one_file! { /// Tests support for functions on Seq. #[test] test_exec_spec_seq IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Inner { i: i64 } pub struct Data { x: u8, y: Seq, z: (u8, u8, Inner), } spec fn add_eq(s1: Seq, s2: Seq, s3: Seq) -> bool { s1.add(s2) == s3 } spec fn add_nested(s1: Seq>, s2: Seq>, s3: Seq>) -> bool { s1.add(s2) == s3 } spec fn add_struct(s1: Seq, s2: Seq, s3: Seq) -> bool { s1.add(s2) == s3 } spec fn contains_eq(s1: Seq, x: u8) -> bool { s1.contains(x) } spec fn contains_nested(s1: Seq>, x: Seq) -> bool { s1.contains(x) } spec fn contains_struct(s1: Seq, x: Data) -> bool { s1.contains(x) } spec fn drop_first_eq(s1: Seq, s2: Seq) -> bool recommends s1.len() >= 1 { s1.drop_first() == s2 } spec fn drop_first_nested(s1: Seq>, s2: Seq>) -> bool recommends s1.len() >= 1 { s1.drop_first() == s2 } spec fn drop_first_struct(s1: Seq, s2: Seq) -> bool recommends s1.len() >= 1 { s1.drop_first() == s2 } spec fn drop_last_eq(s1: Seq, s2: Seq) -> bool recommends s1.len() >= 1 { s1.drop_last() == s2 } spec fn drop_last_nested(s1: Seq>, s2: Seq>) -> bool recommends s1.len() >= 1 { s1.drop_last() == s2 } spec fn drop_last_struct(s1: Seq, s2: Seq) -> bool recommends s1.len() >= 1 { s1.drop_last() == s2 } spec fn empty_seq() -> Seq { Seq::empty() } spec fn empty_seq_length_zero() -> bool { empty_seq().len() == 0 } spec fn first_element(s: Seq, x: u8) -> bool recommends 0 < s.len() { s.first() == x } spec fn first_nested(s: Seq>, x: Seq) -> bool recommends 0 < s.len() { s.first() == x } spec fn first_struct(s: Seq, x: Data) -> bool recommends 0 < s.len() { s.first() == x } spec fn index_eq(s: Seq, i: usize, x: u8) -> bool recommends 0 <= i < s.len() { s.index(i as int) == x } spec fn index_nested(s: Seq>, i: usize, x: Seq) -> bool recommends 0 <= i < s.len() { s.index(i as int) == x } spec fn index_struct(s: Seq, i: usize, x: Data) -> bool recommends 0 <= i < s.len() { s.index(i as int) == x } spec fn index_of_eq(s1: Seq, x: u8, i: usize) -> bool { s1.index_of(x) == i } spec fn index_of_nested(s1: Seq>, x: Seq, i: usize) -> bool { s1.index_of(x) == i } spec fn index_of_struct(s1: Seq, x: Data, i: usize) -> bool { s1.index_of(x) == i } spec fn index_of_first_eq(s1: Seq, x: u8, i: Option) -> bool { match s1.index_of_first(x) { Some(n) => true, None => false } } spec fn index_of_first_nested(s1: Seq>, x: Seq, i: Option) -> bool { s1.index_of_first(x) == match i { None => None, Some(n) => Some(n as int), } } spec fn index_of_first_struct(s1: Seq, x: Data, i: Option) -> bool { s1.index_of_first(x) == match i { None => None, Some(n) => Some(n as int), } } spec fn index_of_last_eq(s1: Seq, x: u8, i: Option) -> bool { s1.index_of_last(x) == match i { None => None, Some(n) => Some(n as int), } } spec fn index_of_last_nested(s1: Seq>, x: Seq, i: Option) -> bool { s1.index_of_last(x) == match i { None => None, Some(n) => Some(n as int), } } spec fn index_of_last_struct(s1: Seq, x: Data, i: Option) -> bool { s1.index_of_last(x) == match i { None => None, Some(n) => Some(n as int), } } spec fn is_prefix_of_eq(s1: Seq, s2: Seq) -> bool { s1.is_prefix_of(s2) } spec fn is_prefix_of_nested(s1: Seq>, s2: Seq>) -> bool { s1.is_prefix_of(s2) } spec fn is_prefix_of_struct(s1: Seq, s2: Seq) -> bool { s1.is_prefix_of(s2) } spec fn is_suffix_of_eq(s1: Seq, s2: Seq) -> bool { s1.is_suffix_of(s2) } spec fn is_suffix_of_nested(s1: Seq>, s2: Seq>) -> bool { s1.is_suffix_of(s2) } spec fn is_suffix_of_struct(s1: Seq, s2: Seq) -> bool { s1.is_suffix_of(s2) } spec fn last_element(s: Seq, x: u8) -> bool recommends 0 < s.len() { s.last() == x } spec fn last_nested(s: Seq>, x: Seq) -> bool recommends 0 < s.len() { s.last() == x } spec fn last_struct(s: Seq, x: Data) -> bool recommends 0 < s.len() { s.last() == x } spec fn push_element(s1: Seq, x: u8, s2: Seq) -> bool { s1.push(x) == s2 } spec fn push_nested(s1: Seq>, x: Seq, s2: Seq>) -> bool { s1.push(x) == s2 } spec fn push_struct(s1: Seq, x: Data, s2: Seq) -> bool { s1.push(x) == s2 } spec fn skip_eq(s1: Seq, n: usize, s2: Seq) -> bool recommends 0 <= n <= s1.len() { s1.skip(n as int) == s2 } spec fn skip_nested(s1: Seq>, n: usize, s2: Seq>) -> bool recommends 0 <= n <= s1.len() { s1.skip(n as int) == s2 } spec fn skip_struct(s1: Seq, n: usize, s2: Seq) -> bool recommends 0 <= n <= s1.len() { s1.skip(n as int) == s2 } spec fn subrange_eq(s1: Seq, s: usize, e: usize, s2: Seq) -> bool recommends 0 <= s <= e <= s1.len() { s1.subrange(s as int, e as int) == s2 } spec fn subrange_nested(s1: Seq>, s: usize, e: usize, s2: Seq>) -> bool recommends 0 <= s <= e <= s1.len() { s1.subrange(s as int, e as int) == s2 } spec fn subrange_struct(s1: Seq, s: usize, e: usize, s2: Seq) -> bool recommends 0 <= s <= e <= s1.len() { s1.subrange(s as int, e as int) == s2 } spec fn take_eq(s1: Seq, n: usize, s2: Seq) -> bool recommends 0 <= n <= s1.len() { s1.take(n as int) == s2 } spec fn take_nested(s1: Seq>, n: usize, s2: Seq>) -> bool recommends 0 <= n <= s1.len() { s1.take(n as int) == s2 } spec fn take_struct(s1: Seq, n: usize, s2: Seq) -> bool recommends 0 <= n <= s1.len() { s1.take(n as int) == s2 } spec fn to_multiset_eq(s: Seq, m: Multiset) -> bool { s.to_multiset() == m } spec fn seq_to_multiset_count(s: Seq, m: Multiset, e: u8) -> bool { s.to_multiset().count(e) == m.count(e) } spec fn update_eq(s1: Seq, i: usize, x: u8, s2: Seq) -> bool recommends 0 <= i < s1.len() { s1.update(i as int, x) == s2 } spec fn update_nested(s1: Seq>, i: usize, x: Seq, s2: Seq>) -> bool recommends 0 <= i < s1.len() { s1.update(i as int, x) == s2 } spec fn update_struct(s1: Seq, i: usize, x: Data, s2: Seq) -> bool recommends 0 <= i < s1.len() { s1.update(i as int, x) == s2 } } } => Ok(()) } test_verify_one_file! { #[test] test_exec_spec_seq_update IMPORTS.to_string() + verus_code_str! { fn test_update() { let v = vec![1u8]; let updated = v.as_slice().exec_update(0, 2); assert(updated.deep_view() =~= seq![2u8]); } } => Ok(()) } test_verify_one_file! { #[test] test_exec_spec_seq_update_requires IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn update_at(s: Seq, i: usize, x: u8) -> Seq { s.update(i as int, x) // FAILS } } fn test_update() { let v = vec![1u8]; let _ = v.as_slice().exec_update(1, 2); // FAILS } } => Err(err) => assert_fails(err, 2) } test_verify_one_file! { /// A key whose deep view forgets data that `Eq` compares cannot be used /// with the hash-based translations. #[test] test_exec_spec_lossy_key_rejected IMPORTS.to_string() + verus_code_str! { #[derive(PartialEq, Eq, Hash)] pub struct K(pub u64); impl DeepView for K { type V = (); open spec fn deep_view(&self) -> () { () } } impl DeepViewClone for K { fn deep_clone(&self) -> (res: Self) { K(self.0) } } fn insert(m: &HashMap) -> HashMap { <&HashMap as ExecSpecMapInsert>>::exec_insert(m, K(1), 7u64) } } => Err(err) => assert_rust_error_msg(err, "ObeysDeepEq") } test_verify_one_file! { /// ... and such a key cannot prove that it obeys deep equality. #[test] test_exec_spec_lossy_key_law_fails IMPORTS.to_string() + verus_code_str! { #[derive(PartialEq, Eq, StructuralEq)] pub struct K(pub u64); impl DeepView for K { type V = (); open spec fn deep_view(&self) -> () { () } } impl ObeysDeepEq for K { proof fn lemma_obeys_deep_eq() { reveal(vstd::laws_eq::obeys_deep_eq); } } } => Err(err) => assert_vir_error_msg(err, "postcondition not satisfied") } test_verify_one_file! { /// The generated `PartialEq` of exec types decides deep-view equality. #[test] test_exec_spec_generated_obeys_deep_eq IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Data { pub x: u8, pub s: Seq, } pub enum Shape { Dot, Line(u8, u8), Named { name: SpecString, n: Option }, } } fn data_eq(a: &ExecData, b: &ExecData) -> (r: bool) ensures r == (a.deep_view() == b.deep_view()), { a == b } fn shape_eq(a: &ExecShape, b: &ExecShape) -> (r: bool) ensures r == (a.deep_view() == b.deep_view()), { a == b } proof fn key_laws() { <(ExecShape, Vec) as ObeysDeepEq>::lemma_obeys_deep_eq(); assert(vstd::laws_eq::obeys_deep_eq::<(ExecShape, Vec)>()); } } => Ok(()) } /// Runs the compiled translations whose results depend on `==`. #[test] fn test_exec_spec_deep_eq_runtime() { let source = code_str! { use vstd::prelude::*; use vstd::contrib::exec_spec::*; use vstd::multiset::*; use std::collections::{HashMap, HashSet}; verus! { // The deep view forgets all but the parity, and so does `==`. pub struct K(pub u8); impl DeepView for K { type V = bool; open spec fn deep_view(&self) -> bool { self.0 % 2 == 0 } } impl PartialEq for K { fn eq(&self, other: &K) -> bool { self.0 % 2 == other.0 % 2 } } impl vstd::std_specs::cmp::PartialEqSpecImpl for K { open spec fn obeys_eq_spec() -> bool { true } open spec fn eq_spec(&self, other: &K) -> bool { self.deep_view() == other.deep_view() } } impl ObeysDeepEq for K { proof fn lemma_obeys_deep_eq() { reveal(vstd::laws_eq::obeys_deep_eq); } } fn contains_other() -> (b: bool) ensures b, { let values = vec![K(2)]; let s = values.as_slice(); assert(s.deep_view() =~= seq![true]); assert(s.deep_view()[0]); s.exec_contains(K(4)) } exec_spec_verified! { pub struct Data { pub x: u8, pub s: Seq, } spec fn data_set_len(m: Set, k: Data) -> usize recommends m.len() < usize::MAX { m.insert(k).len() as usize } spec fn multiset_eq(a: Multiset, b: Multiset) -> bool { a == b } } // A count of 0 is the same as an absent element. fn zero_count_is_empty() -> (b: bool) ensures b, { let mut m = HashMap::new(); m.insert(1u8, 0usize); let a = ExecMultiset { m }; let e = ExecMultiset { m: HashMap::new() }; proof { broadcast use vstd::std_specs::hash::group_hash_axioms; broadcast use vstd::std_specs::hash::lemma_hashmap_deepview_properties; assert(a.deep_view() =~= Multiset::::empty()); assert(e.deep_view() =~= Multiset::::empty()); } exec_multiset_eq(&a, &e) } } fn main() { assert!(contains_other()); let values = [K(1), K(2), K(4)]; let s = values.as_slice(); assert!(s.exec_contains(K(6))); assert_eq!(s.exec_index_of(K(6)), 1); assert_eq!(s.exec_index_of_first(K(6)), Some(1)); assert_eq!(s.exec_index_of_last(K(6)), Some(2)); let values = [K(1), K(3)]; let s = values.as_slice(); assert!(!s.exec_contains(K(2))); assert_eq!(s.exec_index_of(K(2)), 2); assert_eq!(s.exec_index_of_first(K(2)), None); assert_eq!(s.exec_index_of_last(K(2)), None); let mut set = HashSet::new(); set.insert(ExecData { x: 1, s: vec![1, 2] }); assert_eq!(exec_data_set_len(&set, &ExecData { x: 1, s: vec![1, 2] }), 1); assert_eq!(exec_data_set_len(&set, &ExecData { x: 1, s: vec![] }), 2); assert!(zero_count_is_empty()); } }; let tempdir = tempfile::tempdir().unwrap(); let entry_file = tempdir.path().join("deep_eq.rs"); std::fs::write(&entry_file, format!("{FEATURE_PRELUDE}\n{USE_PRELUDE}\n{source}")).unwrap(); let output = run_verus_raw(&["--compile", entry_file.to_str().unwrap()], tempdir.path()); assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr)); let binary = tempdir.path().join(if cfg!(windows) { "deep_eq.exe" } else { "deep_eq" }); let output = std::process::Command::new(binary).output().unwrap(); assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr)); } test_verify_one_file! { /// Tests support for functions on Set. #[test] test_exec_spec_set IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Inner { i: i64 } pub struct Data { x: u8, y: Seq, z: (u8, u8, Inner), } spec fn contains_eq(m1: Set, k: u8) -> bool { m1.contains(k) } spec fn contains_nested(m1: Set>, k: Seq) -> bool { m1.contains(k) } spec fn contains_struct(m1: Set, k: Data) -> bool { m1.contains(k) } spec fn difference_eq(m1: Set, m2: Set, m3: Set) -> bool { m1.difference(m2) == m3 } spec fn difference_nested(m1: Set>, m2: Set>, m3: Set>) -> bool { m1.difference(m2) == m3 } spec fn difference_struct(m1: Set, m2: Set, m3: Set) -> bool { m1.difference(m2) == m3 } spec fn empty_set() -> Set { Set::empty() } spec fn empty_set_length_zero() -> bool { empty_set().len() == 0 } spec fn insert_eq(m1: Set, k: u8, m2: Set) -> bool { m1.insert(k) == m2 } spec fn insert_nested(m1: Set>, k: Seq, m2: Set>) -> bool { m1.insert(k) == m2 } spec fn insert_struct(m1: Set, k: Data, m3: Set) -> bool { m1.insert(k) == m3 } spec fn intersect_eq(m1: Set, m2: Set, m3: Set) -> bool { m1.intersect(m2) == m3 } spec fn intersect_nested(m1: Set>, m2: Set>, m3: Set>) -> bool { m1.intersect(m2) == m3 } spec fn intersect_struct(m1: Set, m2: Set, m3: Set) -> bool { m1.intersect(m2) == m3 } spec fn len_eq(m1: Set, n: usize) -> bool { m1.len() == n as int } spec fn len_struct(m1: Set, n: usize) -> bool { m1.len() == n as int } spec fn remove_eq(m1: Set, k: u8, m2: Set) -> bool { m1.remove(k) == m2 } spec fn remove_nested(m1: Set>, k: Seq, m2: Set>) -> bool { m1.remove(k) == m2 } spec fn remove_struct(m1: Set, k: Data, m2: Set) -> bool { m1.remove(k) == m2 } spec fn union_eq(m1: Set, m2: Set, m3: Set) -> bool { m1.union(m2) == m3 } spec fn union_nested(m1: Set>, m2: Set>, m3: Set>) -> bool { m1.union(m2) == m3 } spec fn union_struct(m1: Set, m2: Set, m3: Set) -> bool { m1.union(m2) == m3 } } } => Ok(()) } test_verify_one_file! { /// Tests support for functions on Map. #[test] test_exec_spec_map IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Inner { i: i64 } pub struct Data { x: u8, y: Seq, z: (u8, u8, Inner), } spec fn dom_eq(m1: Map, s: Set) -> bool { m1.dom() == s } spec fn dom_struct(m1: Map, s: Set) -> bool { m1.dom() == s } spec fn empty_map() -> Map { Map::empty() } spec fn empty_map_length_zero() -> bool { empty_map().len() == 0 } spec fn get_eq(m1: Map, k: u8, v: u8) -> bool { m1.get(k) == Some(v) } spec fn get_nested(m1: Map, u8>, k: Seq, v: u8) -> bool { m1.get(k) == Some(v) } spec fn get_struct(m1: Map, k: Data, v: u8) -> bool { m1.get(k) == Some(v) } spec fn index_eq(m1: Map, k: u8, v: u8) -> bool recommends m1.dom().contains(k) { m1[k] == v } spec fn index_method_eq(m1: Map, k: u8, v: u8) -> bool recommends m1.dom().contains(k) { m1.index(k) == v } spec fn insert_eq(m1: Map, k: u8, v: u8, m2: Map) -> bool { m1.insert(k, v) == m2 } spec fn insert_nested(m1: Map, u8>, k: Seq, v: u8, m2: Map, u8>) -> bool { m1.insert(k, v) == m2 } spec fn insert_nested_key(m1: Map, Seq>, k: Seq, v: Seq, m2: Map, Seq>) -> bool { m1.insert(k, v) == m2 } spec fn insert_struct(m1: Map, k: Data, v: u8, m2: Map) -> bool { m1.insert(k, v) == m2 } spec fn len_eq(m1: Map, n: usize) -> bool { m1.len() == n as int } spec fn len_struct(m1: Map, n: usize) -> bool { m1.len() == n as int } spec fn remove_eq(m1: Map, k: u8, m2: Map) -> bool { m1.remove(k) == m2 } spec fn remove_nested(m1: Map, u8>, k: Seq, m2: Map, u8>) -> bool { m1.remove(k) == m2 } spec fn remove_struct(m1: Map, k: Data, m2: Map) -> bool { m1.remove(k) == m2 } } } => Ok(()) } test_verify_one_file! { /// Tests support for functions on Multiset. #[test] test_exec_spec_multiset IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Inner { i: i64 } pub struct Data { x: u8, y: Seq, z: (u8, u8, Inner), } spec fn add_eq(m1: Multiset, m2: Multiset, m3: Multiset) -> bool { m1.add(m2) == m3 } spec fn add_nested(m1: Multiset>, m2: Multiset>, m3: Multiset>) -> bool { m1.add(m2) == m3 } spec fn add_struct(m1: Multiset, m2: Multiset, m3: Multiset) -> bool { m1.add(m2) == m3 } spec fn count_eq(s: Multiset, value: u8, c: usize) -> bool { s.count(value) == c as nat } spec fn count_nested(s: Multiset>>, value: Seq>, c: usize) -> bool { s.count(value) == c as nat } spec fn count_struct(s: Multiset, value: Data, c: usize) -> bool { s.count(value) == c as nat } spec fn empty_multiset() -> Multiset { Multiset::empty() } spec fn empty_multiset_length_zero() -> bool { empty_multiset().len() == 0 } spec fn test(s: Multiset, i: usize) -> bool { s.len() == i as nat } spec fn test_struct(s: Multiset, i: usize) -> bool { s.len() == i as nat } spec fn singleton_eq(v: u8, m: Multiset) -> bool { Multiset::singleton(v) == m } spec fn singleton_nested(v: Seq, m: Multiset>) -> bool { Multiset::singleton(v) == m } spec fn singleton_struct(v: Data, m: Multiset) -> bool { Multiset::singleton(v) == m } spec fn sub_eq(m1: Multiset, m2: Multiset, m3: Multiset) -> bool { m1.sub(m2) == m3 } spec fn sub_nested(m1: Multiset>, m2: Multiset>, m3: Multiset>) -> bool { m1.sub(m2) == m3 } spec fn sub_struct(m1: Multiset, m2: Multiset, m3: Multiset) -> bool { m1.sub(m2) == m3 } } } => Ok(()) } test_verify_one_file! { /// Tests struct/enum constructors. #[test] test_exec_spec_constructor IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { struct A { a: u32, b: u32, } enum B { C { a: A, } } spec fn test_struct(a: u32, b: u32) -> A { A { a, b } } spec fn test_struct2(a: A) -> (B, (B, B)) { let x = B::C { a }; let y = B::C { a: test_struct(a.a, a.b), }; (B::C { a: A { a: a.a, b: a.b, }, }, (x, y)) } } } => Ok(()) } test_verify_one_file! { /// Tests `matches`. #[test] test_exec_spec_matches IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { enum D { E, F } enum C { A, B(D) } spec fn test_matches1(x: C) -> bool { ||| x matches C::B(y) && y matches D::E ||| x matches C::B(D::F) ==> x matches C::A ||| { &&& x matches C::B(z) &&& z matches D::F } } spec fn test_matches2(x: Option>) -> bool { ||| x matches Some(_) ||| x matches Some(Some(x)) ==> x matches C::A } } } => Ok(()) } test_verify_one_file! { /// Tests support for recursions and `decreases` clauses. #[test] test_exec_spec_recursion IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test_recursion1(n: usize) -> usize decreases n { if n == 0 { 0 } else { test_recursion1((n - 1) as usize) } } spec fn test_recursion2(n: i32) -> i32 decreases n when n >= 0 { if n == 0 { 1 } else { test_recursion2((n - 1) as i32) } } } } => Ok(()) } test_verify_one_file! { /// Tests support for recursion with sequence. #[test] test_exec_spec_recursion_seq IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test_all_positive(a: Seq, i: usize) -> bool recommends 0 <= i < a.len() decreases a.len() - i when i < usize::MAX { &&& a[i as int] > 0 &&& i + 1 < a.len() ==> test_all_positive(a, (i + 1) as usize) } } } => Ok(()) } test_verify_one_file! { /// Tests support for some built-in constants. #[test] test_exec_spec_constant IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test(i: usize) -> bool { usize::MAX - i != 0 } } } => Ok(()) } test_verify_one_file! { /// Tests interoperability and generated post/pre-conditions #[test] test_exec_spec_interop1 IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn test_all_positive(a: Seq, i: usize) -> bool recommends 0 <= i < a.len() decreases a.len() - i when i < usize::MAX { &&& a[i as int] > 0 &&& i + 1 < a.len() ==> test_all_positive(a, (i + 1) as usize) } } fn sanity_check() { reveal_with_fuel(test_all_positive, 3); assert(test_all_positive(seq![1, 2, 3], 0)); let res = exec_test_all_positive(&[1, 2, 3], 0); assert(res); } } => Ok(()) } test_verify_one_file! { /// Tests interoperability and generated post/pre-conditions. #[test] test_exec_spec_interop2 IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { struct A { a: u32, b: u32, } spec fn pred(a: A) -> bool { a.a > a.b } } fn sanity_check() { let a = ExecA { a: 3, b: 2 }; if exec_pred(&a) { assert(a.a > a.b); } } } => Ok(()) } test_verify_one_file! { /// Tests interoperability and generated post/pre-conditions. #[test] test_exec_spec_interop3 IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { struct MyPair(Seq, Seq); spec fn pred_helper(a: Seq, b: Seq, i: usize) -> bool recommends 0 <= i < a.len() == b.len() decreases a.len() - i when i < usize::MAX { &&& a[i as int] > b[i as int] &&& i + 1 < a.len() ==> pred_helper(a, b, (i + 1) as usize) } spec fn pred(p: MyPair) -> bool recommends p.0.len() == p.1.len() { if p.0.len() == 0 { true } else { pred_helper(p.0, p.1, 0) } } } fn test() { let a = ExecMyPair(vec![1, 2, 3], vec![0, 1, 2]); reveal_with_fuel(pred_helper, 3); if exec_pred(&a) { assert(a.0@[0] > a.1@[0]); assert(a.0@[1] > a.1@[1]); assert(a.0@[2] > a.1@[2]); } else { assert(a.0@[0] <= a.1@[0] || a.0@[1] <= a.1@[1] || a.0@[2] <= a.1@[2]); } } } => Ok(()) } test_verify_one_file! { /// Tests that error spans are accurate. #[test] test_exec_spec_error_span IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { struct MyPair(Seq, Seq); spec fn pred(p: MyPair) -> bool recommends p.0.len() != 0 { p.0[0] + 10 > 100 // FAILS } } } => Err(err) => assert_fails(err, 1) } test_verify_one_file! { /// Tests that linear variables are compiled correctly. #[test] test_exec_spec_linear IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { struct B; struct A { x: B, y: B, } spec fn test1(a: A) -> bool { let b = a; let c = b; let d = b; true } spec fn test2(a: A) -> B { let b = a.x; let e = { let c = b; let d = b; d }; e } } } => Ok(()) } test_verify_one_file! { /// Tests complex structs/enums from the X.509 project. #[test] test_exec_spec_certificate IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Attribute { pub oid: SpecString, pub value: SpecString, } pub struct DistinguishedName(pub Seq>); pub enum GeneralName { DNSName(SpecString), DirectoryName(DistinguishedName), IPAddr(Seq), OtherName, Unsupported, } pub enum SubjectKey { RSA { mod_length: usize, }, DSA { p_len: usize, q_len: usize, g_len: usize, }, Other, } pub struct AuthorityKeyIdentifier { pub critical: Option, pub key_id: Option, pub issuer: Option, pub serial: Option, } pub struct SubjectKeyIdentifier { pub critical: Option, pub key_id: SpecString, } pub enum ExtendedKeyUsageType { ServerAuth, ClientAuth, CodeSigning, EmailProtection, TimeStamping, OCSPSigning, Any, Other(SpecString), } pub struct ExtendedKeyUsage { pub critical: Option, pub usages: Seq, } pub struct BasicConstraints { pub critical: Option, pub is_ca: bool, pub path_len: Option, } pub struct KeyUsage { pub critical: Option, pub digital_signature: bool, pub non_repudiation: bool, pub key_encipherment: bool, pub data_encipherment: bool, pub key_agreement: bool, pub key_cert_sign: bool, pub crl_sign: bool, pub encipher_only: bool, pub decipher_only: bool, } pub struct SubjectAltName { pub critical: Option, pub names: Seq, } pub struct NameConstraints { pub critical: Option, pub permitted: Seq, pub excluded: Seq, } pub struct CertificatePolicies { pub critical: Option, pub policies: Seq, } pub struct AuthorityInfoAccess { pub critical: Option, // Other info is not encoded } pub struct SignatureAlgorithm { pub id: SpecString, pub bytes: SpecString, } pub struct Extension { pub oid: SpecString, pub critical: Option, } pub struct Certificate { pub fingerprint: SpecString, pub version: u32, pub serial: SpecString, pub sig_alg_outer: SignatureAlgorithm, pub sig_alg_inner: SignatureAlgorithm, pub not_after: u64, pub not_before: u64, pub issuer: DistinguishedName, pub subject: DistinguishedName, pub subject_key: SubjectKey, pub issuer_uid: Option, pub subject_uid: Option, pub ext_authority_key_id: Option, pub ext_subject_key_id: Option, pub ext_extended_key_usage: Option, pub ext_basic_constraints: Option, pub ext_key_usage: Option, pub ext_subject_alt_name: Option, pub ext_name_constraints: Option, pub ext_certificate_policies: Option, pub ext_authority_info_access: Option, // All extensions without parameters pub all_exts: Option>, } pub enum Purpose { ServerAuth, } pub struct Task { pub hostname: Option, pub purpose: Purpose, pub now: u64, } pub enum PolicyError { UnsupportedTask, } } } => Ok(()) } test_verify_one_file! { /// Tests basic `forall` expressions. #[test] test_exec_spec_basic_forall IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn zero_vec(a: Seq) -> bool { forall |i: usize| 0 <= i < a.len() ==> a[i as int] != 0 } } fn sanity_check() { let v = vec![1, 2, 3]; if exec_zero_vec(&v) { assert(v.deep_view()[0] != 0); } } } => Ok(()) } test_verify_one_file! { /// Tests basic `exists` expressions. #[test] test_exec_spec_basic_exists IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn non_zero_vec(a: Seq) -> bool { exists |i: usize| 0 <= i < a.len() && a[i as int] != 0 } } fn sanity_check() { let v = vec![1, 2, 3]; if exec_non_zero_vec(&v) { assert(non_zero_vec(v.deep_view())); assert(exists |i: usize| 0 <= i < v.deep_view().len() && v.deep_view()[i as int] != 0); } } } => Ok(()) } test_verify_one_file! { /// Tests different bound expressions for quantifiers #[test] test_exec_spec_quant_bounds IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn eq_0(i: usize) -> bool { i == 0 } spec fn eq_10(i: usize) -> bool { i == 10 } spec fn neq_0(i: usize) -> bool { i != 0 } spec fn neq_10(i: usize) -> bool { i != 10 } spec fn le_le_0_10(i: usize) -> bool { 0 <= i && i <= 10 } spec fn lt_lt_forall() -> bool { forall |i: usize| 0 < i < 10 ==> neq_0(i) && neq_10(i) } spec fn le_lt_forall() -> bool { forall |i: usize| 0 <= i < 10 ==> neq_10(i) } spec fn lt_le_forall() -> bool { forall |i: usize| 0 < i <= 10 ==> neq_0(i) } spec fn le_le_forall() -> bool { forall |i: usize| 0 <= i <= 10 ==> le_le_0_10(i) } spec fn lt_lt_exists() -> bool { !(exists |i: usize| 0 < i < 10 && (eq_0(i) || eq_10(i))) } spec fn le_lt_exists() -> bool { exists |i: usize| 0 <= i < 10 && eq_0(i) } spec fn lt_le_exists() -> bool { exists |i: usize| 0 < i <= 10 && eq_10(i) } spec fn le_le_exists() -> bool { exists |i: usize| 0 <= i <= 10 && eq_10(i) } } } => Ok(()) } test_verify_one_file! { /// Tests nested `forall`s. #[test] test_exec_spec_nested_foralls IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn distinct(a: Seq) -> bool { forall |i: usize| #![trigger a[i as int]] 0 <= i < a.len() ==> forall |j: usize| #![trigger a[j as int]] 0 <= j < i ==> a[i as int] != a[j as int] } } fn sanity_check(v: Vec) { if exec_distinct(&v) { assert(v.deep_view().len() >= 2 ==> v.deep_view()[0] != v.deep_view()[1]); } } } => Ok(()) } test_verify_one_file! { /// Tests nested `exists`s. #[test] test_exec_spec_nested_exists IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn has_duplicate(a: Seq) -> bool { exists |i: usize| #![trigger a[i as int]] 0 <= i < a.len() && exists |j: usize| #![trigger a[j as int]] 0 <= j < i && a[i as int] == a[j as int] } } fn sanity_check(v: Vec) { if exec_has_duplicate(&v) { assert(v.deep_view().len() == 2 ==> v.deep_view()[0] == v.deep_view()[1]); } } } => Ok(()) } test_verify_one_file! { /// Tests alternating quantifiers. /// Currently ignored because it contains a trigger loop and is thus flaky. #[ignore] #[test] test_exec_spec_alt_quants IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { spec fn has_unique_maximum(a: Seq) -> bool { exists |i: usize| #![trigger a[i as int]] 0 <= i < a.len() && forall |j: usize| #![trigger a[j as int]] 0 <= j < a.len() ==> i == j || a[i as int] > a[j as int] } } fn sanity_check(v: Vec) { if exec_has_unique_maximum(&v) { assert(v.deep_view().len() == 2 ==> v.deep_view()[0] > v.deep_view()[1] || v.deep_view()[0] < v.deep_view()[1]); } } } => Ok(()) } test_verify_one_file! { /// Inherent impl on a struct: `&self` method using fields, with `recommends` /// referencing `self` as well. #[test] test_exec_spec_impl_struct IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Pair { pub x: u32, pub y: u32, } impl Pair { pub open spec fn sum(&self) -> u32 recommends self.x + self.y <= u32::MAX { (self.x + self.y) as u32 } pub open spec fn max(&self) -> u32 { if self.x >= self.y { self.x } else { self.y } } } } } => Ok(()) } test_verify_one_file! { /// Inherent impl on an enum: `&self` method using `match self`. #[test] test_exec_spec_impl_enum IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub enum E { A(u32), B { v: u32 }, C, } impl E { pub open spec fn tag(&self) -> u32 { match self { E::A(_) => 0, E::B { .. } => 1, E::C => 2, } } pub open spec fn is_c(&self) -> bool { match self { E::C => true, _ => false, } } } } } => Ok(()) } test_verify_one_file! { /// Recursive method with `decreases` referencing `self`. #[test] test_exec_spec_impl_self_recursion IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Counter { pub n: u32, } impl Counter { pub open spec fn count_down(&self) -> u32 decreases self.n { if self.n == 0 { 0 } else { let next = Counter { n: (self.n - 1) as u32 }; next.count_down() } } } } } => Ok(()) } test_verify_one_file! { /// Recursive method on an enum (linked list shape). #[test] test_exec_spec_impl_enum_recursion IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub enum List { Cons(u32, Seq), Nil, } impl List { pub open spec fn is_nil(&self) -> bool { match self { List::Cons(..) => false, List::Nil => true, } } } // Free-standing recursion that calls a method on each step. spec fn count_nils(l: List, n: usize) -> u32 decreases n { if n == 0 { 0 } else if l.is_nil() { 1 } else { 0 } } } } => Ok(()) } test_verify_one_file! { /// `decreases ... when ...` clause referencing `self`, using a `decreases self` pattern. #[test] test_exec_spec_impl_decreases_when IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Counter { pub n: i32, } impl Counter { pub open spec fn down(&self) -> i32 decreases self.n when self.n >= 0 { if self.n == 0 { 1 } else { let next = Counter { n: (self.n - 1) as i32 }; next.down() } } } } } => Ok(()) } test_verify_one_file! { /// Method body uses `match self` and post-condition `=~~=` against the /// spec's match result, exercising the deep-view ext-eq path. #[test] test_exec_spec_impl_matching_spec IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub enum Shape { Square, Rect, } impl Shape { pub open spec fn is_square(&self) -> bool { match self { Shape::Square => true, Shape::Rect => false, } } pub open spec fn is_rect(&self) -> bool { match self { Shape::Square => false, Shape::Rect => true, } } } } } => Ok(()) } test_verify_one_file! { /// Free-standing function calls a user-defined method (exercises the /// `Expr::MethodCall` fallthrough into `exec_`). #[test] test_exec_spec_impl_method_call_site IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Pair { pub x: u32, pub y: u32, } impl Pair { pub open spec fn sum(&self) -> u32 recommends self.x <= 1000, self.y <= 1000 { (self.x + self.y) as u32 } } spec fn add_pairs(p: Pair, q: Pair) -> u32 recommends p.x <= 1000, p.y <= 1000, q.x <= 1000, q.y <= 1000, { (p.sum() + q.sum()) as u32 } } } => Ok(()) } test_verify_one_file! { /// `&self` is supported. Using `self` by value or `&mut self` is rejected. #[test] test_exec_spec_impl_ref_self_supported IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct W { pub v: u32 } impl W { pub open spec fn get(&self) -> u32 { self.v } } } } => Ok(()) } test_verify_one_file! { /// `self` by value is rejected with a clear error. #[test] test_exec_spec_impl_value_self_rejected IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct W { pub v: u32 } impl W { pub open spec fn get(self) -> u32 { self.v } } } } => Err(err) => assert_vir_error_msg(err, "only `&self` is supported") } test_verify_one_file! { /// `&mut self` is rejected (spec methods are pure). #[test] test_exec_spec_impl_mut_self_rejected IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct W { pub v: u32 } impl W { pub open spec fn get(&mut self) -> u32 { self.v } } } } => Err(err) => assert_vir_error_msg(err, "`&mut self` is not supported") } test_verify_one_file! { /// Trait impls are not supported in `exec_spec_verified!`. #[test] test_exec_spec_impl_trait_rejected IMPORTS.to_string() + verus_code_str! { trait MyTrait { spec fn label() -> u32; } exec_spec_verified! { pub struct S { pub v: u32 } impl MyTrait for S { open spec fn label() -> u32 { 0 } } } } => Err(err) => assert_vir_error_msg(err, "trait impls not supported in exec_spec") } test_verify_one_file! { /// Generic impls are not supported. #[test] test_exec_spec_impl_generics_rejected IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct W { pub v: u32 } impl W { pub open spec fn get(&self) -> u32 { self.v } } } } => Err(err) => assert_vir_error_msg(err, "generics not supported") } test_verify_one_file! { /// Mix of `pub closed` and `pub open` spec functions in the same macro /// invocation. #[test] test_exec_spec_closed_and_open_fns IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub closed spec fn squared(x: u32) -> u32 recommends x * x <= u32::MAX { (x * x) as u32 } pub open spec fn doubled(x: u32) -> u32 recommends x + x <= u32::MAX { (x + x) as u32 } } } => Ok(()) } test_verify_one_file! { /// Closed spec methods inside an impl block. #[test] test_exec_spec_impl_closed_method IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Pair { pub x: u32, pub y: u32, } impl Pair { pub closed spec fn sum(&self) -> u32 recommends self.x + self.y <= u32::MAX { (self.x + self.y) as u32 } pub open spec fn max(&self) -> u32 { if self.x >= self.y { self.x } else { self.y } } } } } => Ok(()) } test_verify_one_file! { /// `&&&` and `|||` (BigAnd / BigOr) inside impl method bodies and inside /// `recommends` clauses. #[test] test_exec_spec_impl_big_and_or IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct Triple { pub a: u32, pub b: u32, pub c: u32, } impl Triple { pub open spec fn all_small(&self) -> bool { &&& self.a <= 10 &&& self.b <= 10 &&& self.c <= 10 } pub open spec fn any_small(&self) -> bool { ||| self.a <= 10 ||| self.b <= 10 ||| self.c <= 10 } pub open spec fn well_formed(&self) -> u32 recommends self.a <= 100, self.b <= 100, self.c <= 100, { (self.a + self.b + self.c) as u32 } } } } => Ok(()) } test_verify_one_file! { /// `e is Variant` over user-defined enums with all three variant shapes /// (named, tuple, unit). Also `isnt`. #[test] test_exec_spec_is_user_enum IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub enum E { Named { v: u32 }, Tuple(u32), Unit, } pub open spec fn classify(e: E) -> u32 { if e is Named { 1 } else if e is Tuple { 2 } else { 3 } } pub open spec fn not_named(e: E) -> bool { e isnt Named } } } => Ok(()) } test_verify_one_file! { /// `e is Variant` on `Option`. #[test] test_exec_spec_is_option IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub open spec fn is_some(o: Option) -> bool { o is Some } pub open spec fn is_none(o: Option) -> bool { o is None } pub open spec fn not_some(o: Option) -> bool { o isnt Some } } } => Ok(()) } test_verify_one_file! { /// Tests prefix deref `*self` in a spec method body (exercises `UnOp::Deref`). #[test] test_exec_spec_impl_deref_self IMPORTS.to_string() + verus_code_str! { exec_spec_verified! { pub struct W { pub v: u32 } impl W { pub open spec fn copy(&self) -> W { *self } } } fn sanity_check() { let w = ExecW { v: 7 }; let c = w.exec_copy(); assert(c.v == 7); } } => Ok(()) }