rust-lang / rust-lang/rust-clippy
`impl_trait_in_params` doesn't work for non-public functions
Open
Nobody has claimed this yet.
C-bug
I-false-negative
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The lint only appears for public functions (i.e. public API surface of a library).
Lint Name
impl_trait_in_params
Reproducer
I tried this code:
#![deny(clippy::impl_trait_in_params)]
#![allow(dead_code)]
pub fn true_positive(_: impl Sized) {}
fn false_negative(_: impl Sized) {}
I expected to see this happen:
2 instances of impl_trait_in_params should appear, one for each function.
Instead, this happened:
Only 1 instance appeared for the pub function:
error: `impl Trait` used as a function parameter
--> src/lib.rs:3:25
|
3 | pub fn true_positive(_: impl Sized) {}
| ^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![deny(clippy::impl_trait_in_params)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a type parameter
|
3 | pub fn true_positive<{ /* Generic name */ }: Sized>(_: impl Sized) {}
| +++++++++++++++++++++++++++++++
Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided Rust snippet and the clippy::impl_trait_in_params lint. Trace the lint's handling of public and non-public functions, then verify that both true_positive and false_negative produce diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100