Skip to content

Commit 68dfc1d

Browse files
Rollup merge of #158820 - TaKO8Ki:fix-deprecated-note-reexport-chain, r=GuillaumeGomez
Fix rustdoc ICE on deprecated note in inlined re-export chain Fixes #158745
2 parents 3ffc2ad + e7408fb commit 68dfc1d

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use smallvec::{SmallVec, smallvec};
3131
use tracing::{debug, info, instrument, trace};
3232

3333
use crate::clean::utils::find_nearest_parent_module;
34-
use crate::clean::{self, Crate, Item, ItemId, ItemLink, PrimitiveType};
34+
use crate::clean::{self, Crate, Item, ItemId, ItemLink, PrimitiveType, reexport_chain};
3535
use crate::core::DocContext;
3636
use crate::html::markdown::{MarkdownLink, MarkdownLinkRange, markdown_links};
3737
use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS};
@@ -1148,10 +1148,19 @@ impl LinkCollector<'_, '_> {
11481148
// `use` statement, we need to use the `def_id` of the `use` statement, not the
11491149
// inlined item.
11501150
// <https://github.com/rust-lang/rust/pull/151120>
1151-
let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id
1152-
&& find_attr!(tcx, inline_stmt_id, Deprecated { span, ..} if span == depr_span)
1153-
{
1154-
inline_stmt_id.to_def_id()
1151+
let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id {
1152+
let target_def_id = item.item_id.expect_def_id();
1153+
reexport_chain(tcx, inline_stmt_id, target_def_id)
1154+
.iter()
1155+
.flat_map(|reexport| reexport.id())
1156+
.find(|&reexport_def_id| {
1157+
find_attr!(
1158+
tcx,
1159+
reexport_def_id,
1160+
Deprecated { span, .. } if span == depr_span
1161+
)
1162+
})
1163+
.unwrap_or(target_def_id)
11551164
} else {
11561165
item.item_id.expect_def_id()
11571166
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
3+
// Regression test for https://github.com/rust-lang/rust/issues/158745.
4+
// This checks that rustdoc resolves intra-doc links in deprecation notes using
5+
// the re-export that carries the attribute, even when that re-export is later
6+
// inlined through another re-export.
7+
8+
#![deny(rustdoc::broken_intra_doc_links)]
9+
10+
mod bar {
11+
pub struct A;
12+
}
13+
14+
#[deprecated(note = "[std::io::ErrorKind::NotFound]")]
15+
pub use bar::A;
16+
17+
#[doc(inline)]
18+
pub use A as X;

0 commit comments

Comments
 (0)