Skip to content

Commit 14110eb

Browse files
committed
added rustdoc book documentation, improved behavior when unstable flag not present
1 parent 657e24c commit 14110eb

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

Diff for: src/doc/rustdoc/src/unstable-features.md

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

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

Diff for: src/librustdoc/html/markdown.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl LangString {
665665
}
666666
"no_run" => { data.no_run = true; seen_rust_tags = !seen_other_tags; }
667667
"ignore" => { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; }
668-
x if enable_per_target_ignores && x.starts_with("ignore-") => {
668+
x if x.starts_with("ignore-") => if enable_per_target_ignores {
669669
ignores.push(x.trim_start_matches("ignore-").to_owned());
670670
seen_rust_tags = !seen_other_tags;
671671
}
@@ -696,15 +696,9 @@ impl LangString {
696696
_ => { seen_other_tags = true }
697697
}
698698
}
699-
700-
match data.ignore {
701-
Ignore::All => {},
702-
Ignore::None => {
703-
if !ignores.is_empty() {
704-
data.ignore = Ignore::Some(ignores);
705-
}
706-
},
707-
_ => unreachable!(),
699+
// ignore-foo overrides ignore
700+
if !ignores.is_empty() {
701+
data.ignore = Ignore::Some(ignores);
708702
}
709703

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

Diff for: 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)