Skip to content

Commit

Permalink
fix a test
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhance committed Jun 5, 2023
1 parent 241b80a commit 4dd0213
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion source/rust_verify/src/lifetime_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ fn erase_expr<'tcx>(
mk_exp(ExpX::Op(vec![], typ))
}
}
Res::Def(DefKind::Const | DefKind::Fn, id) => {
Res::Def(DefKind::Const | DefKind::Fn | DefKind::AssocFn, id) => {
let vir_path = def_id_to_vir_path(ctxt.tcx, id);
let fun_name = Arc::new(FunX { path: vir_path });
return mk_exp(ExpX::Var(state.fun_name(&fun_name)));
Expand Down
2 changes: 1 addition & 1 deletion source/rust_verify/src/rust_to_vir_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,7 @@ pub(crate) fn expr_to_vir_innermost<'tcx>(
let fun = FunX { path };
mk_expr(ExprX::ConstVar(Arc::new(fun)))
}
Res::Def(DefKind::Fn, id) => {
Res::Def(DefKind::Fn, id) | Res::Def(DefKind::AssocFn, id) => {
let path = def_id_to_vir_path(tcx, id);
let fun = Arc::new(vir::ast::FunX { path });
mk_expr(ExprX::ExecFnByName(fun))
Expand Down
46 changes: 23 additions & 23 deletions source/rust_verify_test/tests/fndef_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ test_verify_one_file_with_options! {
}

test_verify_one_file_with_options! {
#[test] basic_with_trait ["vstd"] => verus_code! {
trait Tr {
fn llama(&self, y: &Self, z: &Self) -> (b: bool)
#[test] with_trait ["vstd"] => verus_code! {
trait Tr : Sized {
fn llama(self, y: Self, z: Self) -> (b: bool)
requires self == y,
ensures b == (y == z);
}
Expand All @@ -186,7 +186,7 @@ test_verify_one_file_with_options! {
}

impl Tr for X {
fn llama(&self, y: &Self, z: &Self) -> (b: bool)
fn llama(self, y: Self, z: Self) -> (b: bool)
{
assume(false);
true
Expand All @@ -200,28 +200,28 @@ test_verify_one_file_with_options! {
let y = X { t: 4 };
let z = X { t: 6 };

let b = t(&x, &y, &z);
let b = t(x, y, z);
assert(!b);

let x = X { t: 4 };
let y = X { t: 4 };
let z = X { t: 4 };

let b = t(&x, &y, &z);
let b = t(x, y, z);
assert(b);

assert(forall |x: X, y: X, z: X| (x == y) ==> (X::llama).requires((&x,&y,&z)));
assert(forall |x: X, y: X, z: X, b| (X::llama).ensures((&x,&y,&z),b) ==> b == (y == z));
assert(forall |x: X, y: X, z: X| (x == y) ==> (X::llama).requires((x,y,z)));
assert(forall |x: X, y: X, z: X, b| (X::llama).ensures((x,y,z),b) ==> b == (y == z));
}

fn test2() {
let t = <X as Tr>::llama;

let x = X { t: 4 };
let y = X { t: 4 };
let z = X { t: 6 };
let z = X { t: 4 };

let b = t(&x, &y, &z);
let b = t(x, y, z);
assert(!b); // FAILS
}

Expand All @@ -232,52 +232,52 @@ test_verify_one_file_with_options! {
let y = X { t: 13 };
let z = X { t: 14 };

t(&x, &y, &z); // FAILS
t(x, y, z); // FAILS
}

fn test4() {
assert(forall |x: X, y: X, z: X| (y == z) ==> (X::llama).requires((&x,&y,&z))); // FAILS
assert(forall |x: X, y: X, z: X| (y == z) ==> (X::llama).requires((x,y,z))); // FAILS
}

fn test5() {
assert(forall |x: X, y: X, z: X, b| (X::llama).ensures((&x,&y,&z),b) ==> b == (y != z)); // FAILS
assert(forall |x: X, y: X, z: X, b| (X::llama).ensures((x,y,z),b) ==> b == (y != z)); // FAILS
}

fn takes_fn1<F: Fn(&X, &X, &X) -> bool>(f: F)
fn takes_fn1<F: Fn(X, X, X) -> bool>(f: F)
requires
f.requires((&X { t: 4 }, &X { t: 4 } , &X { t: 4 })),
f.requires((&X { t: 7 }, &X { t: 7 } , &X { t: 4 })),
forall |x: X, y: X, z: X, b| f.ensures((&x,&y,&z), b) ==> b == (y == z)
f.requires((X { t: 4 }, X { t: 4 } , X { t: 4 })),
f.requires((X { t: 7 }, X { t: 7 } , X { t: 4 })),
forall |x: X, y: X, z: X, b| f.ensures((x,y,z), b) ==> b == (y == z)
{
}

fn test_take1() {
takes_fn1(X::llama);
}

fn takes_fn2<F: Fn(&X, &X, &X) -> bool>(f: F)
fn takes_fn2<F: Fn(X, X, X) -> bool>(f: F)
requires
f.requires((&X { t: 6 }, &X { t: 7 }, &X { t: 8 })),
f.requires((X { t: 6 }, X { t: 7 }, X { t: 8 })),
{
}

fn test_take2() {
takes_fn2(X::llama); // FAILS
}

fn takes_fn3<F: Fn(&X, &X, &X) -> bool>(f: F)
fn takes_fn3<F: Fn(X, X, X) -> bool>(f: F)
requires
forall |x: X, y: X, z: X, b| f.ensures((&x,&y,&z), b) ==> b == (y != z)
forall |x: X, y: X, z: X, b| f.ensures((x,y,z), b) ==> b == (y != z)
{
}

fn test_take3() {
takes_fn3(X::llama); // FAILS
}

fn takes_fn4<T, F: Fn(&T, &T, &T) -> bool>(f: F)
fn takes_fn4<T, F: Fn(T, T, T) -> bool>(f: F)
requires
forall |x: T, y: T, z: T, b| f.ensures((&x,&y,&z), b) ==> b == (y != z)
forall |x: T, y: T, z: T, b| f.ensures((x,y,z), b) ==> b == (y != z)
{
}

Expand Down

0 comments on commit 4dd0213

Please sign in to comment.