rust-lang / rust-lang/rust

private_bounds: false positive on inherent impl with no public items

Open
#139,158 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-bug L-false-positive L-private_bounds T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the false positive with rustc 1.88.0-nightly using the Rust snippet provided in the issue. No repository file or test is named, so trace the private_bounds lint from this reproduction; the fix is complete when the empty impl emits no warning and a regression test covers the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.