@@ -1047,29 +1047,36 @@ pub fn transform_fnabi<'tcx>(
1047
1047
// pointers.
1048
1048
return transform_fn_trait_fnabi ( tcx, fn_abi, options) ;
1049
1049
} else {
1050
- // Replace the concrete self by a reference to a trait object (i.e., perform
1051
- // type erasure). Non Fn trait objects are transformed into their identities
1052
- // in transform_predicate.
1053
- if fn_abi. args [ 0 ] . layout . ty . is_mutable_ptr ( ) {
1054
- Ty :: new_mut_ref (
1055
- tcx,
1056
- tcx. lifetimes . re_erased ,
1057
- new_dynamic_trait (
1058
- tcx,
1059
- trait_ref. skip_binder ( ) . def_id ,
1060
- trait_ref. skip_binder ( ) . args ,
1061
- ) ,
1062
- )
1050
+ if options. contains ( EncodeTyOptions :: NO_TYPE_ERASURE ) {
1051
+ // Do not perform type erasure for assigning a secondary type id to
1052
+ // methods with their concrete self so they can be used as function
1053
+ // pointers.
1054
+ return fn_abi. clone ( ) ;
1063
1055
} else {
1064
- Ty :: new_imm_ref (
1065
- tcx,
1066
- tcx. lifetimes . re_erased ,
1067
- new_dynamic_trait (
1056
+ // Replace the concrete self by a reference to a trait object (i.e., perform
1057
+ // type erasure). Non Fn trait objects are transformed into their identities
1058
+ // in transform_predicate.
1059
+ if fn_abi. args [ 0 ] . layout . ty . is_mutable_ptr ( ) {
1060
+ Ty :: new_mut_ref (
1068
1061
tcx,
1069
- trait_ref. skip_binder ( ) . def_id ,
1070
- trait_ref. skip_binder ( ) . args ,
1071
- ) ,
1072
- )
1062
+ tcx. lifetimes . re_erased ,
1063
+ new_dynamic_trait (
1064
+ tcx,
1065
+ trait_ref. skip_binder ( ) . def_id ,
1066
+ trait_ref. skip_binder ( ) . args ,
1067
+ ) ,
1068
+ )
1069
+ } else {
1070
+ Ty :: new_imm_ref (
1071
+ tcx,
1072
+ tcx. lifetimes . re_erased ,
1073
+ new_dynamic_trait (
1074
+ tcx,
1075
+ trait_ref. skip_binder ( ) . def_id ,
1076
+ trait_ref. skip_binder ( ) . args ,
1077
+ ) ,
1078
+ )
1079
+ }
1073
1080
}
1074
1081
} ;
1075
1082
let mut fn_abi = fn_abi. clone ( ) ;
0 commit comments