@@ -7,7 +7,6 @@ use std::fmt::Display;
77use std:: mem;
88use std:: ops:: Range ;
99
10- use rustc_ast:: attr:: AttributeExt ;
1110use rustc_ast:: util:: comments:: may_have_doc_links;
1211use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap , FxIndexSet } ;
1312use rustc_data_structures:: intern:: Interned ;
@@ -1038,20 +1037,21 @@ fn preprocessed_markdown_links(s: &str) -> Vec<PreprocessedMarkdownLink> {
10381037impl LinkCollector < ' _ , ' _ > {
10391038 #[ instrument( level = "debug" , skip_all) ]
10401039 fn resolve_links ( & mut self , item : & Item ) {
1040+ let tcx = self . cx . tcx ;
10411041 if !self . cx . document_private ( )
10421042 && let Some ( def_id) = item. item_id . as_def_id ( )
10431043 && let Some ( def_id) = def_id. as_local ( )
1044- && !self . cx . tcx . effective_visibilities ( ( ) ) . is_exported ( def_id)
1044+ && !tcx. effective_visibilities ( ( ) ) . is_exported ( def_id)
10451045 && !has_primitive_or_keyword_or_attribute_docs ( & item. attrs . other_attrs )
10461046 {
10471047 // Skip link resolution for non-exported items.
10481048 return ;
10491049 }
10501050
10511051 let mut insert_links = |item_id, doc : & str | {
1052- let module_id = match self . cx . tcx . def_kind ( item_id) {
1053- DefKind :: Mod if item. inner_docs ( self . cx . tcx ) => item_id,
1054- _ => find_nearest_parent_module ( self . cx . tcx , item_id) . unwrap ( ) ,
1052+ let module_id = match tcx. def_kind ( item_id) {
1053+ DefKind :: Mod if item. inner_docs ( tcx) => item_id,
1054+ _ => find_nearest_parent_module ( tcx, item_id) . unwrap ( ) ,
10551055 } ;
10561056 for md_link in preprocessed_markdown_links ( & doc) {
10571057 let link = self . resolve_link ( & doc, item, item_id, module_id, & md_link) ;
@@ -1084,15 +1084,33 @@ impl LinkCollector<'_, '_> {
10841084
10851085 // Also resolve links in the note text of `#[deprecated]`.
10861086 for attr in & item. attrs . other_attrs {
1087- let Some ( note_sym) = attr. deprecation_note ( ) else { continue } ;
1087+ let rustc_hir:: Attribute :: Parsed ( rustc_hir:: attrs:: AttributeKind :: Deprecation {
1088+ span,
1089+ deprecation,
1090+ } ) = attr
1091+ else {
1092+ continue ;
1093+ } ;
1094+ let Some ( note_sym) = deprecation. note else { continue } ;
10881095 let note = note_sym. as_str ( ) ;
10891096
10901097 if !may_have_doc_links ( note) {
10911098 continue ;
10921099 }
10931100
10941101 debug ! ( "deprecated_note={note}" ) ;
1095- insert_links ( item. item_id . expect_def_id ( ) , note)
1102+ // When resolving an intra-doc link inside a deprecation note that is on an inlined
1103+ // `use` statement, we need to use the `def_id` of the `use` statement, not the
1104+ // inlined item.
1105+ // <https://github.com/rust-lang/rust/pull/151120>
1106+ let item_id = if let Some ( inline_stmt_id) = item. inline_stmt_id
1107+ && item. span ( tcx) . is_none_or ( |item_span| !item_span. inner ( ) . contains ( * span) )
1108+ {
1109+ inline_stmt_id. to_def_id ( )
1110+ } else {
1111+ item. item_id . expect_def_id ( )
1112+ } ;
1113+ insert_links ( item_id, note)
10961114 }
10971115 }
10981116
0 commit comments