Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Aug 10, 2017
1 parent bc9e082 commit 640cf59
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/doc/rustdoc/src/the-doc-attribute.md
Expand Up @@ -3,15 +3,17 @@
The `#[doc]` attribute lets you control various aspects of how `rustdoc` does
its job.

The most basic job of `#[doc]` is to be the way that the text of the documentation
is handled. That is, `///` is syntax sugar for `#[doc]`. This means that these two
The most basic function of `#[doc]` is to handle the actual documentation
text. That is, `///` is syntax sugar for `#[doc]`. This means that these two
are the same:

```rust,ignore
/// This is a doc comment.
#[doc = "This is a doc comment."]
#[doc = " This is a doc comment."]
```

(Note the leading space in the attribute version.)

In most cases, `///` is easier to use than `#[doc]`. One case where the latter is easier is
when generating documentation in macros; the `collapse-docs` pass will combine multiple
`#[doc]` attributes into a single doc comment, letting you generate code like this:
Expand All @@ -22,7 +24,13 @@ when generating documentation in macros; the `collapse-docs` pass will combine m
#[doc = "doc comment"]
```

Which can feel more flexible.
Which can feel more flexible. Note that this would generate this:

```rust,ignore
#[doc = "This is\n a \ndoc comment"]
```

but given that docs are rendered via Markdown, it will remove these newlines.

The `doc` attribute has more options though! These don't involve the text of
the output, but instead, various aspects of the presentation of the output.
Expand Down

0 comments on commit 640cf59

Please sign in to comment.