Skip to content

Commit ba663c6

Browse files
committed
Respect --error-format in rustdoc --test
1 parent 3d5f54a commit ba663c6

14 files changed

+57
-45
lines changed

src/librustdoc/doctest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
174174
crate_name: options.crate_name.clone(),
175175
remap_path_prefix: options.remap_path_prefix.clone(),
176176
unstable_opts: options.unstable_opts.clone(),
177+
error_format: options.error_format.clone(),
177178
..config::Options::default()
178179
};
179180

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,39 @@
33
#![deny(rustdoc::invalid_codeblock_attributes)]
44

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

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

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

2635
/// b
36+
//~^ ERROR unknown attribute `test-harness`
37+
//~^^ ERROR unknown attribute `testharness`
38+
//~^^^ ERROR unknown attribute `tesT_harness`
2739
///
2840
/// ```test-harness,testharness,tesT_harness
2941
/// boo

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

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ error: unknown attribute `compile-fail`
22
--> $DIR/check-attr-test.rs:5:1
33
|
44
LL | / /// foo
5-
LL | | ///
6-
LL | | /// ```compile-fail,compilefail,comPile_fail
5+
... |
76
LL | | /// boo
87
LL | | /// ```
98
| |_______^
@@ -20,8 +19,7 @@ error: unknown attribute `compilefail`
2019
--> $DIR/check-attr-test.rs:5:1
2120
|
2221
LL | / /// foo
23-
LL | | ///
24-
LL | | /// ```compile-fail,compilefail,comPile_fail
22+
... |
2523
LL | | /// boo
2624
LL | | /// ```
2725
| |_______^
@@ -33,8 +31,7 @@ error: unknown attribute `comPile_fail`
3331
--> $DIR/check-attr-test.rs:5:1
3432
|
3533
LL | / /// foo
36-
LL | | ///
37-
LL | | /// ```compile-fail,compilefail,comPile_fail
34+
... |
3835
LL | | /// boo
3936
LL | | /// ```
4037
| |_______^
@@ -43,11 +40,10 @@ LL | | /// ```
4340
= 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`
4441

4542
error: unknown attribute `should-panic`
46-
--> $DIR/check-attr-test.rs:12:1
43+
--> $DIR/check-attr-test.rs:15:1
4744
|
4845
LL | / /// bar
49-
LL | | ///
50-
LL | | /// ```should-panic,shouldpanic,shOuld_panic
46+
... |
5147
LL | | /// boo
5248
LL | | /// ```
5349
| |_______^
@@ -56,11 +52,10 @@ LL | | /// ```
5652
= 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`
5753

5854
error: unknown attribute `shouldpanic`
59-
--> $DIR/check-attr-test.rs:12:1
55+
--> $DIR/check-attr-test.rs:15:1
6056
|
6157
LL | / /// bar
62-
LL | | ///
63-
LL | | /// ```should-panic,shouldpanic,shOuld_panic
58+
... |
6459
LL | | /// boo
6560
LL | | /// ```
6661
| |_______^
@@ -69,11 +64,10 @@ LL | | /// ```
6964
= 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`
7065

7166
error: unknown attribute `shOuld_panic`
72-
--> $DIR/check-attr-test.rs:12:1
67+
--> $DIR/check-attr-test.rs:15:1
7368
|
7469
LL | / /// bar
75-
LL | | ///
76-
LL | | /// ```should-panic,shouldpanic,shOuld_panic
70+
... |
7771
LL | | /// boo
7872
LL | | /// ```
7973
| |_______^
@@ -82,11 +76,10 @@ LL | | /// ```
8276
= 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`
8377

8478
error: unknown attribute `no-run`
85-
--> $DIR/check-attr-test.rs:19:1
79+
--> $DIR/check-attr-test.rs:25:1
8680
|
8781
LL | / /// foobar
88-
LL | | ///
89-
LL | | /// ```no-run,norun,nO_run
82+
... |
9083
LL | | /// boo
9184
LL | | /// ```
9285
| |_______^
@@ -95,11 +88,10 @@ LL | | /// ```
9588
= 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`
9689

9790
error: unknown attribute `norun`
98-
--> $DIR/check-attr-test.rs:19:1
91+
--> $DIR/check-attr-test.rs:25:1
9992
|
10093
LL | / /// foobar
101-
LL | | ///
102-
LL | | /// ```no-run,norun,nO_run
94+
... |
10395
LL | | /// boo
10496
LL | | /// ```
10597
| |_______^
@@ -108,11 +100,10 @@ LL | | /// ```
108100
= 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`
109101

110102
error: unknown attribute `nO_run`
111-
--> $DIR/check-attr-test.rs:19:1
103+
--> $DIR/check-attr-test.rs:25:1
112104
|
113105
LL | / /// foobar
114-
LL | | ///
115-
LL | | /// ```no-run,norun,nO_run
106+
... |
116107
LL | | /// boo
117108
LL | | /// ```
118109
| |_______^
@@ -121,11 +112,10 @@ LL | | /// ```
121112
= 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`
122113

123114
error: unknown attribute `test-harness`
124-
--> $DIR/check-attr-test.rs:26:1
115+
--> $DIR/check-attr-test.rs:35:1
125116
|
126117
LL | / /// b
127-
LL | | ///
128-
LL | | /// ```test-harness,testharness,tesT_harness
118+
... |
129119
LL | | /// boo
130120
LL | | /// ```
131121
| |_______^
@@ -134,11 +124,10 @@ LL | | /// ```
134124
= 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`
135125

136126
error: unknown attribute `testharness`
137-
--> $DIR/check-attr-test.rs:26:1
127+
--> $DIR/check-attr-test.rs:35:1
138128
|
139129
LL | / /// b
140-
LL | | ///
141-
LL | | /// ```test-harness,testharness,tesT_harness
130+
... |
142131
LL | | /// boo
143132
LL | | /// ```
144133
| |_______^
@@ -147,11 +136,10 @@ LL | | /// ```
147136
= 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`
148137

149138
error: unknown attribute `tesT_harness`
150-
--> $DIR/check-attr-test.rs:26:1
139+
--> $DIR/check-attr-test.rs:35:1
151140
|
152141
LL | / /// b
153-
LL | | ///
154-
LL | | /// ```test-harness,testharness,tesT_harness
142+
... |
155143
LL | | /// boo
156144
LL | | /// ```
157145
| |_______^

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/main-alongside-stmts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//@ check-pass
1616

