Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl_trait_in_params doesn't work for non-public functions #12792

Open
CobaltCause opened this issue May 13, 2024 · 2 comments
Open

impl_trait_in_params doesn't work for non-public functions #12792

CobaltCause opened this issue May 13, 2024 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@CobaltCause
Copy link

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
@CobaltCause CobaltCause added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels May 13, 2024
@J-ZhengLi
Copy link
Member

looks like it was intended by design, but the doc didn't specify that:

&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()

@CobaltCause
Copy link
Author

Hmm, I just read through the PR in which the lint was added (#10197) and there wasn't any discussion about whether this was desirable or intentional. Maybe it being written this way was accidental. Either way, I personally think this lint should apply to all instances, not just public ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

2 participants