Move some field extraction logic onto a method on Node
This commit is contained in:
parent
30ff127036
commit
cb161e77ba
@ -3743,6 +3743,29 @@ impl<'hir> Node<'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the type for constants, assoc types, type aliases and statics.
|
||||||
|
pub fn ty(self) -> Option<&'hir Ty<'hir>> {
|
||||||
|
match self {
|
||||||
|
Node::Item(it) => match it.kind {
|
||||||
|
ItemKind::TyAlias(ty, _) | ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => {
|
||||||
|
Some(ty)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
Node::TraitItem(it) => match it.kind {
|
||||||
|
TraitItemKind::Const(ty, _) => Some(ty),
|
||||||
|
TraitItemKind::Type(_, ty) => ty,
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
Node::ImplItem(it) => match it.kind {
|
||||||
|
ImplItemKind::Const(ty, _) => Some(ty),
|
||||||
|
ImplItemKind::Type(ty) => Some(ty),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
|
pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
|
||||||
match self {
|
match self {
|
||||||
Node::Item(Item { kind: ItemKind::TyAlias(ty, ..), .. }) => Some(ty),
|
Node::Item(Item { kind: ItemKind::TyAlias(ty, ..), .. }) => Some(ty),
|
||||||
|
@ -177,13 +177,9 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefKind::AssocTy | DefKind::AssocConst => {
|
DefKind::AssocTy | DefKind::AssocConst => {
|
||||||
let span = match tcx.hir().get_by_def_id(item) {
|
let span = match tcx.hir().get_by_def_id(item).ty() {
|
||||||
rustc_hir::Node::ImplItem(it) => match it.kind {
|
Some(ty) => ty.span,
|
||||||
rustc_hir::ImplItemKind::Const(ty, _) => ty.span,
|
_ => tcx.def_span(item),
|
||||||
rustc_hir::ImplItemKind::Type(ty) => ty.span,
|
|
||||||
other => span_bug!(tcx.def_span(item), "{other:#?}"),
|
|
||||||
},
|
|
||||||
other => span_bug!(tcx.def_span(item), "{other:#?}"),
|
|
||||||
};
|
};
|
||||||
collector.visit_spanned(span, tcx.type_of(item).subst_identity());
|
collector.visit_spanned(span, tcx.type_of(item).subst_identity());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user