@@ -280,12 +280,12 @@ fn encode_region<'tcx>(region: Region<'tcx>, dict: &mut FxHashMap<DictKey<'tcx>,
280280 s. push ( 'E' ) ;
281281 compress ( dict, DictKey :: Region ( region) , & mut s) ;
282282 }
283- // FIXME(@lcnr): Why is `ReEarlyParam` reachable here.
284- RegionKind :: ReEarlyParam ( ..) | RegionKind :: ReErased => {
283+ RegionKind :: ReErased => {
285284 s. push_str ( "u6region" ) ;
286285 compress ( dict, DictKey :: Region ( region) , & mut s) ;
287286 }
288- RegionKind :: ReLateParam ( ..)
287+ RegionKind :: ReEarlyParam ( ..)
288+ | RegionKind :: ReLateParam ( ..)
289289 | RegionKind :: ReStatic
290290 | RegionKind :: ReError ( _)
291291 | RegionKind :: ReVar ( ..)
@@ -746,22 +746,40 @@ fn encode_ty<'tcx>(
746746}
747747
748748/// Transforms predicates for being encoded and used in the substitution dictionary.
749- fn transform_predicates < ' tcx > (
749+ fn transform_dyn_predicates < ' tcx > (
750750 tcx : TyCtxt < ' tcx > ,
751751 predicates : & List < ty:: PolyExistentialPredicate < ' tcx > > ,
752+ parents : & mut Vec < Ty < ' tcx > > ,
753+ options : TransformTyOptions ,
752754) -> & ' 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- } ) )
755+ let mut predicates: Vec < _ > = predicates
756+ . iter ( )
757+ . map ( |predicate| {
758+ predicate. map_bound ( |predicate| match predicate {
759+ ty:: ExistentialPredicate :: Trait ( ty:: ExistentialTraitRef { def_id, args } ) => {
760+ ty:: ExistentialPredicate :: Trait ( ty:: ExistentialTraitRef {
761+ def_id,
762+ args : transform_args ( tcx, args, parents, options) ,
763+ } )
764+ }
765+ ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
766+ def_id,
767+ args,
768+ term,
769+ } ) => ty:: ExistentialPredicate :: Projection ( ty:: ExistentialProjection {
770+ def_id,
771+ args : transform_args ( tcx, args, parents, options) ,
772+ term : match term. unpack ( ) {
773+ TermKind :: Ty ( ty) => transform_ty ( tcx, ty, parents, options) . into ( ) ,
774+ TermKind :: Const ( ct) => ct. into ( ) ,
775+ } ,
776+ } ) ,
777+ ty:: ExistentialPredicate :: AutoTrait ( ..) => predicate,
778+ } )
779+ } )
780+ . collect ( ) ;
781+ predicates. sort_by ( |a, b| a. skip_binder ( ) . stable_cmp ( tcx, & b. skip_binder ( ) ) ) ;
782+ tcx. mk_poly_existential_predicates ( & predicates)
765783}
766784
767785/// Transforms args for being encoded and used in the substitution dictionary.
@@ -935,11 +953,12 @@ fn transform_ty<'tcx>(
935953 }
936954
937955 ty:: Ref ( region, ty0, ..) => {
956+ assert_eq ! ( * region, tcx. lifetimes. re_erased) ;
938957 if options. contains ( TransformTyOptions :: GENERALIZE_POINTERS ) {
939958 if ty. is_mutable_ptr ( ) {
940- ty = Ty :: new_mut_ref ( tcx, tcx . lifetimes . re_static , Ty :: new_unit ( tcx) ) ;
959+ ty = Ty :: new_mut_ref ( tcx, * region , Ty :: new_unit ( tcx) ) ;
941960 } else {
942- ty = Ty :: new_imm_ref ( tcx, tcx . lifetimes . re_static , Ty :: new_unit ( tcx) ) ;
961+ ty = Ty :: new_imm_ref ( tcx, * region , Ty :: new_unit ( tcx) ) ;
943962 }
944963 } else {
945964 if ty. is_mutable_ptr ( ) {
@@ -993,25 +1012,22 @@ fn transform_ty<'tcx>(
9931012 }
9941013 }
9951014
996- ty:: Dynamic ( predicates, _region, kind) => {
1015+ ty:: Dynamic ( predicates, region, kind) => {
1016+ assert_eq ! ( * region, tcx. lifetimes. re_erased) ;
9971017 ty = Ty :: new_dynamic (
9981018 tcx,
999- transform_predicates ( tcx, predicates) ,
1000- tcx . lifetimes . re_erased ,
1019+ transform_dyn_predicates ( tcx, predicates, parents , options ) ,
1020+ * region ,
10011021 * kind,
10021022 ) ;
10031023 }
10041024
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 ( ..) => {
1025+ ty:: Alias ( ..)
1026+ | ty:: Bound ( ..)
1027+ | ty:: Error ( ..)
1028+ | ty:: Infer ( ..)
1029+ | ty:: Param ( ..)
1030+ | ty:: Placeholder ( ..) => {
10151031 bug ! ( "transform_ty: unexpected `{:?}`" , ty. kind( ) ) ;
10161032 }
10171033 }
0 commit comments