about summary refs log tree commit diff
path: root/src/librustdoc/doctest/make.rs
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-04-25 22:01:00 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-04-25 22:01:00 +0200
commit3ededc1053f752d993a0b25286faebfe3616819d (patch)
treed6b2dc9474fd4114251aece221b3fd5e9f4ffb60 /src/librustdoc/doctest/make.rs
parent81438c0b05f177ae7bc0d6511d1cc507652eb241 (diff)
downloadrust-3ededc1053f752d993a0b25286faebfe3616819d.tar.gz
rust-3ededc1053f752d993a0b25286faebfe3616819d.zip
Improve code
Diffstat (limited to 'src/librustdoc/doctest/make.rs')
-rw-r--r--src/librustdoc/doctest/make.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/librustdoc/doctest/make.rs b/src/librustdoc/doctest/make.rs
index 94e227b70e0..c46c6d71491 100644
--- a/src/librustdoc/doctest/make.rs
+++ b/src/librustdoc/doctest/make.rs
@@ -407,7 +407,7 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
                     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 parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
                             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 parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
                     // 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 parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
                     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;