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
{{ message }}
Repository navigation
Rustdoc doesn't see trait implementations inside of functions #41480
It's possible to define trait implementations inside of functions in Rust. This is useful not too often, but particularly nice if you have a macro that both defines trait implementation and calls some initialization for a given type.
Anyway, the following code is valid in Rust itself:
But Rustdoc doesn't generate documentation for a given trait, despite it being visible to Rust itself, and being immediately available and unique across entire crate.
I can move impl out of the function and then it gets seen by Rustdoc, but this is rather inconvenient when impl is generated as part of a bigger macro.
The scope of the implementation is only inside the function and so cannot be used outside of it and so shouldn't be documented. Also, macro != functions. If you make an implementation inside a macro, it's documented.
Closing it then, don't hesitate to reopen it if I missed something.
The scope of the implementation is only inside the function and so cannot be used outside of it and so shouldn't be documented.
No, this is exactly the problem I was referring to - impl is not scoped. In Rust itself it's visible across entire codebase despite being declared inside of a function.
Also, macro != functions. If you make an implementation inside a macro, it's documented.
I referred to macro only because I'm using them inside of such function to generate bothimpl and a call to some other function.
Got bit by this. rustdoc were simply unable to find a trait implementation defined in a function which cargo build picked up fine https://docs.rs/crate/serde_state/0.4.2/builds/77728 . Thought I was going crazy for second there.
Activity
GuillaumeGomez commentedon Apr 25, 2017
The scope of the implementation is only inside the function and so cannot be used outside of it and so shouldn't be documented. Also, macro != functions. If you make an implementation inside a macro, it's documented.
Closing it then, don't hesitate to reopen it if I missed something.
RReverser commentedon Apr 25, 2017
No, this is exactly the problem I was referring to -
implis not scoped. In Rust itself it's visible across entire codebase despite being declared inside of a function.I referred to macro only because I'm using them inside of such function to generate both
impland a call to some other function.RReverser commentedon Apr 25, 2017
To enhance the example above:
^^
Fromworks here as expected, as well as other crates that depend on this one, can use it, which is why it's important to have it documented.@GuillaumeGomez
petrochenkov commentedon Apr 25, 2017
(GitHub doesn't allow non-members to reopen issues closed by others.)
RReverser commentedon Apr 25, 2017
Indeed, thanks for reopening this!
GuillaumeGomez commentedon Apr 25, 2017
Thanks for reopening it @petrochenkov.
@RReverser: That's completely crazy. Another example just for the fun:
So rustdoc should document these implementations as well. Thanks for opening the issue!
Marwes commentedon Nov 29, 2017
Got bit by this. rustdoc were simply unable to find a trait implementation defined in a function which
cargo buildpicked up fine https://docs.rs/crate/serde_state/0.4.2/builds/77728 . Thought I was going crazy for second there.QuietMisdreavus commentedon Aug 7, 2018
I've opened #53162 to fix this.
Auto merge of #53162 - QuietMisdreavus:crouching-impl-hidden-trait, r…
Rollup merge of rust-lang#53162 - QuietMisdreavus:crouching-impl-hidd…
Rollup merge of rust-lang#53162 - QuietMisdreavus:crouching-impl-hidd…