1717
//! ```
18+
//~^ WARN the `main` function of this doctest won't be run
1819
//! # if cfg!(miri) { return; }
1920
//! use std::ops::Deref;
2021
//!
@@ -24,6 +25,7 @@
2425
//! ```
2526
//!
2627
//! ```
28+
//~^^ WARN the `main` function of this doctest won't be run
2729
//! let x = 2;
2830
//! assert_eq!(x, 2);
2931
//!

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | //! ```
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
88
--> $DIR/main-alongside-stmts.rs:26:1
99
|
10-
LL | //! ```
11-
| ^^^^^^^
10+
LL | //!
11+
| ^^^
1212

1313
warning: 2 warnings emitted
1414

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
//!

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error: unknown attribute `standalone`
22
--> $DIR/standalone-warning-2024.rs:11:1
33
|
44
LL | / //! ```standalone
5+
LL | |
6+
LL | |
57
LL | | //! bla
6-
LL | | //! ```
7-
LL | | //!
8-
LL | | //! ```standalone-crate
8+
... |
99
LL | | //! bla
1010
LL | | //! ```
1111
| |_______^
@@ -23,10 +23,10 @@ error: unknown attribute `standalone-crate`
2323
--> $DIR/standalone-warning-2024.rs:11:1
2424
|
2525
LL | / //! ```standalone
26+
LL | |
27+
LL | |
2628
LL | | //! bla
27-
LL | | //! ```
28-
LL | | //!
29-
LL | | //! ```standalone-crate
29+
... |
3030
LL | | //! bla
3131
LL | | //! ```
3232
| |_______^

tests/rustdoc-ui/doctest/test-compile-fail1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
pub fn f() {}
77

88
pub fn f() {}
9+
//~^ ERROR the name `f` is defined multiple times
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//@ compile-flags:--test
22

33
fail
4+
//~^ ERROR

0 commit comments

Comments
 (0)