Skip to content

Commit a864e30

Browse files
authored
Rollup merge of rust-lang#131096 - GuillaumeGomez:rm-no_unused, r=notriddle
rustdoc: Remove usage of `allow(unused)` attribute on `no_run` merged doctests Fixes [rust-lang#130681](rust-lang#130681). It fixes the behaviour difference with the current doctests. r? ``@notriddle``
2 parents 8d9686e + b073ddc commit a864e30

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

src/librustdoc/doctest/runner.rs

-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ fn generate_mergeable_doctest(
198198
} else {
199199
writeln!(output, "mod {test_id} {{\n{}{}", doctest.crates, doctest.maybe_crate_attrs)
200200
.unwrap();
201-
if scraped_test.langstr.no_run {
202-
// To prevent having warnings about unused items since they're not called.
203-
writeln!(output, "#![allow(unused)]").unwrap();
204-
}
205201
if doctest.has_main_fn {
206202
output.push_str(&doctest.everything_else);
207203
} else {
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test ensures that the 2024 edition merged doctest will not use `#[allow(unused)]`.
2+
3+
//@ compile-flags:--test -Zunstable-options --edition 2024
4+
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
5+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
6+
//@ failure-status: 101
7+
8+
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
9+
10+
/// Example
11+
///
12+
/// ```rust,no_run
13+
/// trait T { fn f(); }
14+
/// ```
15+
pub fn f() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
running 1 test
3+
test $DIR/dead-code-2024.rs - f (line 12) - compile ... FAILED
4+
5+
failures:
6+
7+
---- $DIR/dead-code-2024.rs - f (line 12) stdout ----
8+
error: trait `T` is never used
9+
--> $DIR/dead-code-2024.rs:13:7
10+
|
11+
LL | trait T { fn f(); }
12+
| ^
13+
|
14+
note: the lint level is defined here
15+
--> $DIR/dead-code-2024.rs:11:9
16+
|
17+
LL | #![deny(warnings)]
18+
| ^^^^^^^^
19+
= note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
20+
21+
error: aborting due to 1 previous error
22+
23+
Couldn't compile the test.
24+
25+
failures:
26+
$DIR/dead-code-2024.rs - f (line 12)
27+
28+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
29+

tests/rustdoc-ui/doctest/dead-code.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test ensures that the doctest will not use `#[allow(unused)]`.
2+
3+
//@ compile-flags:--test
4+
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
5+
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
6+
//@ failure-status: 101
7+
8+
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
9+
10+
/// Example
11+
///
12+
/// ```rust,no_run
13+
/// trait T { fn f(); }
14+
/// ```
15+
pub fn f() {}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
running 1 test
3+
test $DIR/dead-code.rs - f (line 12) - compile ... FAILED
4+
5+
failures:
6+
7+
---- $DIR/dead-code.rs - f (line 12) stdout ----
8+
error: trait `T` is never used
9+
--> $DIR/dead-code.rs:13:7
10+
|
11+
LL | trait T { fn f(); }
12+
| ^
13+
|
14+
note: the lint level is defined here
15+
--> $DIR/dead-code.rs:11:9
16+
|
17+
LL | #![deny(warnings)]
18+
| ^^^^^^^^
19+
= note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
20+
21+
error: aborting due to 1 previous error
22+
23+
Couldn't compile the test.
24+
25+
failures:
26+
$DIR/dead-code.rs - f (line 12)
27+
28+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
29+

0 commit comments

Comments
 (0)