Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifetime-generate has additional trait bound restrictions (?) #966

Open
utaal-b opened this issue Jan 23, 2024 · 1 comment
Open

Lifetime-generate has additional trait bound restrictions (?) #966

utaal-b opened this issue Jan 23, 2024 · 1 comment

Comments

@utaal-b
Copy link
Contributor

utaal-b commented Jan 23, 2024

use vstd::prelude::*;
use vstd::seq_lib::*;

verus! {

trait VerusClone: View + Sized {
    fn verus_clone(&self) -> (r: Self)
        ensures self@ == r@;
}

fn vec_filter<V: VerusClone>(v: Vec<V>, f: impl Fn(&V)->bool, f_spec: FnSpec(V)->bool) -> (r: Vec<V>)
    requires forall|v: V| #[trigger] f.requires((&v,)), forall |v:V,r:bool| f.ensures((&v,), r) ==> f_spec(v) == r,
    ensures [email protected]_multiset() =~= [email protected]_multiset().filter(f_spec)
{
    let mut r = Vec::new();
    let mut i = 0;
    proof { lemma_seq_properties::<V>(); }
    while i < v.len()
        invariant
            forall|v: V| #[trigger] f.requires((&v,)),
            i <= v.len(),
            [email protected]_multiset() =~= [email protected](0, i as int).to_multiset().filter(f_spec),
            forall |v:V,r:bool| f.ensures((&v,), r) ==> f_spec(v) == r,
    {
        proof { lemma_seq_properties::<V>(); }
        let ghost pre_r = [email protected]_multiset();
        assert(
            [email protected](0, i as int + 1)
            =~=
            [email protected](0, i as int).push(v@[i as int]));
        if f(&v[i]) {
            r.push(v[i].verus_clone());
        }
        
        i += 1;
    }
    r
}

}

fails with

error: the trait bound `A27_V: T28_View` is not satisfied
  --> vec.rs:32:20
   |
32 |               r.push(v[i].verus_clone());
   |  ____________________^^^^_^
33 | |         }
   | |______^

and

fn vec_filter<V: VerusClone>

needs to be

fn vec_filter<V: VerusClone + View + Sized>
@utaal-b
Copy link
Contributor Author

utaal-b commented Jan 23, 2024

I believe this is because we ignore VerusClone because it doesn't have any associated types, but the type checker uses it to constrain V to be View + Sized too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant