Skip to content

Commit aa69e3a

Browse files
Fix bad handling of macros if there is already a main function
1 parent 3ef98a5 commit aa69e3a

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/librustdoc/doctest/make.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
424424
// We assume that the macro calls will expand to item(s) even though they could
425425
// expand to statements and expressions. And the simple fact that we're trying
426426
// to retrieve a `main` function inside it is a terrible idea.
427-
StmtKind::MacCall(ref mac_call) if !info.has_main_fn => {
427+
StmtKind::MacCall(ref mac_call) => {
428+
if info.has_main_fn {
429+
continue;
430+
}
428431
let mut iter = mac_call.mac.args.tokens.iter();
429432

430433
while let Some(token) = iter.next() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use std::string::String;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This test checks a corner case where the macro calls used to be skipped,
2+
// making them considered as statement, and therefore some cases where
3+
// `include!` macro was then put into a function body, making the doctest
4+
// compilation fail.
5+
6+
//@ compile-flags:--test
7+
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
8+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
9+
//@ check-pass
10+
11+
//! ```
12+
//! include!("./auxiliary/macro-after-main.rs");
13+
//!
14+
//! fn main() {}
15+
//! eprintln!();
16+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
running 1 test
3+
test $DIR/macro-after-main.rs - (line 11) ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
6+

0 commit comments

Comments
 (0)