about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2023-01-28 00:23:16 +0900
committerGitHub <noreply@github.com>2023-01-28 00:23:16 +0900
commitc64f4c41f76581807bf7e063ded17f7da51b4478 (patch)
treef43de35b2376ccebaa6bcfa5863a555104b9d360
parent85dc93b4d346a8138f343c6d9b0b803b4b55a8a6 (diff)
parent1b64e16643eb3322b61f916c8cfec436e30e7bf3 (diff)
downloadrust-c64f4c41f76581807bf7e063ded17f7da51b4478.tar.gz
rust-c64f4c41f76581807bf7e063ded17f7da51b4478.zip
Rollup merge of #107357 - GuillaumeGomez:fix-infinite-loop-in-rustdoc-get_all_import_attributes, r=notriddle
Fix infinite loop in rustdoc get_all_import_attributes function

Fixes https://github.com/rust-lang/rust/issues/107350.

We'll also need to backport this fix to beta.

r? `@notriddle`
-rw-r--r--src/librustdoc/clean/mod.rs4
-rw-r--r--tests/rustdoc/issue-107350.rs18
2 files changed, 21 insertions, 1 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 3cb6ad10e72..4b1cd78c4ad 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2112,10 +2112,12 @@ fn get_all_import_attributes<'hir>(
 ) {
     let hir_map = tcx.hir();
     let mut visitor = OneLevelVisitor::new(hir_map, target_def_id);
+    let mut visited = FxHashSet::default();
     // If the item is an import and has at least a path with two parts, we go into it.
     while let hir::ItemKind::Use(path, _) = item.kind &&
         path.segments.len() > 1 &&
-        let hir::def::Res::Def(_, def_id) = path.segments[path.segments.len() - 2].res
+        let hir::def::Res::Def(_, def_id) = path.segments[path.segments.len() - 2].res &&
+        visited.insert(def_id)
     {
         if let Some(hir::Node::Item(parent_item)) = hir_map.get_if_local(def_id) {
             // We add the attributes from this import into the list.
diff --git a/tests/rustdoc/issue-107350.rs b/tests/rustdoc/issue-107350.rs
new file mode 100644
index 00000000000..75f378ed249
--- /dev/null
+++ b/tests/rustdoc/issue-107350.rs
@@ -0,0 +1,18 @@
+// This is a regression test for <https://github.com/rust-lang/rust/issues/107350>.
+// It shouldn't loop indefinitely.
+
+#![crate_name = "foo"]
+
+// @has 'foo/oops/enum.OhNo.html'
+
+pub mod oops {
+    pub use crate::oops::OhNo;
+
+    mod inner {
+        pub enum OhNo {
+            Item = 1,
+        }
+    }
+
+    pub use self::inner::*;
+}