Skip to contentSkip to conversation

rust: allow `clippy::disallowed_names` for doctests

PATCH Applied Miguel Ojeda 5 participants 10 messages Nov 17, 2025

Subsystems (4)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: allow `clippy::disallowed_names` for doctests

Examples (i.e. doctests) may want to use names such as foo, thus the clippy::disallowed_names lint gets in the way.

Thus allow it for all doctests.

In addition, remove it from the existing expects we have in a few doctests.

This does not mean that we should stop trying to find good names for our examples, though.

---
 rust/kernel/init.rs         | 3 +--
 rust/kernel/types.rs        | 1 -
 scripts/rustdoc_test_gen.rs | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)
rust/kernel/init.rs +1 -2
index e476d81c1a27..899b9a962762 100644
@@ -30,7 +30,7 @@
 //! ## General Examples
 //!
 //! ```rust
-//! # #![expect(clippy::disallowed_names, clippy::undocumented_unsafe_blocks)]
+//! # #![expect(clippy::undocumented_unsafe_blocks)]
 //! use kernel::types::Opaque;
 //! use pin_init::pin_init_from_closure;
 //!
@@ -67,7 +67,6 @@
 //! ```
 //!
 //! ```rust
-//! # #![expect(clippy::disallowed_names)]
 //! use kernel::{prelude::*, types::Opaque};
 //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
 //! # mod bindings {
