Repository: rust
Issue: `unreachable_pub` lint suggests a breaking fix for associated type on trait
Labels: A-lints,A-visibility,T-compiler,C-bug,L-unreachable_pub

(Apologies for the terrible title; I'm not sure what the correct terminology is for what's going on)

I tried this code:

```rust
// src/traiter.rs
pub trait CrateTrait<const X: usize> {}

// src/lib.rs
#[warn(unreachable_pub)]

mod traiter;

pub trait PubTrate<const X: usize> {
    type T: traiter::CrateTrait<X>;
}
```

This produces the following warning output:

```
   Compiling pub_crate v0.1.0 ([...]/pub_crate)
warning: unreachable `pub` item
 --> src/traiter.rs:1:1
  |
1 | pub trait CrateTrait<const X: usize> {}
  | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | |
  | help: consider restricting its visibility: `pub(crate)`
  |
  = help: or consider exporting it for use by other crates
note: the lint level is defined here
 --> src/lib.rs:1:8
  |
1 | #[warn(unreachable_pub)]
  |        ^^^^^^^^^^^^^^^

warning: `pub_crate` (lib) generated 1 warning (run `cargo fix --lib -p pub_crate` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
```

When I took the compiler's helpful advice to run `cargo fix --lib -p pub_crate`, it fails, with this output:

```
    Checking pub_crate v0.1.0 ([...]/pub_crate)
warning: failed to automatically apply fixes suggested by rustc to crate `pub_crate`
                                              
after fixes were automatically applied the compiler reported errors within these files:
                                              
  * src/lib.rs
  * src/traiter.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see 
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0445]: crate-private trait `CrateTrait<X>` in public interface
 --> src/lib.rs:6:5
  |
6 |     type T: traiter::CrateTrait<X>;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-private trait
  |
 ::: src/traiter.rs:1:1
  |
1 | pub(crate) trait CrateTrait<const X: usize> {}
  | ------------------------------------------- `CrateTrait<X>` declared as crate-private

error: aborting due to previous error

For more information about this error, try `rustc --explain E0445`.
Original diagnostics will follow.

warning: unreachable `pub` item
 --> src/traiter.rs:1:1
  |
1 | pub trait CrateTrait<const X: usize> {}
  | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | |
  | help: consider restricting its visibility: `pub(crate)`
  |
  = help: or consider exporting it for use by other crates
note: the lint level is defined here
 --> src/lib.rs:1:8
  |
1 | #[warn(unreachable_pub)]
  |        ^^^^^^^^^^^^^^^

warning: `pub_crate` (lib) generated 1 warning (run `cargo fix --lib -p pub_crate` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.34s
```

### Meta

`rustc --version --verbose`:
```
rustc 1.71.0-nightly (1a6ae3d69 2023-04-27)
binary: rustc
commit-hash: 1a6ae3d692cfb52b21d0f45ba50b659486e53d6c
commit-date: 2023-04-27
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2
```

Also occurs with stable, this version produces seemingly-identical results:

```
rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7
```