Description
Summary
As of 1.84.0, it is not possible to use #[allow]
or #[expect]
to silence clippy::disallowed_macros
when invoking std::panic
with exactly two arguments.
Or at least, the straightforward thing does not work, and I haven't found a workaround other than "don't use std::panic
with two arguments".
As far as I can tell, this is specific to std::panic
and specific to the two-argument case, which seems pretty strange... But I obviously haven't exhaustively tested all macros so maybe that is just a coincidence.
Lint Name
disallowed_macros
Reproducer
I tried this code:
pub fn print_1_arg() {
#![expect(clippy::disallowed_macros)]
print!("foo");
}
pub fn print_2_args() {
#![expect(clippy::disallowed_macros)]
print!("{}", 123);
}
pub fn print_3_args() {
#![expect(clippy::disallowed_macros)]
print!("{} {}", 123, 456);
}
pub fn panic_1_arg() {
#![expect(clippy::disallowed_macros)]
panic!("foo");
}
pub fn panic_2_args() {
#![expect(clippy::disallowed_macros)]
panic!("{}", 123);
}
pub fn panic_3_args() {
#![expect(clippy::disallowed_macros)]
panic!("{} {}", 123, 456);
}
With this clippy.toml
:
disallowed-macros = ["std::panic", "std::print"]
I saw this happen:
warning: use of a disallowed macro `std::panic`
--> asdf.rs:20:5
|
20 | panic!("{}", 123);
| ^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
= note: `#[warn(clippy::disallowed_macros)]` on by default
warning: this lint expectation is unfulfilled
--> asdf.rs:19:15
|
19 | #![expect(clippy::disallowed_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
I expected to see this happen: no error.
With cargo +1.83.0 clippy
it works, with cargo +1.84.0 clippy
it no longer does. (And at least 1.82.0 and 1.81.0 also work; didn't test older than that.)
If the #![expect]
lines are removed, I see six errors with both versions as expected — though 1.84.0 strangely reports the two-argument std::panic
one, i.e. the problematic one that can't be silenced, as the very first error, instead of reporting the errors in source code order. Maybe that's somehow related?
Version
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5
Additional Labels
No response