@@ -7,6 +7,7 @@ use std::fmt::Display;
77use std:: mem;
88use std:: ops:: Range ;
99
10+ use rustc_ast:: attr:: AttributeExt ;
1011use rustc_ast:: util:: comments:: may_have_doc_links;
1112use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet } ;
1213use rustc_data_structures:: intern:: Interned ;
@@ -1047,18 +1048,7 @@ impl LinkCollector<'_, '_> {
10471048 return ;
10481049 }
10491050
1050- // We want to resolve in the lexical scope of the documentation.
1051- // In the presence of re-exports, this is not the same as the module of the item.
1052- // Rather than merging all documentation into one, resolve it one attribute at a time
1053- // so we know which module it came from.
1054- for ( item_id, doc) in prepare_to_doc_link_resolution ( & item. attrs . doc_strings ) {
1055- if !may_have_doc_links ( & doc) {
1056- continue ;
1057- }
1058- debug ! ( "combined_docs={doc}" ) ;
1059- // NOTE: if there are links that start in one crate and end in another, this will not resolve them.
1060- // This is a degenerate case and it's not supported by rustdoc.
1061- let item_id = item_id. unwrap_or_else ( || item. item_id . expect_def_id ( ) ) ;
1051+ let mut insert_links = |item_id, doc : & str | {
10621052 let module_id = match self . cx . tcx . def_kind ( item_id) {
10631053 DefKind :: Mod if item. inner_docs ( self . cx . tcx ) => item_id,
10641054 _ => find_nearest_parent_module ( self . cx . tcx , item_id) . unwrap ( ) ,
@@ -1074,6 +1064,35 @@ impl LinkCollector<'_, '_> {
10741064 . insert ( link) ;
10751065 }
10761066 }
1067+ } ;
1068+
1069+ // We want to resolve in the lexical scope of the documentation.
1070+ // In the presence of re-exports, this is not the same as the module of the item.
1071+ // Rather than merging all documentation into one, resolve it one attribute at a time
1072+ // so we know which module it came from.
1073+ for ( item_id, doc) in prepare_to_doc_link_resolution ( & item. attrs . doc_strings ) {
1074+ if !may_have_doc_links ( & doc) {
1075+ continue ;
1076+ }
1077+
1078+ debug ! ( "combined_docs={doc}" ) ;
1079+ // NOTE: if there are links that start in one crate and end in another, this will not resolve them.
1080+ // This is a degenerate case and it's not supported by rustdoc.
1081+ let item_id = item_id. unwrap_or_else ( || item. item_id . expect_def_id ( ) ) ;
1082+ insert_links ( item_id, & doc)
1083+ }
1084+
1085+ // Also resolve links in the note text of `#[deprecated]`.
1086+ for attr in & item. attrs . other_attrs {
1087+ let Some ( note_sym) = attr. deprecation_note ( ) else { continue } ;
1088+ let note = note_sym. as_str ( ) ;
1089+
1090+ if !may_have_doc_links ( note) {
1091+ continue ;
1092+ }
1093+
1094+ debug ! ( "deprecated_note={note}" ) ;
1095+ insert_links ( item. item_id . expect_def_id ( ) , note)
10771096 }
10781097 }
10791098
@@ -1086,7 +1105,7 @@ impl LinkCollector<'_, '_> {
10861105 /// FIXME(jynelson): this is way too many arguments
10871106 fn resolve_link (
10881107 & mut self ,
1089- dox : & String ,
1108+ dox : & str ,
10901109 item : & Item ,
10911110 item_id : DefId ,
10921111 module_id : DefId ,
0 commit comments