rust-lang / rust-lang/rust-clippy

[1.84.0 regression] `#[allow(clippy::disallowed_macros)]` does not work on two-argument `std::panic`

Open
#14,017 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in the issue and its clippy.toml configuration, running it with Rust 1.83.0 and 1.84.0 to isolate the regression in two-argument std::panic. Trace the disallowed_macros lint handling for the panic_2_args entry point; done means #[allow] or #[expect] suppresses the warning as it does for the other cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.