rustdoc: interpret all leading feature attributes in examples as crate attributes
This makes it possible to write `#![feature(foo)]` in doc tests.
This commit is contained in:
parent
809a554fca
commit
3d365f6a01
3 changed files with 46 additions and 9 deletions
|
|
@ -237,14 +237,17 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
Here's the full algorithm:
|
||||
Here's the full algorithm rustdoc uses to postprocess examples:
|
||||
|
||||
1. Given a code block, if it does not contain `fn main()`, it is wrapped in
|
||||
`fn main() { your_code }`
|
||||
2. Given that result, if it contains no `extern crate` directives but it also
|
||||
contains the name of the crate being tested, then `extern crate <name>` is
|
||||
injected at the top.
|
||||
3. Some common allow attributes are added for documentation examples at the top.
|
||||
1. Any leading `#![foo]` attributes are left intact as crate attributes.
|
||||
2. Some common `allow` attributes are inserted, including
|
||||
`unused_variables`, `unused_assignments`, `unused_mut`,
|
||||
`unused_attributes`, and `dead_code`. Small examples often trigger
|
||||
these lints.
|
||||
3. If the example does not contain `extern crate`, then `extern crate
|
||||
<mycrate>;` is inserted.
|
||||
2. Finally, if the example does not contain `fn main`, the remainder of the
|
||||
text is wrapped in `fn main() { your_code }`
|
||||
|
||||
Sometimes, this isn't enough, though. For example, all of these code samples
|
||||
with `///` we've been talking about? The raw text:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue