Skip to content

Commit 1f6a6b1

Browse files
GuillaumeGomezcuviper
authored andcommitted
Fix bad handling of macros if there is already a main function
(cherry picked from commit aa69e3a)
1 parent c44a1d7 commit 1f6a6b1

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
@@ -428,7 +428,10 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
428428
// We assume that the macro calls will expand to item(s) even though they could
429429
// expand to statements and expressions. And the simple fact that we're trying
430430
// to retrieve a `main` function inside it is a terrible idea.
431-
StmtKind::MacCall(ref mac_call) if !info.has_main_fn => {
431+
StmtKind::MacCall(ref mac_call) => {
432+
if info.has_main_fn {
433+
continue;
434+
}
432435
let mut iter = mac_call.mac.args.tokens.iter();
433436

434437
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)