@@ -14,19 +14,22 @@ use rustc_hir::TraitCandidate;
14
14
use rustc_middle:: ty:: { DefIdTree , Visibility } ;
15
15
use rustc_resolve:: { ParentScope , Resolver } ;
16
16
use rustc_session:: config:: Externs ;
17
+ use rustc_session:: Session ;
17
18
use rustc_span:: { Symbol , SyntaxContext } ;
18
19
19
20
use std:: collections:: hash_map:: Entry ;
20
21
use std:: mem;
21
22
22
23
crate fn early_resolve_intra_doc_links (
23
24
resolver : & mut Resolver < ' _ > ,
25
+ sess : & Session ,
24
26
krate : & ast:: Crate ,
25
27
externs : Externs ,
26
28
document_private_items : bool ,
27
29
) -> ResolverCaches {
28
30
let mut link_resolver = EarlyDocLinkResolver {
29
31
resolver,
32
+ sess,
30
33
current_mod : CRATE_DEF_ID ,
31
34
visited_mods : Default :: default ( ) ,
32
35
markdown_links : Default :: default ( ) ,
@@ -70,6 +73,7 @@ fn doc_attrs<'a>(attrs: impl Iterator<Item = &'a ast::Attribute>) -> Attributes
70
73
71
74
struct EarlyDocLinkResolver < ' r , ' ra > {
72
75
resolver : & ' r mut Resolver < ' ra > ,
76
+ sess : & ' r Session ,
73
77
current_mod : LocalDefId ,
74
78
visited_mods : DefIdSet ,
75
79
markdown_links : FxHashMap < String , Vec < PreprocessedMarkdownLink > > ,
@@ -167,14 +171,22 @@ impl EarlyDocLinkResolver<'_, '_> {
167
171
}
168
172
}
169
173
170
- fn resolve_doc_links_extern_impl ( & mut self , def_id : DefId , _is_inherent : bool ) {
171
- // FIXME: Resolve links in associated items in addition to traits themselves,
172
- // `force` is used to provide traits in scope for the associated items.
173
- self . resolve_doc_links_extern_outer ( def_id, def_id, true ) ;
174
+ fn resolve_doc_links_extern_impl ( & mut self , def_id : DefId , is_inherent : bool ) {
175
+ self . resolve_doc_links_extern_outer ( def_id, def_id) ;
176
+ let assoc_item_def_ids = Vec :: from_iter (
177
+ self . resolver . cstore ( ) . associated_item_def_ids_untracked ( def_id, self . sess ) ,
178
+ ) ;
179
+ for assoc_def_id in assoc_item_def_ids {
180
+ if !is_inherent
181
+ || self . resolver . cstore ( ) . visibility_untracked ( assoc_def_id) == Visibility :: Public
182
+ {
183
+ self . resolve_doc_links_extern_outer ( assoc_def_id, def_id) ;
184
+ }
185
+ }
174
186
}
175
187
176
- fn resolve_doc_links_extern_outer ( & mut self , def_id : DefId , scope_id : DefId , force : bool ) {
177
- if !force && ! self . resolver . cstore ( ) . may_have_doc_links_untracked ( def_id) {
188
+ fn resolve_doc_links_extern_outer ( & mut self , def_id : DefId , scope_id : DefId ) {
189
+ if !self . resolver . cstore ( ) . may_have_doc_links_untracked ( def_id) {
178
190
return ;
179
191
}
180
192
// FIXME: actually resolve links, not just add traits in scope.
@@ -246,7 +258,7 @@ impl EarlyDocLinkResolver<'_, '_> {
246
258
Res :: Def ( DefKind :: Variant , ..) => self . resolver . parent ( def_id) . unwrap ( ) ,
247
259
_ => def_id,
248
260
} ;
249
- self . resolve_doc_links_extern_outer ( def_id, scope_id, false ) ; // Outer attribute scope
261
+ self . resolve_doc_links_extern_outer ( def_id, scope_id) ; // Outer attribute scope
250
262
if let Res :: Def ( DefKind :: Mod , ..) = child. res {
251
263
self . resolve_doc_links_extern_inner ( def_id) ; // Inner attribute scope
252
264
}
0 commit comments