Skip to content

Commit 6924908

Browse files
GuillaumeGomezcuviper
authored andcommitted
Improve code
(cherry picked from commit 3ededc1)
1 parent 745d54e commit 6924908

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/librustdoc/doctest/make.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
411411
push_to_s(&mut info.crate_attrs, source, attr.span, &mut prev_span_hi);
412412
}
413413
}
414-
let mut has_non_module_items = false;
414+
let mut has_non_items = false;
415415
for stmt in &body.stmts {
416416
let mut is_extern_crate = false;
417417
match stmt.kind {
@@ -423,8 +423,11 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
423423
reset_error_count(&psess);
424424
return Err(());
425425
}
426-
has_non_module_items = true;
426+
has_non_items = true;
427427
}
428+
// We assume that the macro calls will expand to item(s) even though they could
429+
// expand to statements and expressions. And the simple fact that we're trying
430+
// to retrieve a `main` function inside it is a terrible idea.
428431
StmtKind::MacCall(ref mac_call) if !info.has_main_fn => {
429432
let mut iter = mac_call.mac.args.tokens.iter();
430433

@@ -448,7 +451,7 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
448451
// We do nothing in this case. Not marking it as `non_module_items` either.
449452
StmtKind::Empty => {}
450453
_ => {
451-
has_non_module_items = true;
454+
has_non_items = true;
452455
}
453456
}
454457

@@ -474,7 +477,7 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
474477
push_to_s(&mut info.crates, source, span, &mut prev_span_hi);
475478
}
476479
}
477-
if has_non_module_items {
480+
if has_non_items {
478481
// FIXME: if `info.has_main_fn` is `true`, emit a warning here to mention that
479482
// this code will not be called.
480483
info.has_main_fn = false;

0 commit comments

Comments
 (0)