Clippy wanted features & bugfixes · Issue #349 · Rust-for-Linux/linux (original) (raw)
Features that we would like to see
Required (we almost certainly want them)
- Macros wrapping expressions in
unsafe
blocks when usingunsafe_op_in_unsafe_fn
.- Issue: Macros wrapping expressions in unsafe blocks when using unsafe_op_in_unsafe_fn rust-lang/rust-clippy#7323.
- Unfinished PR: Add new lint macros_hiding_unsafe_code rust-lang/rust-clippy#7469.
- Related: Rust 1.80.0's
clippy::macro_metavars_in_unsafe
.
- Lint to catch
#[no_mangle]
on non-repr(C)
pub static
s. - Support custom
dbg!
s in thedbg_macro
lint.- We started using it in Rust 1.60, but it stopped working in 1.61 (but it may be intended).
- Issue: Custom dbg! macros for dbg_macro lint rust-lang/rust-clippy#11303.
- Lint to catch non-absolute paths in macros, e.g.
core::...
instead of::core::...
.
Nice to have (not critical, we could workaround if needed, etc.)
- Improved shadowing lints.
- We currently do not enable any of the
shadow_*
lints. In particular,shadow_reuse
would lint on many things that are OK for us, especially "top-level"let ... =
s. Please see the details in Lint dangerous uses of shadowing rust-lang/rust-clippy#3433 (comment). - It would have already prevented one kernel bug: https://lore.kernel.org/rust-for-linux/20241123-rust-fix-arraylayout-v1-1-197e64c95bd4@asahilina.net/.
- Issue: Lint dangerous uses of shadowing rust-lang/rust-clippy#3433.
- Issue: Lint request: warn when variable declared in match pattern shadows other variable rust-lang/rust-clippy#2890.
- We currently do not enable any of the
- Lints that generalize
exit
,todo
,mem_forget
, etc. disallowed_names
support for identifiers.- Per-path lint levels for
DisallowedPath
-related lints. - Have a lint against usize-to-u64 casts (or, against all integer casts).
- Make
unnecessary_cast
cover somecore::ffi::c_*
cases. unnecessary_cast
does not trigger with a local but it does with a parameter.- Ignoring lints added after a given Rust version.
- Issue: Ignoring lints added after a given Rust version rust-lang/rust-clippy#11227.
- Related: New lints are not backwards compatible rust-lang/cargo#12495 (about ignoring unknown lints, explicitly passed, when compiling with an older compiler, rather than a new compiler introducing new lints).
- If we had something like this, then we could consider using
-D
for some lint groups or leaving Clippy's default for some lints inclippy::all
.
- Unsafe attributes support.
- Avoid inherent methods on generic smart pointers.
- Split
needless_lifetimes
.- One "major addition" to the lint added in 1.86.
- Currently it is the only
clippy::all
lint that weallow
. - Issue: Consider splitting needless_lifetimes into cases that do and do not require '_ rust-lang/rust-clippy#13514.
- Lore: https://lore.kernel.org/rust-for-linux/20241012231300.397010-1-ojeda@kernel.org/.
- Lore: https://lore.kernel.org/rust-for-linux/20241116181538.369355-1-ojeda@kernel.org/.
- Support for
--fix
without Cargo (e.g. insideclippy-driver
).- Using
cargo
(the binary) would be fine if needed, but not if it requires a Cargo-based structure.
- Using
unsafe extern
support.- Unneeded
rust
as language inrustdoc
's documentation examples. manual_div_ceil
suggests change that could alter behaviour.- Lint to catch docs using
///
instead of//!
.- Issue: Documentation mistakenly using /// instead of //! rust-lang/rust-clippy#14402.
- Example: 8d9b095 ("samples: rust_misc_device: Provide an example C program to exercise functionality").
- Support
msrv
with a list of unstable features to assume (or perhaps a list of lints that ignore themsrv
field). - Lint to catch links in normal comments (i.e.
//
) that are not formatted as Markdown autolinks (i.e.<https://...>
).- Should lints like these be part of
rustdoc
in general, like the wish for intra-doc links there? - Rust for Linux example issue to clean instances of these: Use Markdown autolinks in normal comments #1153.
- Should lints like these be part of
Low priority (we will likely not use them in the end)
- Conditional compilation for
clippy.toml
?- No concrete use cases from our side yet; and if needed, we could always handle it on our side generating
.clippy.toml
on the fly (and usingCLIPPY_CONF_DIR
to find it in theobjtree
instead of thesrctree
). - Issue: Conditional compilation for configuration file? rust-lang/rust-clippy#11433.
- No concrete use cases from our side yet; and if needed, we could always handle it on our side generating
- Fine-grained
check-private-items
(https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items).- So far, we have
check-private-items
enabled, but we do not have all the lints covered enabled, and in the future we might want to enable them, thuscheck-private-items
may make it harder to start. - Issue: Separate check-private-items configuration for different lints rust-lang/rust-clippy#13074.
- So far, we have
Done (stabilized, fixed, not needed anymore, etc.)
- Overindented lines lint (similar to
doc_lazy_continuation
). - Support/document running Clippy as a
rustc
wrapper. - Configuring lint levels when using
clippy-driver
. - Normalize semicolon inside/outside blocks for
()
returning expressions (semicolon_outside_block
andsemicolon_inside_block
, 1.68.0). - Lint to warn about missing
// SAFETY:
explanations (undocumented_unsafe_blocks
, 1.58.0). - Lint to warn about unexpected
# Safety
contracts (i.e. the reverse of themissing_safety_doc
lint) (unnecessary_safety_doc
, 1.67.0). - Lint to warn about unexpected
// SAFETY:
comments (i.e. the reverse of theundocumented_unsafe_blocks
lint) (unnecessary_safety_comment
, 1.67.0).- Issue: New lint (unnecessary_safety_comment): reverse of undocumented_unsafe_blocks rust-lang/rust-clippy#7954.
- PR: Lint unnecessary safety comments rust-lang/rust-clippy#9851.
- Unclear if we will use
// SAFETY:
comments also for explaining why safe code makes other unsafe code sound, though.
- Lint to catch
#[no_mangle]
but non-extern "C"
(no_mangle_with_rust_abi
, 1.69.0).
Bugs that we would like to see fixed
Required (we almost certainly want them)
undocumented_unsafe_blocks
false positives around attributes.- Workaround: moving the attribute on top always fixes it.
- Workaround: where it makes sense, moving the comment inside the expression, also works.
- Issue: undocumented_unsafe_blocks false positives around attributes rust-lang/rust-clippy#13189.
disallowed_macros
false negatives.- For
dbg_macro
emulation purposes. - Issue: disallowed_macros false negatives rust-lang/rust-clippy#11431.
- PR (for the
$t + $t
case): Check binary operators and attributes in disallowed_macros rust-lang/rust-clippy#11439 (1.74).
- For
cast_lossless
false negative onchar as u32
.
Nice to have (probably not critical, we could workaround if needed, etc.)
unnecessary_safety_comment
does not lint for the first line.unnecessary_safety_comment
does not lint the first item of a module without a body.unnecessary_safety_comment
does not lint for a doc(hidden) item.unnecessary_safety_comment
does not lint for "orphan" comments.- Feedback on
needless_continue
in Rust 1.86.0 (which we will probably disable globally).
Low priority (we will likely not use them in the end)
Done (stabilized, fixed, or not needed anymore, etc.)
README
: document that Clippy may change codegen.new_ret_no_self
false positive when returningimpl Trait<Self>
.macro_metavars_in_unsafe
false negative without statement.single_match
difference in 1.85.0 -- is it intended?- We cannot use
expect
in https://lore.kernel.org/rust-for-linux/20250122054719.595878-1-dirk.behme@de.bosch.com/. - Issue: clippy::single_match does not report if a comment is on top of an arm rust-lang/rust-clippy#14418.
- PR: Reinstate single_match/single_match_else lints with comments rust-lang/rust-clippy#14420 (1.87?).
- We cannot use
- Diagnostic for unexpected paths in configuration file.
- For instance, for
disallowed_macros
's paths. - Issue: Diagnostic for unexpected paths in configuration file rust-lang/rust-clippy#11432.
- PR: Validate paths in disallowed_* configurations rust-lang/rust-clippy#14397 (1.87?).
- For instance, for
- Reduce or split
ptr_eq
.- One "major addition" to the lint (linting all pointer comparisons) added in 1.87.
- We may need to
allow
it globally otherwise, likeneedless_continue
. - Issue: Feedback on needless_continue in Rust 1.86 rust-lang/rust-clippy#14536.
- Issue: clippy beta 1.87 lints all pointer comparisons, possibly too much? rust-lang/rust-clippy#14525.
- PR: Restrict the cases where ptr_eq triggers rust-lang/rust-clippy#14526.
- Backport PR (for Rust 1.87): [beta] Clippy beta backport rust-lang/rust#140810, [stable] Prepare the 1.87.0 release rust-lang/rust#140859.
- Patch that
allow
ed a few of them (when applied): https://lore.kernel.org/rust-for-linux/20250502140237.1659624-3-ojeda@kernel.org/.