Re: [PATCH 12/19] rust: replace `clippy::dbg_macro` with `disallowed_macros`

From: Gary Guo
Date: Sat Sep 14 2024 - 19:10:54 EST


On Thu, 5 Sep 2024 07:20:46 +0200
Geert Stappers <stappers@xxxxxxxxxxx> wrote:

> On Wed, Sep 04, 2024 at 10:43:40PM +0200, Miguel Ojeda wrote:
> > diff --git a/.clippy.toml b/.clippy.toml
> > index f66554cd5c45..ad9f804fb677 100644
> > --- a/.clippy.toml
> > +++ b/.clippy.toml
> > @@ -1 +1,7 @@
> > # SPDX-License-Identifier: GPL-2.0
> > +
> > +disallowed-macros = [
> > + # The `clippy::dbg_macro` lint only works with `std::dbg!`, thus we simulate
> > + # it here, see: https://github.com/rust-lang/rust-clippy/issues/11303.
> > + { path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool" },
> > +]
> > diff --git a/rust/kernel/std_vendor.rs b/rust/kernel/std_vendor.rs
> > index 67bf9d37ddb5..085b23312c65 100644
> > --- a/rust/kernel/std_vendor.rs
> > +++ b/rust/kernel/std_vendor.rs
> > @@ -14,7 +14,7 @@
> > -/// # #[allow(clippy::dbg_macro)]
> > +/// # #[allow(clippy::disallowed_macros)]
> > @@ -52,7 +52,7 @@
> > -/// # #[allow(clippy::dbg_macro)]
> > +/// # #[allow(clippy::disallowed_macros)]
> > @@ -71,7 +71,7 @@
> > -/// # #[allow(clippy::dbg_macro)]
> > +/// # #[allow(clippy::disallowed_macros)]
> > @@ -118,7 +118,7 @@
> > /// a tuple (and return it, too):
> > ///
> > /// ```
> > -/// # #[allow(clippy::dbg_macro)]
> > +/// # #![allow(clippy::disallowed_macros)]
> > /// assert_eq!(dbg!(1usize, 2u32), (1, 2));
> > /// ```
> > ///
>
> For what it is worth, the exclamation mark did surprise me.

`#[]` would apply to the next item/statement, and `#![]` would apply to
the surrouding scope. In this case there's just a single statement so
they should be equivalent.

Miguel, is this change from `#[]` to `#![]` intentional?

Best,
Gary

>
>
> > @@ -127,7 +127,7 @@
> > ///
> > /// ```
> > -/// # #[allow(clippy::dbg_macro)]
> > +/// # #[allow(clippy::disallowed_macros)]
> > /// # {
> > /// assert_eq!(1, dbg!(1u32,)); // trailing comma ignored
> > /// assert_eq!((1,), dbg!((1u32,))); // 1-tuple
>
>
> Groeten
> Geert Stappers