Skip to content

Commit 728a2db

Browse files
committed
Add expect_ty method to Kind
1 parent 597f432 commit 728a2db

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/librustc/ty/subst.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ impl<'tcx> Kind<'tcx> {
123123
}
124124
}
125125
}
126+
127+
/// Unpack the `Kind` as a type when it is known certainly to be a type.
128+
/// This is true in cases where `Substs` is used in places where the kinds are known
129+
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
130+
pub fn expect_ty(self) -> Ty<'tcx> {
131+
match self.unpack() {
132+
UnpackedKind::Type(ty) => ty,
133+
_ => bug!("expected a type, but found another kind"),
134+
}
135+
}
126136
}
127137

128138
impl<'a, 'tcx> Lift<'tcx> for Kind<'a> {
@@ -174,8 +184,7 @@ pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>;
174184

175185
impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> {
176186
/// Creates a `InternalSubsts` that maps each generic parameter to itself.
177-
pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId)
178-
-> SubstsRef<'tcx> {
187+
pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
179188
Self::for_item(tcx, def_id, |param, _| {
180189
tcx.mk_param_from_def(param)
181190
})

0 commit comments

Comments
 (0)