Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide nonlocal doc(hidden) types and impls from "the following other types implement trait" #132024

Open
dtolnay opened this issue Oct 22, 2024 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Oct 22, 2024

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.1

Anything 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.

@dtolnay dtolnay added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-visibility Area: Visibility / privacy and removed A-visibility Area: Visibility / privacy labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant