Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
target_triple: options.target.clone(),
crate_name: options.crate_name.clone(),
remap_path_prefix: options.remap_path_prefix.clone(),
unstable_opts: options.unstable_opts.clone(),
error_format: options.error_format.clone(),
..config::Options::default()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ideally we would either exhaustively destructure RustdocOptions at the start of the function or exhaustively construct config::Options to prevent such mistakes in the futures (hell, I don't even know if there are still any options we want to copy over); but yeah, it's probably not feasible due to the sheer amount of options...

};

Expand Down
12 changes: 12 additions & 0 deletions tests/rustdoc-ui/doctest/check-attr-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@

#![deny(rustdoc::invalid_codeblock_attributes)]

//~vvv ERROR unknown attribute `compile-fail`
//~| ERROR unknown attribute `compilefail`
//~| ERROR unknown attribute `comPile_fail`
/// foo
///
/// ```compile-fail,compilefail,comPile_fail
/// boo
/// ```
pub fn foo() {}

//~vvv ERROR unknown attribute `should-panic`
//~| ERROR unknown attribute `shouldpanic`
//~| ERROR unknown attribute `shOuld_panic`
/// bar
///
/// ```should-panic,shouldpanic,shOuld_panic
/// boo
/// ```
pub fn bar() {}

//~vvv ERROR unknown attribute `no-run`
//~| ERROR unknown attribute `norun`
//~| ERROR unknown attribute `nO_run`
/// foobar
///
/// ```no-run,norun,nO_run
/// boo
/// ```
pub fn foobar() {}

//~vvv ERROR unknown attribute `test-harness`
//~| ERROR unknown attribute `testharness`
//~| ERROR unknown attribute `tesT_harness`
/// b
///
/// ```test-harness,testharness,tesT_harness
Expand Down
182 changes: 91 additions & 91 deletions tests/rustdoc-ui/doctest/check-attr-test.stderr
Original file line number Diff line number Diff line change
@@ -1,159 +1,159 @@
error: unknown attribute `compile-fail`
--> $DIR/check-attr-test.rs:5:1
|
5 | / /// foo
6 | | ///
7 | | /// ```compile-fail,compilefail,comPile_fail
8 | | /// boo
9 | | /// ```
| |_______^
|
= 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
= 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`
--> $DIR/check-attr-test.rs:8:1
|
LL | / /// foo
LL | | ///
LL | | /// ```compile-fail,compilefail,comPile_fail
LL | | /// boo
LL | | /// ```
| |_______^
|
= 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
= 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`
note: the lint level is defined here
--> $DIR/check-attr-test.rs:3:9
|
3 | #![deny(rustdoc::invalid_codeblock_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--> $DIR/check-attr-test.rs:3:9
|
LL | #![deny(rustdoc::invalid_codeblock_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unknown attribute `compilefail`
--> $DIR/check-attr-test.rs:5:1
|
5 | / /// foo
6 | | ///
7 | | /// ```compile-fail,compilefail,comPile_fail
8 | | /// boo
9 | | /// ```
| |_______^
|
= 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
= 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`
--> $DIR/check-attr-test.rs:8:1
|
LL | / /// foo
LL | | ///
LL | | /// ```compile-fail,compilefail,comPile_fail
LL | | /// boo
LL | | /// ```
| |_______^
|
= 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
= 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`

error: unknown attribute `comPile_fail`
--> $DIR/check-attr-test.rs:5:1
|
5 | / /// foo
6 | | ///
7 | | /// ```compile-fail,compilefail,comPile_fail
8 | | /// boo
9 | | /// ```
| |_______^
|
= 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
= 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`
--> $DIR/check-attr-test.rs:8:1
|
LL | / /// foo
LL | | ///
LL | | /// ```compile-fail,compilefail,comPile_fail
LL | | /// boo
LL | | /// ```
| |_______^
|
= 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
= 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`

error: unknown attribute `should-panic`
--> $DIR/check-attr-test.rs:12:1
--> $DIR/check-attr-test.rs:18:1
|
12 | / /// bar
13 | | ///
14 | | /// ```should-panic,shouldpanic,shOuld_panic
15 | | /// boo
16 | | /// ```
LL | / /// bar
LL | | ///
LL | | /// ```should-panic,shouldpanic,shOuld_panic
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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`

error: unknown attribute `shouldpanic`
--> $DIR/check-attr-test.rs:12:1
--> $DIR/check-attr-test.rs:18:1
|
12 | / /// bar
13 | | ///
14 | | /// ```should-panic,shouldpanic,shOuld_panic
15 | | /// boo
16 | | /// ```
LL | / /// bar
LL | | ///
LL | | /// ```should-panic,shouldpanic,shOuld_panic
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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`

error: unknown attribute `shOuld_panic`
--> $DIR/check-attr-test.rs:12:1
--> $DIR/check-attr-test.rs:18:1
|
12 | / /// bar
13 | | ///
14 | | /// ```should-panic,shouldpanic,shOuld_panic
15 | | /// boo
16 | | /// ```
LL | / /// bar
LL | | ///
LL | | /// ```should-panic,shouldpanic,shOuld_panic
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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`

error: unknown attribute `no-run`
--> $DIR/check-attr-test.rs:19:1
--> $DIR/check-attr-test.rs:28:1
|
19 | / /// foobar
20 | | ///
21 | | /// ```no-run,norun,nO_run
22 | | /// boo
23 | | /// ```
LL | / /// foobar
LL | | ///
LL | | /// ```no-run,norun,nO_run
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `no_run` to compile, but not run, the code sample during testing
= 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`

error: unknown attribute `norun`
--> $DIR/check-attr-test.rs:19:1
--> $DIR/check-attr-test.rs:28:1
|
19 | / /// foobar
20 | | ///
21 | | /// ```no-run,norun,nO_run
22 | | /// boo
23 | | /// ```
LL | / /// foobar
LL | | ///
LL | | /// ```no-run,norun,nO_run
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `no_run` to compile, but not run, the code sample during testing
= 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`

error: unknown attribute `nO_run`
--> $DIR/check-attr-test.rs:19:1
--> $DIR/check-attr-test.rs:28:1
|
19 | / /// foobar
20 | | ///
21 | | /// ```no-run,norun,nO_run
22 | | /// boo
23 | | /// ```
LL | / /// foobar
LL | | ///
LL | | /// ```no-run,norun,nO_run
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `no_run` to compile, but not run, the code sample during testing
= 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`

error: unknown attribute `test-harness`
--> $DIR/check-attr-test.rs:26:1
--> $DIR/check-attr-test.rs:38:1
|
26 | / /// b
27 | | ///
28 | | /// ```test-harness,testharness,tesT_harness
29 | | /// boo
30 | | /// ```
LL | / /// b
LL | | ///
LL | | /// ```test-harness,testharness,tesT_harness
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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`

error: unknown attribute `testharness`
--> $DIR/check-attr-test.rs:26:1
--> $DIR/check-attr-test.rs:38:1
|
26 | / /// b
27 | | ///
28 | | /// ```test-harness,testharness,tesT_harness
29 | | /// boo
30 | | /// ```
LL | / /// b
LL | | ///
LL | | /// ```test-harness,testharness,tesT_harness
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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`

error: unknown attribute `tesT_harness`
--> $DIR/check-attr-test.rs:26:1
--> $DIR/check-attr-test.rs:38:1
|
26 | / /// b
27 | | ///
28 | | /// ```test-harness,testharness,tesT_harness
29 | | /// boo
30 | | /// ```
LL | / /// b
LL | | ///
LL | | /// ```test-harness,testharness,tesT_harness
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/// <https://github.com/rust-lang/rust/issues/91014>
///
/// ```rust
//~^ WARN the `main` function of this doctest won't be run
/// struct S {};
///
/// fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
--> $DIR/failed-doctest-extra-semicolon-on-item.rs:11:1
|
11 | /// ```rust
LL | /// ```rust
| ^^^^^^^^^^^

