Skip to content

Commit

Permalink
return early if it not exists in doc_link_resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Feb 6, 2024
1 parent ff95e52 commit 89df989
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/librustdoc/passes/lint/redundant_explicit_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
return;
}

if item.link_names(&cx.cache).is_empty() {
// If there's no link names in this item,
// then we skip resolution querying to
// avoid from panicking.
return;
}

let Some(item_id) = item.def_id() else {
return;
};
Expand All @@ -58,14 +51,29 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
return;
}

check_redundant_explicit_link(cx, item, hir_id, &doc);
let module_id = match cx.tcx.def_kind(item_id) {
DefKind::Mod if item.inner_docs(cx.tcx) => item_id,
_ => find_nearest_parent_module(cx.tcx, item_id).unwrap(),
};

let Some(resolutions) =
cx.tcx.resolutions(()).doc_link_resolutions.get(&module_id.expect_local())
else {
// If there's no resolutions in this module,
// then we skip resolution querying to
// avoid from panicking.
return;
};

check_redundant_explicit_link(cx, item, hir_id, &doc, &resolutions);
}

fn check_redundant_explicit_link<'md>(
cx: &DocContext<'_>,
item: &Item,
hir_id: HirId,
doc: &'md str,
resolutions: &DocLinkResMap,
) -> Option<()> {
let mut broken_line_callback = |link: BrokenLink<'md>| Some((link.reference, "".into()));
let mut offset_iter = Parser::new_with_broken_link_callback(
Expand All @@ -74,12 +82,6 @@ fn check_redundant_explicit_link<'md>(
Some(&mut broken_line_callback),
)
.into_offset_iter();
let item_id = item.def_id()?;
let module_id = match cx.tcx.def_kind(item_id) {
DefKind::Mod if item.inner_docs(cx.tcx) => item_id,
_ => find_nearest_parent_module(cx.tcx, item_id).unwrap(),
};
let resolutions = cx.tcx.doc_link_resolutions(module_id);

while let Some((event, link_range)) = offset_iter.next() {
match event {
Expand Down
11 changes: 11 additions & 0 deletions tests/rustdoc-ui/issues/issue-120444.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// compile-flags: --document-private-items

mod webdavfs {
pub struct A;
}

/// [`Vfs`]
pub use webdavfs::A;

pub struct Vfs;

0 comments on commit 89df989

Please sign in to comment.