Skip to content

Commit 8aaa90b

Browse files
committed
Remove and stabilize --enable-per-target-ignores
This removes the `--enable-per-target-ignores` and enables it unconditionally.
1 parent 2d77a40 commit 8aaa90b

File tree

12 files changed

+43
-92
lines changed

12 files changed

+43
-92
lines changed

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

-35
Original file line numberDiff line numberDiff line change
@@ -612,41 +612,6 @@ The generated output (formatted) will look like this:
612612
`--output-format html` has no effect, as the default output is HTML. This is
613613
accepted on stable, even though the other options for this flag aren't.
614614

615-
## `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests
616-
617-
* Tracking issue: [#64245](https://github.com/rust-lang/rust/issues/64245)
618-
619-
Using this flag looks like this:
620-
621-
```bash
622-
$ rustdoc src/lib.rs -Z unstable-options --enable-per-target-ignores
623-
```
624-
625-
This flag allows you to tag doctests with compiletest style `ignore-foo` filters that prevent
626-
rustdoc from running that test if the target triple string contains foo. For example:
627-
628-
```rust
629-
///```ignore-foo,ignore-bar
630-
///assert!(2 == 2);
631-
///```
632-
struct Foo;
633-
```
634-
635-
This will not be run when the build target is `super-awesome-foo` or `less-bar-awesome`.
636-
If the flag is not enabled, then rustdoc will consume the filter, but do nothing with it, and
637-
the above example will be run for all targets.
638-
If you want to preserve backwards compatibility for older versions of rustdoc, you can use
639-
640-
```rust
641-
///```ignore,ignore-foo
642-
///assert!(2 == 2);
643-
///```
644-
struct Foo;
645-
```
646-
647-
In older versions, this will be ignored on all targets, but on newer versions `ignore-gnu` will
648-
override `ignore`.
649-
650615
## `--with-examples`: include examples of uses of items as documentation
651616

652617
* Tracking issue: [#88791](https://github.com/rust-lang/rust/issues/88791)

src/doc/rustdoc/src/write-documentation/documentation-tests.md

+28
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,34 @@ should not be merged with the others. So the previous code should use it:
427427
In this case, it means that the line information will not change if you add/remove other
428428
doctests.
429429

430+
### Ignoring targets
431+
432+
Attributes starting with `ignore-` can be used to ignore doctests for specific
433+
targets. For example, `ignore-x86_64` will avoid building doctests when the
434+
target name contains `x86_64`.
435+
436+
```rust
437+
/// ```ignore-x86_64
438+
/// assert!(2 == 2);
439+
/// ```
440+
struct Foo;
441+
```
442+
443+
This doctest will not be built for targets such as `x86_64-unknown-linux-gnu`.
444+
445+
If you want to preserve backwards compatibility for older versions of rustdoc,
446+
you can specify both `ignore` and `ignore-`, such as:
447+
448+
```rust
449+
/// ```ignore,ignore-x86_64
450+
/// assert!(2 == 2);
451+
/// ```
452+
struct Foo;
453+
```
454+
455+
In older versions, this will be ignored on all targets, but starting with
456+
version CURRENT_RUSTC_VERSION, `ignore-x86_64` will override `ignore`.
457+
430458
### Custom CSS classes for code blocks
431459

432460
```rust

src/librustdoc/config.rs

-7
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ pub(crate) struct Options {
125125
pub(crate) test_runtool: Option<String>,
126126
/// Arguments to pass to the runtool
127127
pub(crate) test_runtool_args: Vec<String>,
128-
/// Whether to allow ignoring doctests on a per-target basis
129-
/// For example, using ignore-foo to ignore running the doctest on any target that
130-
/// contains "foo" as a substring
131-
pub(crate) enable_per_target_ignores: bool,
132128
/// Do not run doctests, compile them if should_test is active.
133129
pub(crate) no_run: bool,
134130
/// What sources are being mapped.
@@ -214,7 +210,6 @@ impl fmt::Debug for Options {
214210
.field("crate_version", &self.crate_version)
215211
.field("test_runtool", &self.test_runtool)
216212
.field("test_runtool_args", &self.test_runtool_args)
217-
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
218213
.field("run_check", &self.run_check)
219214
.field("no_run", &self.no_run)
220215
.field("test_builder_wrappers", &self.test_builder_wrappers)
@@ -767,7 +762,6 @@ impl Options {
767762
let extern_strs = matches.opt_strs("extern");
768763
let test_runtool = matches.opt_str("test-runtool");
769764
let test_runtool_args = matches.opt_strs("test-runtool-arg");
770-
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
771765
let document_private = matches.opt_present("document-private-items");
772766
let document_hidden = matches.opt_present("document-hidden-items");
773767
let run_check = matches.opt_present("check");
@@ -830,7 +824,6 @@ impl Options {
830824
persist_doctests,
831825
test_runtool,
832826
test_runtool_args,
833-
enable_per_target_ignores,
834827
test_builder,
835828
run_check,
836829
no_run,

src/librustdoc/doctest.rs

-2
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,9 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
218218
let crate_name = tcx.crate_name(LOCAL_CRATE).to_string();
219219
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
220220
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
221-
let enable_per_target_ignores = options.enable_per_target_ignores;
222221

223222
let hir_collector = HirCollector::new(
224223
ErrorCodes::from(compiler.sess.opts.unstable_features.is_nightly_build()),
225-
enable_per_target_ignores,
226224
tcx,
227225
);
228226
let tests = hir_collector.collect_crate();

src/librustdoc/doctest/markdown.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,7 @@ pub(crate) fn test(input: &Input, options: Options) -> Result<(), String> {
104104
};
105105
let codes = ErrorCodes::from(options.unstable_features.is_nightly_build());
106106

107-
find_testable_code(
108-
&input_str,
109-
&mut md_collector,
110-
codes,
111-
options.enable_per_target_ignores,
112-
None,
113-
);
107+
find_testable_code(&input_str, &mut md_collector, codes, None);
114108

115109
let mut collector = CreateRunnableDocTests::new(options.clone(), opts);
116110
md_collector.tests.into_iter().for_each(|t| collector.add_test(t));

src/librustdoc/doctest/rust.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,18 @@ impl DocTestVisitor for RustCollector {
6363
pub(super) struct HirCollector<'tcx> {
6464
codes: ErrorCodes,
6565
tcx: TyCtxt<'tcx>,
66-
enable_per_target_ignores: bool,
6766
collector: RustCollector,
6867
}
6968

7069
impl<'tcx> HirCollector<'tcx> {
71-
pub fn new(codes: ErrorCodes, enable_per_target_ignores: bool, tcx: TyCtxt<'tcx>) -> Self {
70+
pub fn new(codes: ErrorCodes, tcx: TyCtxt<'tcx>) -> Self {
7271
let collector = RustCollector {
7372
source_map: tcx.sess.psess.clone_source_map(),
7473
cur_path: vec![],
7574
position: DUMMY_SP,
7675
tests: vec![],
7776
};
78-
Self { codes, enable_per_target_ignores, tcx, collector }
77+
Self { codes, tcx, collector }
7978
}
8079

8180
pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
@@ -131,7 +130,6 @@ impl HirCollector<'_> {
131130
&doc,
132131
&mut self.collector,
133132
self.codes,
134-
self.enable_per_target_ignores,
135133
Some(&crate::html::markdown::ExtraInfo::new(self.tcx, def_id, span)),
136134
);
137135
}

src/librustdoc/html/markdown.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
246246
match kind {
247247
CodeBlockKind::Fenced(ref lang) => {
248248
let parse_result =
249-
LangString::parse_without_check(lang, self.check_error_codes, false);
249+
LangString::parse_without_check(lang, self.check_error_codes);
250250
if !parse_result.rust {
251251
let added_classes = parse_result.added_classes;
252252
let lang_string = if let Some(lang) = parse_result.unknown.first() {
@@ -707,17 +707,15 @@ pub(crate) fn find_testable_code<T: doctest::DocTestVisitor>(
707707
doc: &str,
708708
tests: &mut T,
709709
error_codes: ErrorCodes,
710-
enable_per_target_ignores: bool,
711710
extra_info: Option<&ExtraInfo<'_>>,
712711
) {
713-
find_codes(doc, tests, error_codes, enable_per_target_ignores, extra_info, false)
712+
find_codes(doc, tests, error_codes, extra_info, false)
714713
}
715714

716715
pub(crate) fn find_codes<T: doctest::DocTestVisitor>(
717716
doc: &str,
718717
tests: &mut T,
719718
error_codes: ErrorCodes,
720-
enable_per_target_ignores: bool,
721719
extra_info: Option<&ExtraInfo<'_>>,
722720
include_non_rust: bool,
723721
) {
@@ -733,12 +731,7 @@ pub(crate) fn find_codes<T: doctest::DocTestVisitor>(
733731
if lang.is_empty() {
734732
Default::default()
735733
} else {
736-
LangString::parse(
737-
lang,
738-
error_codes,
739-
enable_per_target_ignores,
740-
extra_info,
741-
)
734+
LangString::parse(lang, error_codes, extra_info)
742735
}
743736
}
744737
CodeBlockKind::Indented => Default::default(),
@@ -1162,18 +1155,13 @@ impl Default for LangString {
11621155
}
11631156

11641157
impl LangString {
1165-
fn parse_without_check(
1166-
string: &str,
1167-
allow_error_code_check: ErrorCodes,
1168-
enable_per_target_ignores: bool,
1169-
) -> Self {
1170-
Self::parse(string, allow_error_code_check, enable_per_target_ignores, None)
1158+
fn parse_without_check(string: &str, allow_error_code_check: ErrorCodes) -> Self {
1159+
Self::parse(string, allow_error_code_check, None)
11711160
}
11721161

11731162
fn parse(
11741163
string: &str,
11751164
allow_error_code_check: ErrorCodes,
1176-
enable_per_target_ignores: bool,
11771165
extra: Option<&ExtraInfo<'_>>,
11781166
) -> Self {
11791167
let allow_error_code_check = allow_error_code_check.as_bool();
@@ -1201,10 +1189,8 @@ impl LangString {
12011189
seen_rust_tags = !seen_other_tags;
12021190
}
12031191
LangStringToken::LangToken(x) if x.starts_with("ignore-") => {
1204-
if enable_per_target_ignores {
1205-
ignores.push(x.trim_start_matches("ignore-").to_owned());
1206-
seen_rust_tags = !seen_other_tags;
1207-
}
1192+
ignores.push(x.trim_start_matches("ignore-").to_owned());
1193+
seen_rust_tags = !seen_other_tags;
12081194
}
12091195
LangStringToken::LangToken("rust") => {
12101196
data.rust = true;
@@ -1906,7 +1892,7 @@ pub(crate) fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<Rust
19061892
let lang_string = if syntax.is_empty() {
19071893
Default::default()
19081894
} else {
1909-
LangString::parse(syntax, ErrorCodes::Yes, false, Some(extra_info))
1895+
LangString::parse(syntax, ErrorCodes::Yes, Some(extra_info))
19101896
};
19111897
if !lang_string.rust {
19121898
continue;

src/librustdoc/html/markdown/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn test_unique_id() {
4949
fn test_lang_string_parse() {
5050
fn t(lg: LangString) {
5151
let s = &lg.original;
52-
assert_eq!(LangString::parse(s, ErrorCodes::Yes, true, None), lg)
52+
assert_eq!(LangString::parse(s, ErrorCodes::Yes, None), lg)
5353
}
5454

5555
t(Default::default());
@@ -479,7 +479,7 @@ fn test_markdown_html_escape() {
479479
fn test_find_testable_code_line() {
480480
fn t(input: &str, expect: &[usize]) {
481481
let mut lines = Vec::<usize>::new();
482-
find_testable_code(input, &mut lines, ErrorCodes::No, false, None);
482+
find_testable_code(input, &mut lines, ErrorCodes::No, None);
483483
assert_eq!(lines, expect);
484484
}
485485

src/librustdoc/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,6 @@ fn opts() -> Vec<RustcOptGroup> {
507507
"calculate percentage of public items with documentation",
508508
"",
509509
),
510-
opt(
511-
Unstable,
512-
FlagMulti,
513-
"",
514-
"enable-per-target-ignores",
515-
"parse ignore-foo for ignoring doctests on a per-target basis",
516-
"",
517-
),
518510
opt(
519511
Stable,
520512
Opt,

src/librustdoc/passes/calculate_doc_coverage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl DocVisitor<'_> for CoverageCalculator<'_, '_> {
212212
let has_docs = !i.attrs.doc_strings.is_empty();
213213
let mut tests = Tests { found_tests: 0 };
214214

215-
find_testable_code(&i.doc_value(), &mut tests, ErrorCodes::No, false, None);
215+
find_testable_code(&i.doc_value(), &mut tests, ErrorCodes::No, None);
216216

217217
let has_doc_example = tests.found_tests != 0;
218218
let hir_id = DocContext::as_local_hir_id(self.ctx.tcx, i.item_id).unwrap();

src/librustdoc/passes/check_doc_test_visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub(crate) fn look_for_tests(cx: &DocContext<'_>, dox: &str, item: &Item) {
122122

123123
let mut tests = Tests { found_tests: 0 };
124124

125-
find_testable_code(dox, &mut tests, ErrorCodes::No, false, None);
125+
find_testable_code(dox, &mut tests, ErrorCodes::No, None);
126126

127127
if tests.found_tests == 0 && cx.tcx.features().rustdoc_missing_doc_code_examples() {
128128
if should_have_doc_example(cx, item) {

tests/run-make/rustdoc-default-output/output-default.stdout

-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ Options:
138138
--show-coverage
139139
calculate percentage of public items with
140140
documentation
141-
--enable-per-target-ignores
142-
parse ignore-foo for ignoring doctests on a per-target
143-
basis
144141
--test-runtool The tool to run tests with when building for a different target than host
145142

146143
--test-runtool-arg One (of possibly many) arguments to pass to the runtool

0 commit comments

Comments
 (0)