Skip to content

Commit cd960d9

Browse files
Add regression test for #140310
1 parent 5cf4129 commit cd960d9

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ check-pass
2+
//@ compile-flags:--test --test-args --test-threads=1
3+
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
4+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
5+
6+
// In case there is a `main` function in the doctest alongside expressions,
7+
// the whole doctest will be wrapped into a function and the `main` function
8+
// won't be called.
9+
10+
//! ```
11+
//! macro_rules! bla {
12+
//! ($($x:tt)*) => {}
13+
//! }
14+
//!
15+
//! let x = 12;
16+
//! bla!(fn main ());
17+
//! ```
18+
//!
19+
//! ```
20+
//! let x = 12;
21+
//! fn main() {}
22+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
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/warn-main-not-called.rs:10:1
3+
|
4+
10 | //! ```
5+
| ^^^^^^^
6+
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
8+
--> $DIR/warn-main-not-called.rs:19:1
9+
|
10+
19 | //! ```
11+
| ^^^^^^^
12+
13+
warning: 2 warnings emitted
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
running 2 tests
3+
test $DIR/warn-main-not-called.rs - (line 10) ... ok
4+
test $DIR/warn-main-not-called.rs - (line 19) ... ok
5+
6+
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
7+

0 commit comments

Comments
 (0)