Skip to content

Commit

Permalink
Improve documentation for re-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 17, 2023
1 parent cdd5545 commit 918e455
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/doc/rustdoc/src/write-documentation/re-exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,35 @@ pub use self::public_mod::Public;
With this code, even though `public_mod::Public` is public and present in the documentation, the
`Public` type will be present both at the crate root and in the `public_mod` module.

## Preventing inlining with `#[doc(no_inline)]`

On the opposite of the `#[doc(inline)]` attribute, if you want to prevent an item from being
inlined, you can use `#[doc(no_inline)]`:

```rust,ignore (inline)
pub mod public_mod {
pub struct Public;
}
#[doc(no_inline)]
pub use self::public_mod::Public;
```

In the generated documentation, you will see a re-export at the crate root and not the type
directly.

## Attributes

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

| Attribute | Inlined? | Notes
| Attribute | Is it inlined alongside its item? | Notes
|--|--|--
| `#[doc=""]` | Yes | Intra-doc links are resolved relative to where the doc comment is defined (`///` is syntax sugar for doc string attributes).
| `#[doc(cfg(..))]` | Yes |
| `#[deprecated]` | Yes | Intra-doc links are resolved relative to where the description is defined.
| `#[doc(alias="")]` | No |
| `#[doc(inline)]` | No |
| `#[doc(no_inline)]` | No |
| `#[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.
| `#[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.

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.
6 changes: 6 additions & 0 deletions src/doc/rustdoc/src/write-documentation/the-doc-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,19 @@ Now we'll have a `Re-exports` line, and `Bar` will not link to anywhere.
One special case: In Rust 2018 and later, if you `pub use` one of your dependencies, `rustdoc` will
not eagerly inline it as a module unless you add `#[doc(inline)]`.

If you want to know more about inlining rules, take a look at the
[`re-exports` chapter](./re-exports.md).

### `hidden`

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

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

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.

### `alias`

This attribute adds an alias in the search index.
Expand Down

0 comments on commit 918e455

Please sign in to comment.