diff options
| author | varkor <github@varkor.com> | 2019-04-26 00:26:33 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-04-26 20:57:13 +0100 |
| commit | 728a2db35e76f5126a405db917757ee43910c136 (patch) | |
| tree | c4d20c0a1f44d136171ceef110606b812a1a2faa | |
| parent | 597f432489f12a3f33419daa039ccef11a12c4fd (diff) | |
| download | rust-728a2db35e76f5126a405db917757ee43910c136.tar.gz rust-728a2db35e76f5126a405db917757ee43910c136.zip | |
Add expect_ty method to Kind
| -rw-r--r-- | src/librustc/ty/subst.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index b8ae0430502..ed3da31fb89 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -123,6 +123,16 @@ impl<'tcx> Kind<'tcx> { } } } + + /// Unpack the `Kind` as a type when it is known certainly to be a type. + /// This is true in cases where `Substs` is used in places where the kinds are known + /// to be limited (e.g. in tuples, where the only parameters are type parameters). + pub fn expect_ty(self) -> Ty<'tcx> { + match self.unpack() { + UnpackedKind::Type(ty) => ty, + _ => bug!("expected a type, but found another kind"), + } + } } impl<'a, 'tcx> Lift<'tcx> for Kind<'a> { @@ -174,8 +184,7 @@ pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>; impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { /// Creates a `InternalSubsts` that maps each generic parameter to itself. - pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) - -> SubstsRef<'tcx> { + pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> SubstsRef<'tcx> { Self::for_item(tcx, def_id, |param, _| { tcx.mk_param_from_def(param) }) |
