Closed
Description
Summary
This lint currently seems to warn only for freestanding functions.
It is correct to not warn associated functions of trait impls (since the user has no control over it), but I think it would be reasonable to warn associated functions of normal impls.
It is also probably reasonable to warn associated functions of trait definitions if the avoid-breaking-exported-api
config is set to false
.
Mentioning @blyxyas, who implemented this lint in #10197.
Lint Name
impl_trait_in_params
Reproducer
I tried this code:
#![warn(clippy::impl_trait_in_params)]
pub fn a(_s: impl AsRef<str>) {}
pub struct B;
impl B {
pub fn b(_s: impl AsRef<str>) {}
}
I expected to see this happen: warnings for both a
and b
.
Instead, this happened:
clippy emits warning only for a
.
warning: '`impl Trait` used as a function parameter'
--> src/lib.rs:3:14
|
3 | pub fn a(_s: impl AsRef<str>) {}
| ^^^^^^^^^^^^^^^
|
= 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 | #![warn(clippy::impl_trait_in_params)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: add a type parameter
|
3 | pub fn a<{ /* Generic name */ }: AsRef<str>>(_s: impl AsRef<str>) {}
| ++++++++++++++++++++++++++++++++++++
Version
rustc 1.74.0-nightly (3223b0b5e 2023-09-20)
binary: rustc
commit-hash: 3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e
commit-date: 2023-09-20
host: aarch64-apple-darwin
release: 1.74.0-nightly
LLVM version: 17.0.0