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

int shouldn't be an executable type #1205

Open
jonhnet opened this issue Jul 3, 2024 · 3 comments
Open

int shouldn't be an executable type #1205

jonhnet opened this issue Jul 3, 2024 · 3 comments

Comments

@jonhnet
Copy link
Collaborator

jonhnet commented Jul 3, 2024

Verus passes this test file (verus /tmp/foo.rs --crate-type lib --compile gives 1 verified, 0 errors), but int shouldn't be accessible from executable code. I'm wondering what ended up in the compiled output!

use vstd::prelude::*;

verus!{

struct Point {
    x: int,
    y: int,
}

fn exec_point(p: Point) -> bool
{
    p.x < p.y
}

}
@utaal
Copy link
Collaborator

utaal commented Jul 3, 2024

Oh, I didn't look at this closely enough when you sent it on Slack, sorry.

This isn't technically unsound, as it's not possible for verified code to actually construct an exec-mode Point:

fn main() {
    exec_point(Point { x: 3 as int, y: 4 as int });
}

results in:

error[[E0605]](https://doc.rust-lang.org/stable/error_codes/E0605.html): non-primitive cast: `i32` as `vstd::prelude::int`
  --> /playground/src/main.rs:16:27
   |
16 |     exec_point(Point { x: 3 as int, y: 4 as int });
   |                           ^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

error[[E0605]](https://doc.rust-lang.org/stable/error_codes/E0605.html): non-primitive cast: `i32` as `vstd::prelude::int`
  --> /playground/src/main.rs:16:40
   |
16 |     exec_point(Point { x: 3 as int, y: 4 as int });
   |                                        ^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

error: aborting due to 2 previous errors

@utaal
Copy link
Collaborator

utaal commented Jul 3, 2024

This should help, once I get around to it: #323

@jonhnet
Copy link
Collaborator Author

jonhnet commented Jul 3, 2024

I agree it's not unsound, but it leads to some really confusing and late diagnostics. Lint suggestions in #323 sound good.

I'm also curious what --compile did with this example!

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

2 participants