From 5661fe3fa9e19715d5532d002341098e52fa0c76 Mon Sep 17 00:00:00 2001 From: Lucas De Angelis Date: Fri, 26 Feb 2021 22:09:39 +0100 Subject: [PATCH] Fix intra-doc handling of `Self` in enum Fixes #82209 --- src/librustdoc/passes/collect_intra_doc_links.rs | 3 +++ src/test/rustdoc/issue-82209.rs | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 src/test/rustdoc/issue-82209.rs diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 6d9e3d0b9eab0..2e1197b3fe7b6 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -838,6 +838,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { debug!("looking for the `Self` type"); let self_id = if item.is_fake() { None + // Checking if the item is a field in a variant in an enum + } else if (matches!(self.cx.tcx.def_kind(item.def_id), DefKind::Field) && matches!(self.cx.tcx.def_kind(self.cx.tcx.parent(item.def_id).unwrap()), DefKind::Variant)) { + self.cx.tcx.parent(item.def_id).and_then(|item_id| self.cx.tcx.parent(item_id)) } else if matches!( self.cx.tcx.def_kind(item.def_id), DefKind::AssocConst diff --git a/src/test/rustdoc/issue-82209.rs b/src/test/rustdoc/issue-82209.rs new file mode 100644 index 0000000000000..72a585a705eef --- /dev/null +++ b/src/test/rustdoc/issue-82209.rs @@ -0,0 +1,8 @@ +#![deny(broken_intra_doc_links)] +pub enum Foo { + Bar { + abc: i32, + /// [Self::Bar::abc] + xyz: i32, + }, +}