@@ -280,12 +280,12 @@ fn encode_region<'tcx>(region: Region<'tcx>, dict: &mut FxHashMap<DictKey<'tcx>,
280
280
s. push ( 'E' ) ;
281
281
compress ( dict, DictKey :: Region ( region) , & mut s) ;
282
282
}
283
- // FIXME(@lcnr): Why is `ReEarlyParam` reachable here.
284
- RegionKind :: ReEarlyParam ( ..) | RegionKind :: ReErased => {
283
+ RegionKind :: ReErased => {
285
284
s. push_str ( "u6region" ) ;
286
285
compress ( dict, DictKey :: Region ( region) , & mut s) ;
287
286
}
288
- RegionKind :: ReLateParam ( ..)
287
+ RegionKind :: ReEarlyParam ( ..)
288
+ | RegionKind :: ReLateParam ( ..)
289
289
| RegionKind :: ReStatic
290
290
| RegionKind :: ReError ( _)
291
291
| RegionKind :: ReVar ( ..)
@@ -746,22 +746,40 @@ fn encode_ty<'tcx>(
746
746
}
747
747
748
748
/// Transforms predicates for being encoded and used in the substitution dictionary.
749
- fn transform_predicates < ' tcx > (
749
+ fn transform_dyn_predicates < ' tcx > (
750
750
tcx : TyCtxt < ' tcx > ,
751
751
predicates : & List < ty:: PolyExistentialPredicate < ' tcx > > ,
752
+ parents : & mut Vec < Ty < ' tcx > > ,
753
+ options : TransformTyOptions ,
752
754
) -> & ' 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)
765
783
}
766
784
767
785
/// Transforms args for being encoded and used in the substitution dictionary.
@@ -935,11 +953,12 @@ fn transform_ty<'tcx>(
935
953
}
936
954
937
955
ty:: Ref ( region, ty0, ..) => {
956
+ assert_eq ! ( * region, tcx. lifetimes. re_erased) ;
938
957
if options. contains ( TransformTyOptions :: GENERALIZE_POINTERS ) {
939
958
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) ) ;
941
960
} 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) ) ;
943
962
}
944
963
} else {
945
964
if ty. is_mutable_ptr ( ) {
@@ -993,25 +1012,22 @@ fn transform_ty<'tcx>(
993
1012
}
994
1013
}
995
1014
996
- ty:: Dynamic ( predicates, _region, kind) => {
1015
+ ty:: Dynamic ( predicates, region, kind) => {
1016
+ assert_eq ! ( * region, tcx. lifetimes. re_erased) ;
997
1017
ty = Ty :: new_dynamic (
998
1018
tcx,
999
- transform_predicates ( tcx, predicates) ,
1000
- tcx . lifetimes . re_erased ,
1019
+ transform_dyn_predicates ( tcx, predicates, parents , options ) ,
1020
+ * region ,
1001
1021
* kind,
1002
1022
) ;
1003
1023
}
1004
1024
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 ( ..) => {
1015
1031
bug ! ( "transform_ty: unexpected `{:?}`" , ty. kind( ) ) ;
1016
1032
}
1017
1033
}
0 commit comments