Skip to content

private_bounds: false positive on inherent impl with no public items #139158

Open
@Kyuuhachi

Description

@Kyuuhachi

Code

#![allow(unused)]
struct Type<T>(T);
mod a {
    trait Trait {}
    impl<T: Trait> super::Type<T> {}
}

Current output

warning: trait `Trait` is more private than the item `a::<impl Type<T>>`
 --> src/lib.rs:5:5
  |
5 |     impl<T: Trait> super::Type<T> {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `a::<impl Type<T>>` is reachable at visibility `pub(crate)`
  |
note: but trait `Trait` is only usable at visibility `pub(self)`
 --> src/lib.rs:4:5
  |
4 |     trait Trait {}
  |     ^^^^^^^^^^^
  = note: `#[warn(private_bounds)]` on by default

Desired output

No warning

Rationale and extra context

No items inside the impl exist that leak private details, and the mere existence of the impl shouldn't be an issue. Same warning appears if the impl is non-empty.

I think the warning should be on individual items inside the impl rather than the impl itself.

Other cases

Rust Version

rustc 1.88.0-nightly (1799887bb 2025-03-29)
binary: rustc
commit-hash: 1799887bb281d1ab49287750f1950b8c738c6b77
commit-date: 2025-03-29
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-false-positiveLint: False positive (should not have fired).L-private_boundsLint: private_boundsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions