From 3ededc1053f752d993a0b25286faebfe3616819d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 25 Apr 2025 22:01:00 +0200 Subject: [PATCH] Improve code --- src/librustdoc/doctest/make.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/doctest/make.rs b/src/librustdoc/doctest/make.rs index 94e227b70e00..c46c6d71491a 100644 --- a/src/librustdoc/doctest/make.rs +++ b/src/librustdoc/doctest/make.rs @@ -407,7 +407,7 @@ fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option< push_to_s(&mut info.crate_attrs, source, attr.span, &mut prev_span_hi); } } - let mut has_non_module_items = false; + let mut has_non_items = false; for stmt in &body.stmts { let mut is_extern_crate = false; match stmt.kind { @@ -419,8 +419,11 @@ fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option< reset_error_count(&psess); return Err(()); } - has_non_module_items = true; + has_non_items = true; } + // We assume that the macro calls will expand to item(s) even though they could + // expand to statements and expressions. And the simple fact that we're trying + // to retrieve a `main` function inside it is a terrible idea. StmtKind::MacCall(ref mac_call) if !info.has_main_fn => { let mut iter = mac_call.mac.args.tokens.iter(); @@ -444,7 +447,7 @@ fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option< // We do nothing in this case. Not marking it as `non_module_items` either. StmtKind::Empty => {} _ => { - has_non_module_items = true; + has_non_items = true; } } @@ -470,7 +473,7 @@ fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option< push_to_s(&mut info.crates, source, span, &mut prev_span_hi); } } - if has_non_module_items { + if has_non_items { // FIXME: if `info.has_main_fn` is `true`, emit a warning here to mention that // this code will not be called. info.has_main_fn = false;