Skip to content

Commit

Permalink
Unrolled build for rust-lang#131096
Browse files Browse the repository at this point in the history
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``
  • Loading branch information
rust-timer authored Oct 30, 2024
2 parents 298c746 + b073ddc commit 6c9ca83
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ fn generate_mergeable_doctest(
} else {
writeln!(output, "mod {test_id} {{\n{}{}", doctest.crates, doctest.maybe_crate_attrs)
.unwrap();
if scraped_test.langstr.no_run {
// To prevent having warnings about unused items since they're not called.
writeln!(output, "#![allow(unused)]").unwrap();
}
if doctest.has_main_fn {
output.push_str(&doctest.everything_else);
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/rustdoc-ui/doctest/dead-code-2024.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This test ensures that the 2024 edition merged doctest will not use `#[allow(unused)]`.

//@ compile-flags:--test -Zunstable-options --edition 2024
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ failure-status: 101

#![doc(test(attr(allow(unused_variables), deny(warnings))))]

/// Example
///
/// ```rust,no_run
/// trait T { fn f(); }
/// ```
pub fn f() {}
29 changes: 29 additions & 0 deletions tests/rustdoc-ui/doctest/dead-code-2024.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

running 1 test
test $DIR/dead-code-2024.rs - f (line 12) - compile ... FAILED

failures:

---- $DIR/dead-code-2024.rs - f (line 12) stdout ----
error: trait `T` is never used
--> $DIR/dead-code-2024.rs:13:7
|
LL | trait T { fn f(); }
| ^
|
note: the lint level is defined here
--> $DIR/dead-code-2024.rs:11:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/dead-code-2024.rs - f (line 12)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

15 changes: 15 additions & 0 deletions tests/rustdoc-ui/doctest/dead-code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This test ensures that the doctest will not use `#[allow(unused)]`.

//@ compile-flags:--test
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout-test: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ failure-status: 101

#![doc(test(attr(allow(unused_variables), deny(warnings))))]

/// Example
///
/// ```rust,no_run
/// trait T { fn f(); }
/// ```
pub fn f() {}
29 changes: 29 additions & 0 deletions tests/rustdoc-ui/doctest/dead-code.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

running 1 test
test $DIR/dead-code.rs - f (line 12) - compile ... FAILED

failures:

---- $DIR/dead-code.rs - f (line 12) stdout ----
error: trait `T` is never used
--> $DIR/dead-code.rs:13:7
|
LL | trait T { fn f(); }
| ^
|
note: the lint level is defined here
--> $DIR/dead-code.rs:11:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/dead-code.rs - f (line 12)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

0 comments on commit 6c9ca83

Please sign in to comment.