Skip to content

Commit 918e455

Browse files
Improve documentation for re-exports
1 parent cdd5545 commit 918e455

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/doc/rustdoc/src/write-documentation/re-exports.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,35 @@ pub use self::public_mod::Public;
111111
With this code, even though `public_mod::Public` is public and present in the documentation, the
112112
`Public` type will be present both at the crate root and in the `public_mod` module.
113113

114+
## Preventing inlining with `#[doc(no_inline)]`
115+
116+
On the opposite of the `#[doc(inline)]` attribute, if you want to prevent an item from being
117+
inlined, you can use `#[doc(no_inline)]`:
118+
119+
```rust,ignore (inline)
120+
pub mod public_mod {
121+
pub struct Public;
122+
}
123+
124+
#[doc(no_inline)]
125+
pub use self::public_mod::Public;
126+
```
127+
128+
In the generated documentation, you will see a re-export at the crate root and not the type
129+
directly.
130+
114131
## Attributes
115132

116133
When an item is inlined, its doc comments and most of its attributes will be inlined along with it:
117134

118-
| Attribute | Inlined? | Notes
135+
| Attribute | Is it inlined alongside its item? | Notes
119136
|--|--|--
120137
| `#[doc=""]` | Yes | Intra-doc links are resolved relative to where the doc comment is defined (`///` is syntax sugar for doc string attributes).
121138
| `#[doc(cfg(..))]` | Yes |
122139
| `#[deprecated]` | Yes | Intra-doc links are resolved relative to where the description is defined.
123140
| `#[doc(alias="")]` | No |
124141
| `#[doc(inline)]` | No |
125142
| `#[doc(no_inline)]` | No |
126-
| `#[doc(hidden)]` | Glob imports | For name-based imports (such as `use module::Item as ModuleItem`), hiding an item acts the same as making it private. Glob-based imports (such as `use module::*`), hidden items are not inlined.
143+
| `#[doc(hidden)]` | Glob imports | For name-based imports (such as `use module::Item as ModuleItem`), hiding an item acts the same as making it private. For glob-based imports (such as `use module::*`), hidden items are not inlined.
127144

128145
All other attributes are inherited when inlined, so that the documentation matches the behavior if the inlined item was directly defined at the spot where it's shown.

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

+6
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,19 @@ Now we'll have a `Re-exports` line, and `Bar` will not link to anywhere.
223223
One special case: In Rust 2018 and later, if you `pub use` one of your dependencies, `rustdoc` will
224224
not eagerly inline it as a module unless you add `#[doc(inline)]`.
225225

226+
If you want to know more about inlining rules, take a look at the
227+
[`re-exports` chapter](./re-exports.md).
228+
226229
### `hidden`
227230

228231
<span id="dochidden"></span>
229232

230233
Any item annotated with `#[doc(hidden)]` will not appear in the documentation, unless
231234
the `strip-hidden` pass is removed.
232235

236+
For name-based imports (such as `use module::Item as ModuleItem`), hiding an item acts the same as
237+
making it private. For glob-based imports (such as `use module::*`), hidden items are not inlined.
238+
233239
### `alias`
234240

235241
This attribute adds an alias in the search index.

0 commit comments

Comments
 (0)