rust-lang / rust-lang/rust-clippy

Custom `dbg!` macros for `dbg_macro` lint

Open
#11,303 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

G-Rust-for-Linux
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Back in Rust 1.60.0 we added -Wclippy::dbg_macro to the Linux kernel compilation flags, which worked great with our custom dbg! macro (essentially the std one but calling the kernel printing facilities).

However, in the next version (1.61.0), as well as the current stable (1.80.0) and the current nightly (1.83.0-nightly (bd53aa3bf 2024-09-02)), it does not work. Thus only the first of the following lines emit a warning:

echo 'macro_rules! dbg { () => {} } fn main() { dbg!(); }' | rustup run  1.60.0 clippy-driver -Wclippy::dbg_macro -
echo 'macro_rules! dbg { () => {} } fn main() { dbg!(); }' | rustup run  1.61.0 clippy-driver -Wclippy::dbg_macro -
echo 'macro_rules! dbg { () => {} } fn main() { dbg!(); }' | rustup run  1.80.0 clippy-driver -Wclippy::dbg_macro -
echo 'macro_rules! dbg { () => {} } fn main() { dbg!(); }' | rustup run nightly clippy-driver -Wclippy::dbg_macro -

Is the lint intended to work only with the standard library dbg macro? I imagine that is the case, given the move to diagnostic items in https://github.com/rust-lang/rust-clippy/pull/7466, but it is not entirely clear from the lint description.

A workaround is to use disallowed_macros, but that does not have a specialized diagnostic message nor has the nice help: suggestion. Another is to use rustc_attrs, but I imagine that is not going to be stable.

Thus, instead, could the dbg_macro lint take a configuration with paths to dbg! macros (like disallowed_macros) or, even better, could there be an attribute that users could apply to their dbg! macro (like rustc_diagnostic_item)?

Cc @xFrednet and @Alexendoo who both seemed to work on this in the past.

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 by reviewing the dbg_macro lint behavior and the move to diagnostic items in rust-lang/rust-clippy#7466. Compare the existing disallowed_macros and rustc_attrs approaches, then determine whether configurable paths or a user-facing macro attribute is appropriate. Done means the supported behavior and its documentation or diagnostics are updated with coverage for custom dbg! macros.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.