Not all doc-comments on re-exports are displayed
In nix we're aliasing the libc::termios type using pub use libc::termios as Termios. That type has no documentation in libc, but we'd like to offer documentation for the type in our own crate. Specifying a doc comment above it doesn't support anything in the output. It'd be very useful if you could override documentation when aliasing types.
Originally posted at rust-lang/cargo#4250.
Would a type alias work in this case?
/// I cannot comment it here! pub use libc::termios as Termios /// But this works fine! pub type Termios = libc::termios;I think a type alias works almost identically as a re-export (only it shows up in a different rustdoc category).
Alexandre Bury at 2019-10-03 00:30:19
I believe this is fixed on the latest nightly.
Aaron Hill at 2019-10-03 01:43:43
Indeed! Thanks.
A related question: when pub-using an undocumented
enumfrom another crate, I can re-document theenumitself but not the variant (similarly for astruct, I couldn't document the fields).Is there a way to add some attribute to
#[doc()]so that I can document these inner elements from outside?Alexandre Bury at 2019-10-03 04:38:04
This doesn't seem fixed (anymore?). Using a
type =alias is almost as good but doesn't get you the constructor of a tuple-like struct: https://github.com/rust-lang/rust/issues/73191Tavian Barnes at 2020-06-24 14:31:00
Oh I see, it works for public re-exports of a private type. In my case I wanted to do something like this:
pub mod a { /// A foo. pub struct Foo; } pub mod b { /// This doesn't show up anywhere pub use a::Foo as Bar; }Tavian Barnes at 2020-06-24 14:35:30
If you want the second comment to appear, you can add
#[doc(inline)]on the second reexport. It'll generate another page for theBartype. I think having a lint for this would be quite useful.Guillaume Gomez at 2023-02-12 15:54:04