about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-03-27 14:43:11 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-03-27 16:44:21 +0100
commit49f1e9cd8d31b65416408f4975feb5eded4d6158 (patch)
tree21ac629049f5a5f6c0f6270d85c5036f713ab669
parent1494da4ffbfab8d0b7a62dd37d9f4a77f1038840 (diff)
downloadrust-49f1e9cd8d31b65416408f4975feb5eded4d6158.tar.gz
rust-49f1e9cd8d31b65416408f4975feb5eded4d6158.zip
Remove recursion in `check_item`
-rw-r--r--src/librustdoc/doctest/make.rs20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/librustdoc/doctest/make.rs b/src/librustdoc/doctest/make.rs
index 93be3520006..55b57292b33 100644
--- a/src/librustdoc/doctest/make.rs
+++ b/src/librustdoc/doctest/make.rs
@@ -342,12 +342,7 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
     // Recurse through functions body. It is necessary because the doctest source code is
     // wrapped in a function to limit the number of AST errors. If we don't recurse into
     // functions, we would thing all top-level items (so basically nothing).
-    fn check_item(
-        item: &ast::Item,
-        info: &mut ParseSourceInfo,
-        crate_name: &Option<&str>,
-        is_top_level: bool,
-    ) -> bool {
+    fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option<&str>) -> bool {
         let mut is_extern_crate = false;
         if !info.has_global_allocator
             && item.attrs.iter().any(|attr| attr.name_or_empty() == sym::global_allocator)
@@ -355,19 +350,12 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
             info.has_global_allocator = true;
         }
         match item.kind {
-            ast::ItemKind::Fn(ref fn_item) if !info.has_main_fn => {
+            ast::ItemKind::Fn(_) if !info.has_main_fn => {
                 // We only push if it's the top item because otherwise, we would duplicate
                 // its content since the top-level item was already added.
-                if item.ident.name == sym::main && is_top_level {
+                if item.ident.name == sym::main {
                     info.has_main_fn = true;
                 }
-                if let Some(ref body) = fn_item.body {
-                    for stmt in &body.stmts {
-                        if let StmtKind::Item(ref item) = stmt.kind {
-                            is_extern_crate |= check_item(item, info, crate_name, false);
-                        }
-                    }
-                }
             }
             ast::ItemKind::ExternCrate(original) => {
                 is_extern_crate = true;
@@ -427,7 +415,7 @@ fn parse_source(source: &str, crate_name: &Option<&str>) -> Result<ParseSourceIn
                 let mut is_extern_crate = false;
                 match stmt.kind {
                     StmtKind::Item(ref item) => {
-                        is_extern_crate = check_item(&item, &mut info, crate_name, true);
+                        is_extern_crate = check_item(&item, &mut info, crate_name);
                     }
                     StmtKind::Expr(ref expr) if matches!(expr.kind, ast::ExprKind::Err(_)) => {
                         reset_error_count(&psess);