rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.32k stars 1.53k forks source link

clippy::missing-assert-message gives false positive #13490

Open insideoutclub opened 4 days ago

insideoutclub commented 4 days ago

Summary

This lint shows up even when I add as message as a second parameter to the assert! macro.

Lint Name

missing-assert-message

Reproducer

I tried this code:

pub struct Service {
    ready: bool,
}

pub fn call(service: Service) {
    assert!(service.ready, "`service.poll_ready()` must be called first to ensure that service is ready to receive requests");
}

I saw this happen:


C:\Users\sandersd\Exercism\rust\poker\src>cargo clippy -- -Dclippy::missing_assert_message
    Checking poker v1.1.0 (C:\Users\sandersd\Exercism\rust\poker)
error: assert without any message
 --> src\lib.rs:6:5
  |
6 |     assert!(service.ready, "`service.poll_ready()` must be called first to ensure that service is ready to receive requests...
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider describing why the failing assert is problematic
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_assert_message
  = note: requested on the command line with `-D clippy::missing-assert-message`

error: could not compile `poker` (lib) due to 1 previous error```

I expected to see this happen:

C:\Users\sandersd\Exercism\rust\poker\src>cargo clippy -- -Dclippy::missing_assert_message
    Checking poker v1.1.0 (C:\Users\sandersd\Exercism\rust\poker)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.50s

### Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-pc-windows-msvc
release: 1.81.0
LLVM version: 18.1.7

### Additional Labels

_No response_
alex-semenyuk commented 1 day ago

Do not observe such issue at last version https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0a03582571da3ba6c6c51682b777330c