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

Confusing difference in behavior when creating tracked struct #1460

Open
matthias-brun opened this issue Feb 19, 2025 · 0 comments
Open

Confusing difference in behavior when creating tracked struct #1460

matthias-brun opened this issue Feb 19, 2025 · 0 comments

Comments

@matthias-brun
Copy link
Collaborator

The following code works fine when we initialize the field b with a constant 3u64 but if we try to use the u64 from the argument, Verus emits an error about the expression's mode. This behavior is very confusing and in fact, seeing the mode error message had lead me to believe that values of tracked type can only be created in trusted code.

use vstd::prelude::*; verus! {

struct A { b: u64 }

proof fn new(b: u64) -> tracked A {
    // only works if we declare the field `b` to be `ghost`:
    let tracked a: A = A { b: b };
    // works:
    // let tracked a: A = A { b: 3u64 };
    a
}

}
error: expression has mode spec, expected mode proof
 --> linear.rs:7:24
  |
7 |     let tracked a: A = A { b: b };
  |                        ^^^^^^^^^^
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