rust-lang / rust-lang/rust

`private_bounds` lint does not trigger when associated type is not re-exported

Open
#137,438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried this code:

pub use self::stuff::Trait1;

mod stuff {
    pub trait Trait1 {
        type Thing: Trait2;
    }

    // This triggers it:
    // pub(crate) trait Trait2 {}
    
    // This doesn't:
    pub trait Trait2 {}
}

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=3c1b275b4ccc88b9111b9780ee330916

I expected to see this happen: the private_bounds lint triggers

Instead, this happened: the lint does not trigger - to make it trigger I must mark the second trait pub(crate)

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f04bbc60f 2025-02-20)
binary: rustc
commit-hash: f04bbc60f8c353ee5ba0677bc583ac4a88b2c180
commit-date: 2025-02-20
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
<backtrace>

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

Start with the provided Rust Playground reproduction and trace the compiler's private_bounds lint handling for the associated type bound. Compare the pub(crate) and pub versions, then add or update coverage so the lint triggers when the associated type's bound trait is public but not re-exported.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.