@@ -281,11 +281,12 @@ fn encode_region<'tcx>(region: Region<'tcx>, dict: &mut FxHashMap<DictKey<'tcx>,
281281 compress ( dict, DictKey :: Region ( region) , & mut s) ;
282282 }
283283 // FIXME(@lcnr): Why is `ReEarlyParam` reachable here.
284- RegionKind :: ReEarlyParam ( .. ) | RegionKind :: ReErased => {
284+ RegionKind :: ReErased => {
285285 s. push_str ( "u6region" ) ;
286286 compress ( dict, DictKey :: Region ( region) , & mut s) ;
287287 }
288- RegionKind :: ReLateParam ( ..)
288+ RegionKind :: ReEarlyParam ( ..)
289+ | RegionKind :: ReLateParam ( ..)
289290 | RegionKind :: ReStatic
290291 | RegionKind :: ReError ( _)
291292 | RegionKind :: ReVar ( ..)
@@ -746,22 +747,40 @@ fn encode_ty<'tcx>(
746747}
747748
748749/// Transforms predicates for being encoded and used in the substitution dictionary.
749- fn transform_predicates < ' tcx > (
750+ fn transform_dyn_predicates < ' tcx > (
750751 tcx : TyCtxt < ' tcx > ,
751752 predicates : & List < ty:: PolyExistentialPredicate < ' tcx > > ,
753+ parents : & mut Vec < Ty < ' tcx > > ,
754+ options : TransformTyOptions ,
752755) -> & ' tcx List < ty:: PolyExistentialPredicate < ' tcx > > {
753- tcx. mk_poly_existential_predicates_from_iter ( predicates. iter ( ) . filter_map ( |predicate| {
754- match predicate. skip_binder ( ) {
755- ty:: ExistentialPredicate :: Trait ( trait_ref) => {
756- let trait_ref = ty:: TraitRef :: identity ( tcx, trait_ref. def_id ) ;
757- Some ( ty:: Binder :: dummy ( ty:: ExistentialPredicate :: Trait (
758- ty:: ExistentialTraitRef :: erase_self_ty ( tcx, trait_ref) ,
759- ) ) )
760- }
761- ty:: ExistentialPredicate :: Projection ( ..) => None ,
762- ty:: ExistentialPredicate :: AutoTrait ( ..) => Some ( predicate) ,
763- }
764- } ) )
756+ let mut predicates: Vec < _ > = predicates
757+ . iter ( )
758+ . map ( |predicate| {
759+ predicate. map_bound ( |predicate| match predicate {
760+ ty:: ExistentialPredicate :: Trait ( ty:: ExistentialTraitRef { def_id, args } ) => {
761+ ty:: ExistentialPredicate :: Trait ( ty:: ExistentialTraitRef {
762+ def_id,
763+ args : transform_args ( tcx, args, parents, options) ,
764+ } )
765+ }
766+ ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
767+ def_id,
768+ args,
769+ term,
770+ } ) => ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
771+ def_id,
772+ args : transform_args ( tcx, args, parents, options) ,
773+ term : match term. unpack ( ) {
774+ TermKind :: Ty ( ty) => transform_ty ( tcx, ty, parents, options) . into ( ) ,
775+ TermKind :: Const ( ct) => ct. into ( ) ,
776+ } ,
777+ } ) ,
778+ ty:: ExistentialPredicate :: AutoTrait ( ..) => predicate,
779+ } )
780+ } )
781+ . collect ( ) ;
782+ predicates. sort_by ( |a, b| a. skip_binder ( ) . stable_cmp ( tcx, & b. skip_binder ( ) ) ) ;
783+ tcx. mk_poly_existential_predicates ( & predicates)
765784}
766785
767786/// Transforms args for being encoded and used in the substitution dictionary.
@@ -935,11 +954,12 @@ fn transform_ty<'tcx>(
935954 }
936955
937956 ty:: Ref ( region, ty0, ..) => {
957+ assert_eq ! ( * region, tcx. lifetimes. re_erased) ;
938958 if options. contains ( TransformTyOptions :: GENERALIZE_POINTERS ) {
939959 if ty. is_mutable_ptr ( ) {
940- ty = Ty :: new_mut_ref ( tcx, tcx . lifetimes . re_static , Ty :: new_unit ( tcx) ) ;
960+ ty = Ty :: new_mut_ref ( tcx, * region , Ty :: new_unit ( tcx) ) ;
941961 } else {
942- ty = Ty :: new_imm_ref ( tcx, tcx . lifetimes . re_static , Ty :: new_unit ( tcx) ) ;
962+ ty = Ty :: new_imm_ref ( tcx, * region , Ty :: new_unit ( tcx) ) ;
943963 }
944964 } else {
945965 if ty. is_mutable_ptr ( ) {
@@ -993,25 +1013,22 @@ fn transform_ty<'tcx>(
9931013 }
9941014 }
9951015
996- ty:: Dynamic ( predicates, _region, kind) => {
1016+ ty:: Dynamic ( predicates, region, kind) => {
1017+ assert_eq ! ( * region, tcx. lifetimes. re_erased) ;
9971018 ty = Ty :: new_dynamic (
9981019 tcx,
999- transform_predicates ( tcx, predicates) ,
1000- tcx . lifetimes . re_erased ,
1020+ transform_dyn_predicates ( tcx, predicates, parents , options ) ,
1021+ * region ,
10011022 * kind,
10021023 ) ;
10031024 }
10041025
1005- ty:: Alias ( ..) => {
1006- ty = transform_ty (
1007- tcx,
1008- tcx. normalize_erasing_regions ( ty:: ParamEnv :: reveal_all ( ) , ty) ,
1009- parents,
1010- options,
1011- ) ;
1012- }
1013-
1014- ty:: Bound ( ..) | ty:: Error ( ..) | ty:: Infer ( ..) | ty:: Param ( ..) | ty:: Placeholder ( ..) => {
1026+ ty:: Alias ( ..)
1027+ | ty:: Bound ( ..)
1028+ | ty:: Error ( ..)
1029+ | ty:: Infer ( ..)
1030+ | ty:: Param ( ..)
1031+ | ty:: Placeholder ( ..) => {
10151032 bug ! ( "transform_ty: unexpected `{:?}`" , ty. kind( ) ) ;
10161033 }
10171034 }
0 commit comments