Skip to content

Commit 25c5e39

Browse files
committed
rustdoc: Clean up fn resolve_self_ty
1 parent 863216e commit 25c5e39

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+23-30
Original file line numberDiff line numberDiff line change
@@ -515,36 +515,29 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
515515
return None;
516516
}
517517

518-
let self_id = match item_id.as_def_id() {
519-
None => None,
520-
Some(did)
521-
if (matches!(self.cx.tcx.def_kind(did), DefKind::Field)
522-
&& matches!(
523-
self.cx.tcx.def_kind(self.cx.tcx.parent(did).unwrap()),
524-
DefKind::Variant
525-
)) =>
526-
{
527-
self.cx.tcx.parent(did).and_then(|item_id| self.cx.tcx.parent(item_id))
528-
}
529-
Some(did)
530-
if matches!(
531-
self.cx.tcx.def_kind(did),
532-
DefKind::AssocConst
533-
| DefKind::AssocFn
534-
| DefKind::AssocTy
535-
| DefKind::Variant
536-
| DefKind::Field
537-
) =>
538-
{
539-
self.cx.tcx.parent(did)
540-
}
541-
Some(did) => Some(did),
542-
};
543-
544-
self_id.and_then(|self_id| match self.cx.tcx.def_kind(self_id) {
545-
DefKind::Impl => self.def_id_to_res(self_id),
546-
def_kind => Some(Res::Def(def_kind, self_id)),
547-
})
518+
let tcx = self.cx.tcx;
519+
item_id
520+
.as_def_id()
521+
.map(|def_id| match tcx.def_kind(def_id) {
522+
def_kind @ (DefKind::AssocFn
523+
| DefKind::AssocConst
524+
| DefKind::AssocTy
525+
| DefKind::Variant
526+
| DefKind::Field) => {
527+
let parent_def_id = tcx.parent(def_id).expect("nested item has no parent");
528+
if def_kind == DefKind::Field && tcx.def_kind(parent_def_id) == DefKind::Variant
529+
{
530+
tcx.parent(parent_def_id).expect("variant has no parent")
531+
} else {
532+
parent_def_id
533+
}
534+
}
535+
_ => def_id,
536+
})
537+
.and_then(|self_id| match tcx.def_kind(self_id) {
538+
DefKind::Impl => self.def_id_to_res(self_id),
539+
def_kind => Some(Res::Def(def_kind, self_id)),
540+
})
548541
}
549542

550543
/// Convenience wrapper around `resolve_str_path_error`.

0 commit comments

Comments
 (0)