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

Document traits from #[derive(...)] #44118

Open
carols10cents opened this issue Aug 27, 2017 · 5 comments
Open

Document traits from #[derive(...)] #44118

carols10cents opened this issue Aug 27, 2017 · 5 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@carols10cents
Copy link
Member

Moving here from rust-lang/cargo#4406 on @dns2utf8's behalf:

While documenting every public function of ThreadPool I had to implement #[derive(Clone) manually so I would be able to add an example.

I assume cargo doc has a default template for the derive-able traits.
So I propose something like this:

#[derive(Clone)
/// My custom doc
/// ```
/// let my = custom.example();
/// ```
#[derive(PartialEq, Eq)
/// My custom doc for both traits
/// ```
/// let my = custom.example();
/// ```
struct CustomStruct;

The template would have to include something like "yield" within the code it is generating.
In this case it should generate something equal to:

impl Clone for CustomStruct {
    /// My custom doc
    /// ```
    /// let my = custom.example();
    /// ```
    fn clone(&self) -> Self { CustomStruct }
}
/* similar for the other two traits */
struct CustomStruct;

What do you think?

@carols10cents carols10cents added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 27, 2017
@sfackler
Copy link
Member

I think this'd make more sense if Rustdoc rendered impl-level documentation - There are two methods in PartialEq, and none in Eq, so it's not totally clear where the docs would go. Even Clone has clone and clone_from.

@durka
Copy link
Contributor

durka commented Aug 28, 2017

Nit: /// doc comments are normally before the item they document.

Furthermore, I think this would need a slightly more complex syntax. Currently,

/// doc 1
#[attr]
/// doc 2
item {}

is the same as

/// doc 1
/// doc 2
#[attr]
item {}

(this is because /// doc just means #[doc="doc"]) so suddenly assigning extra meaning to the order of attributes seems weird IMO.

Something like #[derive(Clone(doc="..."))] or #[derive(Clone)] #[clone(doc="...")] could work, though then you have to stuff everything into a single string, which is annoying.

@steveklabnik
Copy link
Member

I am thinking a change of this magnitude requires an RFC, though I'm not sure.

@carols10cents carols10cents added C-feature-request Category: A feature request, i.e: not implemented / a PR. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Aug 28, 2017
@ollie27
Copy link
Member

ollie27 commented Aug 28, 2017

rust-lang/rfcs#1382 could cover this.

@dns2utf8
Copy link
Contributor

One point that is important to me is, the docs should stay in the same file and near the `#[derive(X)]´

@steveklabnik steveklabnik added T-dev-tools-rustdoc and removed A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels Oct 31, 2017
@QuietMisdreavus QuietMisdreavus added the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Oct 31, 2017
@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants