Skip to content

Commit fa55f38

Browse files
authored
Unrolled build for #147292
Rollup merge of #147292 - Urgau:rustdoc-test-unstable_opts, r=fmease Respect `-Z` unstable options in `rustdoc --test` This PR makes rustdoc respect `-Z` unstable options when collecting doctests (`rustdoc --test`). In the process I also realized that `--error-format` wasn't respected as well, making UI annotations impossible to write so I fixed that as well. Best reviewed commit by commit. Fixes #147276 Fixes #143930 r? fmease
2 parents 7950f24 + c1443e2 commit fa55f38

23 files changed

+213
-134
lines changed

src/librustdoc/doctest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
173173
target_triple: options.target.clone(),
174174
crate_name: options.crate_name.clone(),
175175
remap_path_prefix: options.remap_path_prefix.clone(),
176+
unstable_opts: options.unstable_opts.clone(),
177+
error_format: options.error_format.clone(),
176178
..config::Options::default()
177179
};
178180

tests/rustdoc-ui/doctest/check-attr-test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,39 @@
22

33
#![deny(rustdoc::invalid_codeblock_attributes)]
44

5+
//~vvv ERROR unknown attribute `compile-fail`
6+
//~| ERROR unknown attribute `compilefail`
7+
//~| ERROR unknown attribute `comPile_fail`
58
/// foo
69
///
710
/// ```compile-fail,compilefail,comPile_fail
811
/// boo
912
/// ```
1013
pub fn foo() {}
1114

15+
//~vvv ERROR unknown attribute `should-panic`
16+
//~| ERROR unknown attribute `shouldpanic`
17+
//~| ERROR unknown attribute `shOuld_panic`
1218
/// bar
1319
///
1420
/// ```should-panic,shouldpanic,shOuld_panic
1521
/// boo
1622
/// ```
1723
pub fn bar() {}
1824

25+
//~vvv ERROR unknown attribute `no-run`
26+
//~| ERROR unknown attribute `norun`
27+
//~| ERROR unknown attribute `nO_run`
1928
/// foobar
2029
///
2130
/// ```no-run,norun,nO_run
2231
/// boo
2332
/// ```
2433
pub fn foobar() {}
2534

35+
//~vvv ERROR unknown attribute `test-harness`
36+
//~| ERROR unknown attribute `testharness`
37+
//~| ERROR unknown attribute `tesT_harness`
2638
/// b
2739
///
2840
/// ```test-harness,testharness,tesT_harness

tests/rustdoc-ui/doctest/check-attr-test.stderr

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,159 @@
11
error: unknown attribute `compile-fail`
2-
--> $DIR/check-attr-test.rs:5:1
3-
|
4-
5 | / /// foo
5-
6 | | ///
6-
7 | | /// ```compile-fail,compilefail,comPile_fail
7-
8 | | /// boo
8-
9 | | /// ```
9-
| |_______^
10-
|
11-
= help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
12-
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
2+
--> $DIR/check-attr-test.rs:8:1
3+
|
4+
LL | / /// foo
5+
LL | | ///
6+
LL | | /// ```compile-fail,compilefail,comPile_fail
7+
LL | | /// boo
8+
LL | | /// ```
9+
| |_______^
10+
|
11+
= help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
12+
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
1313
note: the lint level is defined here
14-
--> $DIR/check-attr-test.rs:3:9
15-
|
16-
3 | #![deny(rustdoc::invalid_codeblock_attributes)]
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
--> $DIR/check-attr-test.rs:3:9
15+
|
16+
LL | #![deny(rustdoc::invalid_codeblock_attributes)]
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error: unknown attribute `compilefail`
20-
--> $DIR/check-attr-test.rs:5:1
21-
|
22-
5 | / /// foo
23-
6 | | ///
24-
7 | | /// ```compile-fail,compilefail,comPile_fail
25-
8 | | /// boo
26-
9 | | /// ```
27-
| |_______^
28-
|
29-
= help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
30-
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
20+
--> $DIR/check-attr-test.rs:8:1
21+
|
22+
LL | / /// foo
23+
LL | | ///
24+
LL | | /// ```compile-fail,compilefail,comPile_fail
25+
LL | | /// boo
26+
LL | | /// ```
27+
| |_______^
28+
|
29+
= help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
30+
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
3131

3232
error: unknown attribute `comPile_fail`
33-
--> $DIR/check-attr-test.rs:5:1
34-
|
35-
5 | / /// foo
36-
6 | | ///
37-
7 | | /// ```compile-fail,compilefail,comPile_fail
38-
8 | | /// boo
39-
9 | | /// ```
40-
| |_______^
41-
|
42-
= help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
43-
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
33+
--> $DIR/check-attr-test.rs:8:1
34+
|
35+
LL | / /// foo
36+
LL | | ///
37+
LL | | /// ```compile-fail,compilefail,comPile_fail
38+
LL | | /// boo
39+
LL | | /// ```
40+
| |_______^
41+
|
42+
= help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
43+
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
4444

4545
error: unknown attribute `should-panic`
46-
--> $DIR/check-attr-test.rs:12:1
46+
--> $DIR/check-attr-test.rs:18:1
4747
|
48-
12 | / /// bar
49-
13 | | ///
50-
14 | | /// ```should-panic,shouldpanic,shOuld_panic
51-
15 | | /// boo
52-
16 | | /// ```
48+
LL | / /// bar
49+
LL | | ///
50+
LL | | /// ```should-panic,shouldpanic,shOuld_panic
51+
LL | | /// boo
52+
LL | | /// ```
5353
| |_______^
5454
|
5555
= help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
5656
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
5757

5858
error: unknown attribute `shouldpanic`
59-
--> $DIR/check-attr-test.rs:12:1
59+
--> $DIR/check-attr-test.rs:18:1
6060
|
61-
12 | / /// bar
62-
13 | | ///
63-
14 | | /// ```should-panic,shouldpanic,shOuld_panic
64-
15 | | /// boo
65-
16 | | /// ```
61+
LL | / /// bar
62+
LL | | ///
63+
LL | | /// ```should-panic,shouldpanic,shOuld_panic
64+
LL | | /// boo
65+
LL | | /// ```
6666
| |_______^
6767
|
6868
= help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
6969
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
7070

7171
error: unknown attribute `shOuld_panic`
72-
--> $DIR/check-attr-test.rs:12:1
72+
--> $DIR/check-attr-test.rs:18:1
7373
|
74-
12 | / /// bar
75-
13 | | ///
76-
14 | | /// ```should-panic,shouldpanic,shOuld_panic
77-
15 | | /// boo
78-
16 | | /// ```
74+
LL | / /// bar
75+
LL | | ///
76+
LL | | /// ```should-panic,shouldpanic,shOuld_panic
77+
LL | | /// boo
78+
LL | | /// ```
7979
| |_______^
8080
|
8181
= help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
8282
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
8383

8484
error: unknown attribute `no-run`
85-
--> $DIR/check-attr-test.rs:19:1
85+
--> $DIR/check-attr-test.rs:28:1
8686
|
87-
19 | / /// foobar
88-
20 | | ///
89-
21 | | /// ```no-run,norun,nO_run
90-
22 | | /// boo
91-
23 | | /// ```
87+
LL | / /// foobar
88+
LL | | ///
89+
LL | | /// ```no-run,norun,nO_run
90+
LL | | /// boo
91+
LL | | /// ```
9292
| |_______^
9393
|
9494
= help: use `no_run` to compile, but not run, the code sample during testing
9595
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
9696

9797
error: unknown attribute `norun`
98-
--> $DIR/check-attr-test.rs:19:1
98+
--> $DIR/check-attr-test.rs:28:1
9999
|
100-
19 | / /// foobar
101-
20 | | ///
102-
21 | | /// ```no-run,norun,nO_run
103-
22 | | /// boo
104-
23 | | /// ```
100+
LL | / /// foobar
101+
LL | | ///
102+
LL | | /// ```no-run,norun,nO_run
103+
LL | | /// boo
104+
LL | | /// ```
105105
| |_______^
106106
|
107107
= help: use `no_run` to compile, but not run, the code sample during testing
108108
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
109109

110110
error: unknown attribute `nO_run`
111-
--> $DIR/check-attr-test.rs:19:1
111+
--> $DIR/check-attr-test.rs:28:1
112112
|
113-
19 | / /// foobar
114-
20 | | ///
115-
21 | | /// ```no-run,norun,nO_run
116-
22 | | /// boo
117-
23 | | /// ```
113+
LL | / /// foobar
114+
LL | | ///
115+
LL | | /// ```no-run,norun,nO_run
116+
LL | | /// boo
117+
LL | | /// ```
118118
| |_______^
119119
|
120120
= help: use `no_run` to compile, but not run, the code sample during testing
121121
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
122122

123123
error: unknown attribute `test-harness`
124-
--> $DIR/check-attr-test.rs:26:1
124+
--> $DIR/check-attr-test.rs:38:1
125125
|
126-
26 | / /// b
127-
27 | | ///
128-
28 | | /// ```test-harness,testharness,tesT_harness
129-
29 | | /// boo
130-
30 | | /// ```
126+
LL | / /// b
127+
LL | | ///
128+
LL | | /// ```test-harness,testharness,tesT_harness
129+
LL | | /// boo
130+
LL | | /// ```
131131
| |_______^
132132
|
133133
= help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
134134
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
135135

136136
error: unknown attribute `testharness`
137-
--> $DIR/check-attr-test.rs:26:1
137+
--> $DIR/check-attr-test.rs:38:1
138138
|
139-
26 | / /// b
140-
27 | | ///
141-
28 | | /// ```test-harness,testharness,tesT_harness
142-
29 | | /// boo
143-
30 | | /// ```
139+
LL | / /// b
140+
LL | | ///
141+
LL | | /// ```test-harness,testharness,tesT_harness
142+
LL | | /// boo
143+
LL | | /// ```
144144
| |_______^
145145
|
146146
= help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
147147
= help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
148148

149149
error: unknown attribute `tesT_harness`
150-
--> $DIR/check-attr-test.rs:26:1
150+
--> $DIR/check-attr-test.rs:38:1
151151
|
152-
26 | / /// b
153-
27 | | ///
154-
28 | | /// ```test-harness,testharness,tesT_harness
155-
29 | | /// boo
156-
30 | | /// ```
152+
LL | / /// b
153+
LL | | ///
154+
LL | | /// ```test-harness,testharness,tesT_harness
155+
LL | | /// boo
156+
LL | | /// ```
157157
| |_______^
158158
|
159159
= help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function

tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/// <https://github.com/rust-lang/rust/issues/91014>
1010
///
1111
/// ```rust
12+
//~^ WARN the `main` function of this doctest won't be run
1213
/// struct S {};
1314
///
1415
/// fn main() {

tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function
22
--> $DIR/failed-doctest-extra-semicolon-on-item.rs:11:1
33
|
4-
11 | /// ```rust
4+
LL | /// ```rust
55
| ^^^^^^^^^^^
66

77
warning: 1 warning emitted

tests/rustdoc-ui/doctest/main-alongside-stmts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
1515
//@ check-pass
1616

17+
//~v WARN the `main` function of this doctest won't be run
1718
//! ```
1819
//! # if cfg!(miri) { return; }
1920
//! use std::ops::Deref;
@@ -22,6 +23,7 @@
2223
//! assert!(false);
2324
//! }
2425
//! ```
26+
//~v WARN the `main` function of this doctest won't be run
2527
//!
2628
//! ```
2729
//! let x = 2;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function
2-
--> $DIR/main-alongside-stmts.rs:17:1
2+
--> $DIR/main-alongside-stmts.rs:18:1
33
|
4-
17 | //! ```
4+
LL | //! ```
55
| ^^^^^^^
66

77
warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function
8-
--> $DIR/main-alongside-stmts.rs:26:1
8+
--> $DIR/main-alongside-stmts.rs:27:1
99
|
10-
26 | //! ```
11-
| ^^^^^^^
10+
LL | //!
11+
| ^^^
1212

1313
warning: 2 warnings emitted
1414

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
running 2 tests
3-
test $DIR/main-alongside-stmts.rs - (line 17) ... ok
4-
test $DIR/main-alongside-stmts.rs - (line 26) ... ok
3+
test $DIR/main-alongside-stmts.rs - (line 18) ... ok
4+
test $DIR/main-alongside-stmts.rs - (line 27) ... ok
55

66
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
77

tests/rustdoc-ui/doctest/standalone-warning-2024.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#![deny(warnings)]
1010

1111
//! ```standalone
12+
//~^ ERROR unknown attribute `standalone`
13+
//~| ERROR unknown attribute `standalone-crate`
1214
//! bla
1315
//! ```
1416
//!

0 commit comments

Comments
 (0)