@@ -14,19 +14,22 @@ use rustc_hir::TraitCandidate;
1414use rustc_middle:: ty:: { DefIdTree , Visibility } ;
1515use rustc_resolve:: { ParentScope , Resolver } ;
1616use rustc_session:: config:: Externs ;
17+ use rustc_session:: Session ;
1718use rustc_span:: { Symbol , SyntaxContext } ;
1819
1920use std:: collections:: hash_map:: Entry ;
2021use std:: mem;
2122
2223crate fn early_resolve_intra_doc_links (
2324 resolver : & mut Resolver < ' _ > ,
25+ sess : & Session ,
2426 krate : & ast:: Crate ,
2527 externs : Externs ,
2628 document_private_items : bool ,
2729) -> ResolverCaches {
2830 let mut link_resolver = EarlyDocLinkResolver {
2931 resolver,
32+ sess,
3033 current_mod : CRATE_DEF_ID ,
3134 visited_mods : Default :: default ( ) ,
3235 markdown_links : Default :: default ( ) ,
@@ -70,6 +73,7 @@ fn doc_attrs<'a>(attrs: impl Iterator<Item = &'a ast::Attribute>) -> Attributes
7073
7174struct EarlyDocLinkResolver < ' r , ' ra > {
7275 resolver : & ' r mut Resolver < ' ra > ,
76+ sess : & ' r Session ,
7377 current_mod : LocalDefId ,
7478 visited_mods : DefIdSet ,
7579 markdown_links : FxHashMap < String , Vec < PreprocessedMarkdownLink > > ,
@@ -167,14 +171,22 @@ impl EarlyDocLinkResolver<'_, '_> {
167171 }
168172 }
169173
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+ }
174186 }
175187
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) {
178190 return ;
179191 }
180192 // FIXME: actually resolve links, not just add traits in scope.
@@ -246,7 +258,7 @@ impl EarlyDocLinkResolver<'_, '_> {
246258 Res :: Def ( DefKind :: Variant , ..) => self . resolver . parent ( def_id) . unwrap ( ) ,
247259 _ => def_id,
248260 } ;
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
250262 if let Res :: Def ( DefKind :: Mod , ..) = child. res {
251263 self . resolve_doc_links_extern_inner ( def_id) ; // Inner attribute scope
252264 }
0 commit comments