@@ -7,6 +7,7 @@ use rustc_hir::def::{DefKind, DocLinkResMap, Namespace, Res};
7
7
use rustc_hir:: HirId ;
8
8
use rustc_lint_defs:: Applicability ;
9
9
use rustc_resolve:: rustdoc:: source_span_for_markdown_range;
10
+ use rustc_span:: def_id:: DefId ;
10
11
use rustc_span:: Symbol ;
11
12
12
13
use crate :: clean:: utils:: find_nearest_parent_module;
@@ -33,17 +34,22 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
33
34
return ;
34
35
}
35
36
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) ;
41
39
}
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
+ }
42
44
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 {
47
53
return ;
48
54
} ;
49
55
@@ -53,19 +59,34 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item) {
53
59
return ;
54
60
}
55
61
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 ) ;
57
63
if is_private {
58
64
return ;
59
65
}
60
66
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) ;
62
82
}
63
83
64
84
fn check_redundant_explicit_link < ' md > (
65
85
cx : & DocContext < ' _ > ,
66
86
item : & Item ,
67
87
hir_id : HirId ,
68
88
doc : & ' md str ,
89
+ resolutions : & DocLinkResMap ,
69
90
) -> Option < ( ) > {
70
91
let mut broken_line_callback = |link : BrokenLink < ' md > | Some ( ( link. reference , "" . into ( ) ) ) ;
71
92
let mut offset_iter = Parser :: new_with_broken_link_callback (
@@ -74,12 +95,6 @@ fn check_redundant_explicit_link<'md>(
74
95
Some ( & mut broken_line_callback) ,
75
96
)
76
97
. 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) ;
83
98
84
99
while let Some ( ( event, link_range) ) = offset_iter. next ( ) {
85
100
match event {
0 commit comments