warning: 1 warning emitted
Expand Down
2 changes: 2 additions & 0 deletions tests/rustdoc-ui/doctest/main-alongside-stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ check-pass

//~v WARN the `main` function of this doctest won't be run
//! ```
//! # if cfg!(miri) { return; }
//! use std::ops::Deref;
Expand All @@ -22,6 +23,7 @@
//! assert!(false);
//! }
//! ```
//~v WARN the `main` function of this doctest won't be run
//!
//! ```
//! let x = 2;
Expand Down
10 changes: 5 additions & 5 deletions tests/rustdoc-ui/doctest/main-alongside-stmts.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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
--> $DIR/main-alongside-stmts.rs:17:1
--> $DIR/main-alongside-stmts.rs:18:1
|
17 | //! ```
LL | //! ```
| ^^^^^^^

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
--> $DIR/main-alongside-stmts.rs:26:1
--> $DIR/main-alongside-stmts.rs:27:1
|
26 | //! ```
| ^^^^^^^
LL | //!
| ^^^
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unrelated, preexisting) Lol, we really gotta improve the span finding heuristic for all of these cases...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the spans are really rough. I think no one realized how bad they were until now.


warning: 2 warnings emitted

4 changes: 2 additions & 2 deletions tests/rustdoc-ui/doctest/main-alongside-stmts.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

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

2 changes: 2 additions & 0 deletions tests/rustdoc-ui/doctest/standalone-warning-2024.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#![deny(warnings)]

//! ```standalone
//~^ ERROR unknown attribute `standalone`
//~| ERROR unknown attribute `standalone-crate`
//! bla
//! ```
//!
Expand Down
Loading
Loading