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