@@ -7,6 +7,7 @@ use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res};
77use rustc_hir:: HirId ;
88use rustc_lint_defs:: Applicability ;
99use rustc_resolve:: rustdoc:: source_span_for_markdown_range;
10+ use rustc_span:: def_id:: DefId ;
1011use rustc_span:: Symbol ;
1112
1213use crate :: clean:: utils:: find_nearest_parent_module;
@@ -33,17 +34,22 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
3334 return ;
3435 }
3536
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 ;
37+ if let Some ( item_id) = item. def_id ( ) {
38+ check_redundant_explicit_link_for_did ( cx, item, item_id, hir_id, & doc) ;
4139 }
40+ if let Some ( item_id) = item. inline_stmt_id {
41+ check_redundant_explicit_link_for_did ( cx, item, item_id, hir_id, & doc) ;
42+ }
43+ }
4244
43- let Some ( item_id) = item. def_id ( ) else {
44- return ;
45- } ;
46- let Some ( local_item_id) = item_id. as_local ( ) else {
45+ fn check_redundant_explicit_link_for_did < ' md > (
46+ cx : & DocContext < ' _ > ,
47+ item : & Item ,
48+ did : DefId ,
49+ hir_id : HirId ,
50+ doc : & ' md str ,
51+ ) {
52+ let Some ( local_item_id) = did. as_local ( ) else {
4753 return ;
4854 } ;
4955
@@ -53,19 +59,34 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
5359 return ;
5460 }
5561 let is_private = !cx. render_options . document_private
56- && !cx. cache . effective_visibilities . is_directly_public ( cx. tcx , item_id ) ;
62+ && !cx. cache . effective_visibilities . is_directly_public ( cx. tcx , did ) ;
5763 if is_private {
5864 return ;
5965 }
6066
61- check_redundant_explicit_link ( cx, item, hir_id, & doc) ;
67+ let module_id = match cx. tcx . def_kind ( did) {
68+ DefKind :: Mod if item. inner_docs ( cx. tcx ) => did,
69+ _ => find_nearest_parent_module ( cx. tcx , did) . unwrap ( ) ,
70+ } ;
71+
72+ let Some ( resolutions) =
73+ cx. tcx . resolutions ( ( ) ) . doc_link_resolutions . get ( & module_id. expect_local ( ) )
74+ else {
75+ // If there's no resolutions in this module,
76+ // then we skip resolution querying to
77+ // avoid from panicking.
78+ return ;
79+ } ;
80+
81+ check_redundant_explicit_link ( cx, item, hir_id, & doc, & resolutions) ;
6282}
6383
6484fn check_redundant_explicit_link < ' md > (
6585 cx : & DocContext < ' _ > ,
6686 item : & Item ,
6787 hir_id : HirId ,
6888 doc : & ' md str ,
89+ resolutions : & DocLinkResMap ,
6990) -> Option < ( ) > {
7091 let mut broken_line_callback = |link : BrokenLink < ' md > | Some ( ( link. reference , "" . into ( ) ) ) ;
7192 let mut offset_iter = Parser :: new_with_broken_link_callback (
@@ -74,12 +95,6 @@ fn check_redundant_explicit_link<'md>(
7495 Some ( & mut broken_line_callback) ,
7596 )
7697 . 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) ;
8398
8499 while let Some ( ( event, link_range) ) = offset_iter. next ( ) {
85100 match event {
0 commit comments