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

Compilation error when using string in assert #3717

Open
zhassan-aws opened this issue Nov 15, 2024 · 0 comments
Open

Compilation error when using string in assert #3717

zhassan-aws opened this issue Nov 15, 2024 · 0 comments
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@zhassan-aws
Copy link
Contributor

zhassan-aws commented Nov 15, 2024

The following code is valid (albeit deprecated) in Rust 2018, but Kani fails to compile it.

#[kani::proof]
fn main() {
    let s = String::new();
    assert!(true, s);
}

using the following steps:

  1. cargo new --edition 2018 foo
  2. cd foo
  3. Replace src/main.rs with the code above.
  4. Run cargo kani

with Kani version: b774d40

I expected to see this happen: Verification successful

Instead, this happened:

$ cargo kani
Kani Rust Verifier 0.56.0 (cargo plugin)
   Compiling foo v0.1.0 (/home/ubuntu/examples/assert/foo)
error: format argument must be a string literal
 --> src/main.rs:4:19
  |
4 |     assert!(true, s);
  |                   ^
  |
help: you might be missing a string literal to format with
  |
4 |     assert!(true, "{}", s);
  |                   +++++

error: could not compile `foo` (bin "foo") due to 1 previous error
error: Failed to execute cargo (exit status: 101). Found 1 compilation errors.

If I remove #[kani::proof], I'm able to run it with cargo run:

$ cargo run
   Compiling foo v0.1.0 (/home/ubuntu/examples/assert/foo)
warning: panic message is not a string literal
 --> src/main.rs:3:19
  |
3 |     assert!(true, s);
  |                   ^
  |
  = note: this usage of `assert!()` is deprecated; it will be a hard error in Rust 2021
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
  = note: `#[warn(non_fmt_panics)]` on by default
help: add a "{}" format string to `Display` the message
  |
3 |     assert!(true, "{}", s);
  |                   +++++

warning: `foo` (bin "foo") generated 1 warning (run `cargo fix --bin "foo"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/foo`
@zhassan-aws zhassan-aws added the [C] Bug This is a bug. Something isn't working. label Nov 15, 2024
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

No branches or pull requests

1 participant