Skip to content

Commit 5b597b2

Browse files
committed
added rustdoc book documentation, improved behavior when unstable flag not present
1 parent 994144f commit 5b597b2

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

src/doc/rustdoc/src/unstable-features.md

+50
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,53 @@ Some methodology notes about what rustdoc counts in this metric:
455455

456456
Public items that are not documented can be seen with the built-in `missing_docs` lint. Private
457457
items that are not documented can be seen with Clippy's `missing_docs_in_private_items` lint.
458+
459+
### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests
460+
461+
Using this flag looks like this:
462+
463+
```bash
464+
$ rustdoc src/lib.rs -Z unstable-options --enable-per-target-ignores
465+
```
466+
467+
This flag allows you to tag doctests with compiltest style `ignore-foo` filters that prevent
468+
rustdoc from running that test if the target triple string contains foo. For example:
469+
470+
```rust
471+
///```ignore-foo,ignore-bar
472+
///assert!(2 == 2);
473+
///```
474+
struct Foo;
475+
```
476+
477+
This will not be run when the build target is `super-awesome-foo` or `less-bar-awesome`.
478+
If the flag is not enabled, then rustdoc will consume the filter, but do nothing with it, and
479+
the above example will be run for all targets.
480+
If you want to preserve backwards compatibility for older versions of rustdoc, you can use
481+
482+
```rust
483+
///```ignore,ignore-foo
484+
///assert!(2 == 2);
485+
///```
486+
struct Foo;
487+
```
488+
489+
In older versions, this will be ignored on all targets, but on newer versions `ignore-gnu` will
490+
override `ignore`.
491+
492+
### `--runtool`, `--runtool-arg`: program to run tests with; args to pass to it
493+
494+
Using thses options looks like this:
495+
496+
```bash
497+
$ rustdoc src/lib.rs -Z unstable-options --runtool runner --runtool-arg --do-thing --runtool-arg --do-other-thing
498+
```
499+
500+
These options can be used to run the doctest under a program, and also pass arguments to
501+
that program. For example, if you want to run your doctests under valgrind you might run
502+
503+
```bash
504+
$ rustdoc src/lib.rs -Z unstable-options --runtool valgrind
505+
```
506+
507+
Another use case would be to run a test inside an emulator, or through a Virtual Machine.

src/librustdoc/html/markdown.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ impl LangString {
650650
}
651651
"no_run" => { data.no_run = true; seen_rust_tags = !seen_other_tags; }
652652
"ignore" => { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; }
653-
x if enable_per_target_ignores && x.starts_with("ignore-") => {
653+
x if x.starts_with("ignore-") => if enable_per_target_ignores {
654654
ignores.push(x.trim_start_matches("ignore-").to_owned());
655655
seen_rust_tags = !seen_other_tags;
656656
}
@@ -681,15 +681,9 @@ impl LangString {
681681
_ => { seen_other_tags = true }
682682
}
683683
}
684-
685-
match data.ignore {
686-
Ignore::All => {},
687-
Ignore::None => {
688-
if !ignores.is_empty() {
689-
data.ignore = Ignore::Some(ignores);
690-
}
691-
},
692-
_ => unreachable!(),
684+
// ignore-foo overrides ignore
685+
if !ignores.is_empty() {
686+
data.ignore = Ignore::Some(ignores);
693687
}
694688

695689
data.rust &= !seen_other_tags || seen_rust_tags;

src/librustdoc/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ pub fn run(options: Options) -> i32 {
5858
..config::basic_debugging_options()
5959
},
6060
edition: options.edition,
61+
target_triple: options.target.clone(),
6162
..config::Options::default()
6263
};
64+
6365
let config = interface::Config {
6466
opts: sessopts,
6567
crate_cfg: config::parse_cfgspecs(options.cfgs.clone()),

0 commit comments

Comments
 (0)