You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rustdoc currently hides implementated trait methods behind a "Show hidden undocumented items" switch, unless a new doc comment was supplied on the method implementation. For example, consider this code:
pubtraitTest{/// This trait method does X...fnfoo(&self);/// This trait method does Y...fnbar(&self);}pubstructTestImpl;implTestforTestImpl{fnfoo(&self){}/// A special trait implementation that deserves/// some custom documentation.fnbar(&self){}}
The generated documentation looks like this:
Only the bar method is shown because its implementation has a custom doc comment, which indicates that it is somewhat important or special.
Methods with Default Implementations
Trait methods can have default implementations directly in the trait definition:
pubtraitFoo{/// Do somethingfndo_something(&self);/// Do something twicefndo_something_twice(&self){self.do_something();self.do_something();}}pubstructBar;implFooforBar{fndo_something(&self){println!("Bar");}}
Since do_something_twice has a default implementation, we don't need to provide an implementation when implementing the trait.
The generated documentation looks like this:
The do_something_twice method is shown even though it is not mentioned in the impl block. I think the reason is that there is a doc comment on the used default implementation in the trait definition, which rustdoc treats exactly like the doc comment on the bar implementation above.
The Problem
The current behavior causes confusion in several ways:
Default methods and method implementations with a custom doc string look exactly the same:
Here, only the do_something implementation provides an own doc comment. The do_something_twice method looks exactly the same, but it is just a default implementation with the doc comment from the trait definition.
Often, the unimportant methods with default implementations are shown, while more important ones are hidden. For example, this CommandExt implementation shows only the deprecated before_exec function because it has a default implementation.
It sometimes shows a seemingly random set of methods, leading to confusion. For example, for most implementations of PartialEq only the ne method is shown. The reason is that it has a default implementation around eq, but this doesn't really matter to the reader.
A Possible Solution
I think it would be more intuitive to also hide methods with default implementations when they're not overridden in the impl block.
Meta
This issue was originally reported in #56546 (comment). I used some examples from this thread for creating this issue.
Background
Rustdoc currently hides implementated trait methods behind a "Show hidden undocumented items" switch, unless a new doc comment was supplied on the method implementation. For example, consider this code:
The generated documentation looks like this:
Only the
bar
method is shown because its implementation has a custom doc comment, which indicates that it is somewhat important or special.Methods with Default Implementations
Trait methods can have default implementations directly in the trait definition:
Since
do_something_twice
has a default implementation, we don't need to provide an implementation when implementing the trait.The generated documentation looks like this:
The
do_something_twice
method is shown even though it is not mentioned in theimpl
block. I think the reason is that there is a doc comment on the used default implementation in the trait definition, whichrustdoc
treats exactly like the doc comment on thebar
implementation above.The Problem
The current behavior causes confusion in several ways:
Here, only the
do_something
implementation provides an own doc comment. Thedo_something_twice
method looks exactly the same, but it is just a default implementation with the doc comment from the trait definition.CommandExt
implementation shows only the deprecatedbefore_exec
function because it has a default implementation.PartialEq
only thene
method is shown. The reason is that it has a default implementation aroundeq
, but this doesn't really matter to the reader.A Possible Solution
I think it would be more intuitive to also hide methods with default implementations when they're not overridden in the
impl
block.Meta
This issue was originally reported in #56546 (comment). I used some examples from this thread for creating this issue.
cc @GuillaumeGomez
The text was updated successfully, but these errors were encountered: