-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Greatly speed up doctests by compiling compatible doctests in one file #123974
Changes from all commits
86833ee
587c522
4867760
78171c6
e022387
cce04bb
b8f0f2c
56acb5d
882d119
45b075f
cdb59a1
e6f38c5
2c27d9c
76f70fa
f235cbf
b5ca844
e4b74f4
7ea8909
5a3d239
847664a
24a23e1
88cbb78
222f7dc
2e3c2aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -376,6 +376,58 @@ that the code sample should be compiled using the respective edition of Rust. | |||||
# fn foo() {} | ||||||
``` | ||||||
|
||||||
Starting the 2024 edition[^edition-note], compatible doctests will be merged as one before being | ||||||
run. It means that they will share the process, so any change global/static variables will now | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
impact the other doctests. | ||||||
|
||||||
[^edition-note]: This is based on the edition of the whole crate, not the edition of the individual | ||||||
test case that may be specified in its code attribute. | ||||||
|
||||||
For example, if you have: | ||||||
|
||||||
```rust | ||||||
//! ``` | ||||||
//! foo::init(); | ||||||
//! ``` | ||||||
|
||||||
/// ``` | ||||||
/// foo::init(); | ||||||
/// ``` | ||||||
pub fn init() { | ||||||
static mut IS_INIT: bool = false; | ||||||
|
||||||
unsafe { | ||||||
assert!(!IS_INIT); | ||||||
IS_INIT = true; | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
If you run `rustdoc --test` on this code, it'll panic on the second doctest being | ||||||
run because `IS_INIT` value is not `false` anymore. | ||||||
|
||||||
This is where the `standalone` attribute comes in: it tells `rustdoc` that a doctest | ||||||
should not be merged with the others and should be run in its own process. So the | ||||||
previous code should use it: | ||||||
|
||||||
```rust | ||||||
//! ```standalone | ||||||
//! foo::init(); | ||||||
//! ``` | ||||||
|
||||||
/// ```standalone | ||||||
/// foo::init(); | ||||||
/// ``` | ||||||
pub fn init() { | ||||||
static mut IS_INIT: bool = false; | ||||||
|
||||||
unsafe { | ||||||
assert!(!IS_INIT); | ||||||
IS_INIT = true; | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
## Syntax reference | ||||||
|
||||||
The *exact* syntax for code blocks, including the edge cases, can be found | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ The `link_arg_attribute` feature allows passing arguments into the linker | |
from inside of the source code. Order is preserved for link attributes as | ||
they were defined on a single extern block: | ||
|
||
```rust,no_run | ||
```rust,ignore (linking to "c" segfaults) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was it already segfaulting, and the segfault just not getting caught by the test harness, or has something changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually don't know how it could pass before. I opened #124043 about this. |
||
#![feature(link_arg_attribute)] | ||
|
||
#[link(kind = "link-arg", name = "--start-group")] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps also add a sentence explaining that it's for performance reasons? Just so people don't wonder why we're making the change. Could also be worth clarifying that if it fails, the individual tests will be rerun to give an exact error.