Skip to content

Commit c64f4c4

Browse files
authored
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 #107350. We'll also need to backport this fix to beta. r? `@notriddle`
2 parents 85dc93b + 1b64e16 commit c64f4c4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/librustdoc/clean/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2112,10 +2112,12 @@ fn get_all_import_attributes<'hir>(
21122112
) {
21132113
let hir_map = tcx.hir();
21142114
let mut visitor = OneLevelVisitor::new(hir_map, target_def_id);
2115+
let mut visited = FxHashSet::default();
21152116
// If the item is an import and has at least a path with two parts, we go into it.
21162117
while let hir::ItemKind::Use(path, _) = item.kind &&
21172118
path.segments.len() > 1 &&
2118-
let hir::def::Res::Def(_, def_id) = path.segments[path.segments.len() - 2].res
2119+
let hir::def::Res::Def(_, def_id) = path.segments[path.segments.len() - 2].res &&
2120+
visited.insert(def_id)
21192121
{
21202122
if let Some(hir::Node::Item(parent_item)) = hir_map.get_if_local(def_id) {
21212123
// We add the attributes from this import into the list.

tests/rustdoc/issue-107350.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/107350>.
2+
// It shouldn't loop indefinitely.
3+
4+
#![crate_name = "foo"]
5+
6+
// @has 'foo/oops/enum.OhNo.html'
7+
8+
pub mod oops {
9+
pub use crate::oops::OhNo;
10+
11+
mod inner {
12+
pub enum OhNo {
13+
Item = 1,
14+
}
15+
}
16+
17+
pub use self::inner::*;
18+
}

0 commit comments

Comments
 (0)