rust/kernel/types.rs +0 -1
index 835824788506..9c5e7dbf1632 100644
@@ -289,7 +289,6 @@ fn drop(&mut self) {
 /// # Examples
 ///
 /// ```
-/// # #![expect(clippy::disallowed_names)]
 /// use kernel::types::Opaque;
 /// # // Emulate a C struct binding which is from C, maybe uninitialized or not, only the C side
 /// # // knows.
scripts/rustdoc_test_gen.rs +1 -1
index 0e6a0542d1bd..be0561049660 100644
@@ -208,7 +208,7 @@ macro_rules! assert_eq {{
     #[allow(unused)]
     static __DOCTEST_ANCHOR: i32 = ::core::line!() as i32 + {body_offset} + 1;
     {{
-        #![allow(unreachable_pub)]
+        #![allow(unreachable_pub, clippy::disallowed_names)]
         {body}
         main();
     }}
Signature · 1 line
2.51.2
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Miguel Ojeda

Examples (i.e. doctests) may want to use names such as foo, thus the clippy::disallowed_names lint gets in the way.

Thus allow it for all doctests.

In addition, remove it from the existing expects we have in a few doctests.

Quoted 6 lines

This does not mean that we should stop trying to find good names for our examples, though.

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Miguel Ojeda
Quoted 8 lines · Miguel Ojeda

Examples (i.e. doctests) may want to use names such as foo, thus the clippy::disallowed_names lint gets in the way.

Thus allow it for all doctests.

In addition, remove it from the existing expects we have in a few doctests.

Quoted 6 lines

This does not mean that we should stop trying to find good names for our examples, though.

Cheers,
Benno

Quoted 5 lines
---
 rust/kernel/init.rs         | 3 +--
 rust/kernel/types.rs        | 1 -
 scripts/rustdoc_test_gen.rs | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)
Applied
#3 lore raw
In reply to Miguel Ojeda
Quoted 9 lines · Miguel Ojeda

Examples (i.e. doctests) may want to use names such as foo, thus the clippy::disallowed_names lint gets in the way.

Thus allow it for all doctests.

In addition, remove it from the existing expects we have in a few doctests.

Quoted 6 lines

This does not mean that we should stop trying to find good names for our examples, though.

Applied to rust-next -- thanks everyone!

Cheers,
Miguel

#4 lore raw
Quoted 10 lines · Miguel Ojeda
Quoted 9 lines · Miguel Ojeda

Examples (i.e. doctests) may want to use names such as foo, thus the clippy::disallowed_names lint gets in the way.

Thus allow it for all doctests.

In addition, remove it from the existing expects we have in a few doctests.

Quoted 9 lines
Quoted 6 lines

This does not mean that we should stop trying to find good names for our examples, though.

Applied to rust-next -- thanks everyone!

Is rust-next a rebasing branch? I was going to request a non-empty commit body, in order to make it more immediately clear what this does. Something like:

The current set of disallowed names is inherited from clippy's defaults [1], which are "foo", "baz", and "quux". This may be extended via .clipy.toml, which so far has no entries for disallowed names.

thanks,

Signature · 1 line
John Hubbard
#5 lore raw
Quoted 2 lines · John Hubbard
Quoted 1 line · Miguel Ojeda

On Mon, Nov 17, 2025 at 9:07 AM Miguel Ojeda <[email protected]> wrote:

...

Quoted 8 lines

Is rust-next a rebasing branch? I was going to request a non-empty commit body, in order to make it more immediately clear what this does. Something like:

The current set of disallowed names is inherited from clippy's defaults [1], which are "foo", "baz", and "quux". This may be extended via .clipy.toml, which so far has no entries for disallowed names.

oops, left out the link. Here:

[1] https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names

thanks,

Signature · 1 line
John Hubbard
#6 lore raw
In reply to John Hubbard
Quoted 8 lines · John Hubbard

Is rust-next a rebasing branch? I was going to request a non-empty commit body, in order to make it more immediately clear what this does. Something like:

The current set of disallowed names is inherited from clippy's defaults [1], which are "foo", "baz", and "quux". This may be extended via .clipy.toml, which so far has no entries for disallowed names.

What do you mean by "non-empty commit body"? The commit has several short paragraphs and mentions the foo example (precisely to hint at what the lint does).

But, sure, I am happy to add a Link: tag to the lint -- I typically add those when enabling a lint (e.g. commit db4f72c904cb ("rust:
enable clippy::undocumented_unsafe_blocks lint")).

Cheers,
Miguel

#8 lore raw
In reply to John Hubbard
Quoted 4 lines · John Hubbard

The current set of disallowed names is inherited from clippy's defaults [1], which are "foo", "baz", and "quux". This may be extended via .clipy.toml, which so far has no entries for disallowed names.

As for this paragraph, I am confused why we would want to add it.

This isn't about extending the disallowed names or about how the lint works in general. It is just about disabling the lint entirely for doctests.

So adding that paragraph would make it the commit more confusing.

Cheers,
Miguel

#7 lore raw
In reply to Miguel Ojeda
Quoted 6 lines · Miguel Ojeda
Quoted 5 lines · John Hubbard

Is rust-next a rebasing branch? I was going to request a non-empty commit body, in order to make it more immediately clear what this does. Something like:

Quoted 8 lines
Quoted 3 lines

The current set of disallowed names is inherited from clippy's defaults [1], which are "foo", "baz", and "quux". This may be extended via .clipy.toml, which so far has no entries for disallowed names.

What do you mean by "non-empty commit body"? The commit has several short paragraphs and mentions the foo example (precisely to hint at what the lint does).

Yikes, I misread one of the replies (way too quickly) and completely missed the commit body, sorry for that.

thanks,

Signature · 1 line
John Hubbard
#9 lore raw
In reply to Miguel Ojeda
Quoted 11 lines · Miguel Ojeda
Quoted 4 lines · John Hubbard

The current set of disallowed names is inherited from clippy's defaults [1], which are "foo", "baz", and "quux". This may be extended via .clipy.toml, which so far has no entries for disallowed names.

As for this paragraph, I am confused why we would want to add it.

This isn't about extending the disallowed names or about how the lint works in general. It is just about disabling the lint entirely for doctests.

Yes. But I still thought some context might help, because it wasn't obvious at first to me (as a Rust learner).

Quoted 3 lines

So adding that paragraph would make it the commit more confusing.

OK, I'll accept that judgment call. :)

thanks,

Signature · 1 line
John Hubbard