-
Couldn't load subscription status.
- Fork 13.9k
Description
Code
// types/src/lib.rs
pub trait Trait {}
pub struct Public;
impl Trait for Public {}
#[doc(hidden)]
pub struct HiddenStruct;
impl Trait for HiddenStruct {}
pub struct HiddenImpl;
#[doc(hidden)]
impl Trait for HiddenImpl {}
#[doc(hidden)]
pub mod private {
pub struct HiddenModule;
impl crate::Trait for HiddenModule {}
}// src/main.rs
fn require_trait<T: types::Trait>() {}
fn main() {
require_trait::<u8>();
}Current output
error[E0277]: the trait bound `u8: Trait` is not satisfied
--> src/main.rs:4:21
|
4 | require_trait::<u8>();
| ^^ the trait `Trait` is not implemented for `u8`
|
= help: the following other types implement trait `Trait`:
HiddenImpl
HiddenModule
HiddenStruct
Public
note: required by a bound in `require_trait`
--> src/main.rs:1:21
|
1 | fn require_trait<T: types::Trait>() {}
| ^^^^^^^^^^^^ required by this bound in `require_trait`Desired output
- = help: the following other types implement trait `Trait`:
- HiddenImpl
- HiddenModule
- HiddenStruct
- Public
+ = help: the trait `Trait` is implemented for `Public`Rationale and extra context
HiddenStruct should not be volunteered to the user in an error message because that type is doc(hidden).
HiddenImpl should not be volunteered as implementing Trait because its impl Trait for HiddenImpl is doc(hidden).
HiddenModule is also not public, although indirectly.
Context: this came up in serde-rs/serde#2558 (comment).
Rust Version
rustc 1.84.0-nightly (439284741 2024-10-21)
binary: rustc
commit-hash: 4392847410ddd67f6734dd9845f9742ff9e85c83
commit-date: 2024-10-21
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1Anything else?
There is longstanding precedent for #[doc(hidden)] affecting what suggestions rustc tries to make.
For example when suggesting imports. See #119151 and https://github.com/rust-lang/rust/blob/814df6e50eaf89b90793e7d9618bb60f1f18377a/tests/ui/suggestions/dont-suggest-foreign-doc-hidden.rs.
Also when suggesting struct fields. See #93214 and https://github.com/rust-lang/rust/blob/814df6e50eaf89b90793e7d9618bb60f1f18377a/tests/ui/did_you_mean/dont-suggest-doc-hidden-fields.rs.