rust-lang / rust-lang/rust

rustdoc: split out trait implementer's notes from method docs

Open
#139,855 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request needs-rfc T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

On mastodon, Simon Tatham alerted us to the problem that rustdoc will show the method docs from a trait on an implementation of that trait, which may contain parts geared towards implementers, not users of the trait.

There is currently no way to distinguish those in a way that would let rustdoc show the implementer's notes on the trait docs but not on trait implementations.

Since doc comments get lowered to attributes, the lowest common. denominator would be an attribute like #[traitdoc = "..."] that works like #[doc = "..."] but is included by rustdoc only on the doc pages for the trait itself, not on the implementation docs.

In addition, there could be a doc comment variant (perhaps ///^ and //!^ respectively) that lowers to #[traitdoc] attributes. This might need an edition though. Alternatively, rust could pick up on an ## Implementer's notes section header instead and emit #[traitdoc] instead of #[doc] attributes for that whole section.

Example

As an example, the PartialEq::ne method could be documented as follows (other methods and attributes have been removed for brevity):

pub trait PartialEq<Rhs: ?Sized = Self> {
    /// Tests for `self != other`.
    #[traitdoc="The default implementation is almost always sufficient,"]
    #[traitdoc="and should not be overridden without very good reason."]
    fn ne(&self, other: &Rhs) -> bool {
        !self.eq(other)
    }
}

Open questions:

  • Attribute naming: Some alternatives are impldoc, trait_doc, trait-doc, impl-doc.
  • Section header or doc comment variant? If the latter, which sigil to append?

cc @GuillaumeGomez

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 by reviewing how rustdoc currently propagates trait method documentation to implementations and how Rust doc comments are lowered to attributes. Compare the proposed traitdoc attribute, doc-comment variant, and section-header approaches, including the open naming and syntax questions. Done means a decided design with clear behavior for trait and implementation documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.