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

Kani assert override is more restrictive than standard assert #2108

Closed
Tracked by #2138
tedinski opened this issue Jan 12, 2023 · 2 comments · Fixed by #2117
Closed
Tracked by #2138

Kani assert override is more restrictive than standard assert #2108

tedinski opened this issue Jan 12, 2023 · 2 comments · Fixed by #2117
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@tedinski
Copy link
Contributor

This code works as a test but fails with Kani:

#[cfg_attr(test, test)]
#[cfg_attr(kani, kani::proof)]
fn check() {
    let v: bool = true;
    assert!(&v);
}

With test: builds successfully, no warnings/errors, test passes.

With kani:

error[E0308]: mismatched types
  --> test_bool_ref.rs:7:13
   |
7  |     assert!(&v);
   |     --------^^-
   |     |       |
   |     |       expected `bool`, found `&bool`
   |     arguments to this function are incorrect
   |
note: function defined here
  --> /home/ubuntu/rmc/library/kani/src/lib.rs:62:14
   |
62 | pub const fn assert(_cond: bool, _msg: &'static str) {
   |              ^^^^^^
@tedinski tedinski added the [C] Bug This is a bug. Something isn't working. label Jan 12, 2023
@tedinski tedinski changed the title Kani asser override is more restrictive than standard assert Kani assert override is more restrictive than standard assert Jan 12, 2023
@zhassan-aws
Copy link
Contributor

Interesting. Apparently, this is valid Rust:

fn main() {
    let v: bool = true;
    if !&v {}
$ rustc neg.rs
$

which is what the standard assert macro expands to, but it is not valid without the negation:

fn main() {
    let v: bool = true;
    if &v {}
$ rustc not_neg.rs 
error[E0308]: mismatched types
 --> not_neg.rs:3:8
  |
3 |     if &v { }
  |        ^^ expected `bool`, found `&bool`
  |
help: consider removing the borrow
  |
3 -     if &v { }
3 +     if v { }
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

@zhassan-aws
Copy link
Contributor

I've opened #2117 to fix this via a hack. Out of curiosity, where did you see this? It is a bit confusing that if !&b is valid Rust but if &b isn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants