@@ -15,10 +15,9 @@ use hir::def_id::DefId;
1515use middle:: const_val:: ConstVal ;
1616use middle:: region;
1717use rustc_data_structures:: indexed_vec:: Idx ;
18- use ty:: subst:: { Substs , Subst } ;
18+ use ty:: subst:: { Substs , Subst , Kind , UnpackedKind } ;
1919use ty:: { self , AdtDef , TypeFlags , Ty , TyCtxt , TypeFoldable } ;
2020use ty:: { Slice , TyS } ;
21- use ty:: subst:: Kind ;
2221
2322use std:: iter;
2423use std:: cmp:: Ordering ;
@@ -297,8 +296,8 @@ impl<'tcx> ClosureSubsts<'tcx> {
297296 let generics = tcx. generics_of ( def_id) ;
298297 let parent_len = generics. parent_count ( ) ;
299298 SplitClosureSubsts {
300- closure_kind_ty : self . substs [ parent_len ] . as_type ( ) . expect ( "CK should be a type" ) ,
301- closure_sig_ty : self . substs [ parent_len + 1 ] . as_type ( ) . expect ( "CS should be a type" ) ,
299+ closure_kind_ty : self . substs . type_at ( parent_len ) ,
300+ closure_sig_ty : self . substs . type_at ( parent_len + 1 ) ,
302301 upvar_kinds : & self . substs [ parent_len + 2 ..] ,
303302 }
304303 }
@@ -308,7 +307,13 @@ impl<'tcx> ClosureSubsts<'tcx> {
308307 impl Iterator < Item =Ty < ' tcx > > + ' tcx
309308 {
310309 let SplitClosureSubsts { upvar_kinds, .. } = self . split ( def_id, tcx) ;
311- upvar_kinds. iter ( ) . map ( |t| t. as_type ( ) . expect ( "upvar should be type" ) )
310+ upvar_kinds. iter ( ) . map ( |t| {
311+ if let UnpackedKind :: Type ( ty) = t. unpack ( ) {
312+ ty
313+ } else {
314+ bug ! ( "upvar should be type" )
315+ }
316+ } )
312317 }
313318
314319 /// Returns the closure kind for this closure; may return a type
@@ -620,7 +625,7 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> {
620625 ty:: TraitRef {
621626 def_id : self . def_id ,
622627 substs : tcx. mk_substs (
623- iter:: once ( Kind :: from ( self_ty) ) . chain ( self . substs . iter ( ) . cloned ( ) ) )
628+ iter:: once ( self_ty. into ( ) ) . chain ( self . substs . iter ( ) . cloned ( ) ) )
624629 }
625630 }
626631}
@@ -1127,7 +1132,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> {
11271132 projection_ty : ty:: ProjectionTy {
11281133 item_def_id : self . item_def_id ,
11291134 substs : tcx. mk_substs (
1130- iter:: once ( Kind :: from ( self_ty) ) . chain ( self . substs . iter ( ) . cloned ( ) ) ) ,
1135+ iter:: once ( self_ty. into ( ) ) . chain ( self . substs . iter ( ) . cloned ( ) ) ) ,
11311136 } ,
11321137 ty : self . ty ,
11331138 }
0 commit comments