Skip to content

Commit bc9e082

Browse files
committed
doc doc(inline) and doc(no_inline)
1 parent 99e943c commit bc9e082

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

src/doc/rustdoc/src/the-doc-attribute.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,63 @@ it will not.
9494
These forms of the `#[doc]` attribute are used on individual items, to control how
9595
they are documented.
9696

97-
## `#[doc(no_inline)]`
97+
## `#[doc(no_inline)]`/`#[doc(inline)]`
98+
99+
These attributes are used on `use` statements, and control where the documentation shows
100+
up. For example, consider this Rust code:
101+
102+
```rust
103+
pub use bar::Bar;
104+
105+
/// bar docs
106+
pub mod bar {
107+
/// the docs for Bar
108+
pub struct Bar;
109+
}
110+
```
111+
112+
The documentation will generate a "Reexports" section, and say `pub use bar::Bar;`, where
113+
`Bar` is a link to its page.
114+
115+
If we change the `use` line like this:
116+
117+
```rust,ignore
118+
#[doc(inline)]
119+
pub use bar::Bar;
120+
```
121+
122+
Instead, `Bar` will appear in a `Structs` section, just like `Bar` was defined at the
123+
top level, rather than `pub use`'d.
124+
125+
Let's change our original example, by making `bar` private:
126+
127+
```rust
128+
pub use bar::Bar;
129+
130+
/// bar docs
131+
mod bar {
132+
/// the docs for Bar
133+
pub struct Bar;
134+
}
135+
```
136+
137+
Here, because `bar` is not public, `Bar` wouldn't have its own page, so there's nowhere
138+
to link to. `rustdoc` will inline these definitions, and so we end up in the same case
139+
as the `#[doc(inline)]` above; `Bar` is in a `Structs` section, as if it were defined at
140+
the top level. If we add the `no_inline` form of the attribute:
141+
142+
```rust
143+
#[doc(no_inline)]
144+
pub use bar::Bar;
145+
146+
/// bar docs
147+
mod bar {
148+
/// the docs for Bar
149+
pub struct Bar;
150+
}
151+
```
152+
153+
Now we'll have a `Reexports` line, and `Bar` will not link to anywhere.
98154

99155
## `#[doc(hidden)]`
100156

0 commit comments

Comments
 (0)