Skip to content

Commit 89df989

Browse files
committed
return early if it not exists in doc_link_resolutions
1 parent ff95e52 commit 89df989

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/librustdoc/passes/lint/redundant_explicit_links.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
3333
return;
3434
}
3535

36-
if item.link_names(&cx.cache).is_empty() {
37-
// If there's no link names in this item,
38-
// then we skip resolution querying to
39-
// avoid from panicking.
40-
return;
41-
}
42-
4336
let Some(item_id) = item.def_id() else {
4437
return;
4538
};
@@ -58,14 +51,29 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
5851
return;
5952
}
6053

61-
check_redundant_explicit_link(cx, item, hir_id, &doc);
54+
let module_id = match cx.tcx.def_kind(item_id) {
55+
DefKind::Mod if item.inner_docs(cx.tcx) => item_id,
56+
_ => find_nearest_parent_module(cx.tcx, item_id).unwrap(),
57+
};
58+
59+
let Some(resolutions) =
60+
cx.tcx.resolutions(()).doc_link_resolutions.get(&module_id.expect_local())
61+
else {
62+
// If there's no resolutions in this module,
63+
// then we skip resolution querying to
64+
// avoid from panicking.
65+
return;
66+
};
67+
68+
check_redundant_explicit_link(cx, item, hir_id, &doc, &resolutions);
6269
}
6370

6471
fn check_redundant_explicit_link<'md>(
6572
cx: &DocContext<'_>,
6673
item: &Item,
6774
hir_id: HirId,
6875
doc: &'md str,
76+
resolutions: &DocLinkResMap,
6977
) -> Option<()> {
7078
let mut broken_line_callback = |link: BrokenLink<'md>| Some((link.reference, "".into()));
7179
let mut offset_iter = Parser::new_with_broken_link_callback(
@@ -74,12 +82,6 @@ fn check_redundant_explicit_link<'md>(
7482
Some(&mut broken_line_callback),
7583
)
7684
.into_offset_iter();
77-
let item_id = item.def_id()?;
78-
let module_id = match cx.tcx.def_kind(item_id) {
79-
DefKind::Mod if item.inner_docs(cx.tcx) => item_id,
80-
_ => find_nearest_parent_module(cx.tcx, item_id).unwrap(),
81-
};
82-
let resolutions = cx.tcx.doc_link_resolutions(module_id);
8385

8486
while let Some((event, link_range)) = offset_iter.next() {
8587
match event {
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// compile-flags: --document-private-items
3+
4+
mod webdavfs {
5+
pub struct A;
6+
}
7+
8+
/// [`Vfs`]
9+
pub use webdavfs::A;
10+
11+
pub struct Vfs;

0 commit comments

Comments
 (0)