File tree 3 files changed +17
-23
lines changed
rustc_codegen_ssa/src/traits
3 files changed +17
-23
lines changed Original file line number Diff line number Diff line change 1
1
use rustc_abi:: { AddressSpace , Float , Integer , Reg } ;
2
2
use rustc_middle:: bug;
3
+ use rustc_middle:: ty:: Ty ;
3
4
use rustc_middle:: ty:: layout:: { HasTyCtxt , HasTypingEnv , TyAndLayout } ;
4
- use rustc_middle:: ty:: { self , Ty } ;
5
5
use rustc_target:: callconv:: { ArgAbi , CastTarget , FnAbi } ;
6
6
7
7
use super :: BackendTypes ;
@@ -86,16 +86,7 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
86
86
}
87
87
88
88
fn type_has_metadata ( & self , ty : Ty < ' tcx > ) -> bool {
89
- if ty. is_sized ( self . tcx ( ) , self . typing_env ( ) ) {
90
- return false ;
91
- }
92
-
93
- let tail = self . tcx ( ) . struct_tail_for_codegen ( ty, self . typing_env ( ) ) ;
94
- match tail. kind ( ) {
95
- ty:: Foreign ( ..) => false ,
96
- ty:: Str | ty:: Slice ( ..) | ty:: Dynamic ( ..) => true ,
97
- _ => bug ! ( "unexpected unsized tail: {:?}" , tail) ,
98
- }
89
+ self . tcx ( ) . type_has_metadata ( ty, self . typing_env ( ) )
99
90
}
100
91
}
101
92
Original file line number Diff line number Diff line change @@ -208,6 +208,20 @@ impl<'tcx> TyCtxt<'tcx> {
208
208
tcx. struct_tail_raw ( ty, |ty| tcx. normalize_erasing_regions ( typing_env, ty) , || { } )
209
209
}
210
210
211
+ /// Returns true if a type has metadata.
212
+ pub fn type_has_metadata ( self , ty : Ty < ' tcx > , typing_env : ty:: TypingEnv < ' tcx > ) -> bool {
213
+ if ty. is_sized ( self , typing_env) {
214
+ return false ;
215
+ }
216
+
217
+ let tail = self . struct_tail_for_codegen ( ty, typing_env) ;
218
+ match tail. kind ( ) {
219
+ ty:: Foreign ( ..) => false ,
220
+ ty:: Str | ty:: Slice ( ..) | ty:: Dynamic ( ..) => true ,
221
+ _ => bug ! ( "unexpected unsized tail: {:?}" , tail) ,
222
+ }
223
+ }
224
+
211
225
/// Returns the deeply last field of nested structures, or the same type if
212
226
/// not a structure at all. Corresponds to the only possible unsized field,
213
227
/// and its type can be used to determine unsizing strategy.
Original file line number Diff line number Diff line change @@ -1043,18 +1043,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
1043
1043
) -> ( Ty < ' tcx > , Ty < ' tcx > ) {
1044
1044
let ptr_vtable = |inner_source : Ty < ' tcx > , inner_target : Ty < ' tcx > | {
1045
1045
let typing_env = ty:: TypingEnv :: fully_monomorphized ( ) ;
1046
- let type_has_metadata = |ty : Ty < ' tcx > | -> bool {
1047
- if ty. is_sized ( tcx. tcx , typing_env) {
1048
- return false ;
1049
- }
1050
- let tail = tcx. struct_tail_for_codegen ( ty, typing_env) ;
1051
- match tail. kind ( ) {
1052
- ty:: Foreign ( ..) => false ,
1053
- ty:: Str | ty:: Slice ( ..) | ty:: Dynamic ( ..) => true ,
1054
- _ => bug ! ( "unexpected unsized tail: {:?}" , tail) ,
1055
- }
1056
- } ;
1057
- if type_has_metadata ( inner_source) {
1046
+ if tcx. type_has_metadata ( inner_source, typing_env) {
1058
1047
( inner_source, inner_target)
1059
1048
} else {
1060
1049
tcx. struct_lockstep_tails_for_codegen ( inner_source, inner_target, typing_env)
You can’t perform that action at this time.
0 commit comments