File tree Expand file tree Collapse file tree 3 files changed +17
-23
lines changed
rustc_codegen_ssa/src/traits Expand file tree Collapse file tree 3 files changed +17
-23
lines changed Original file line number Diff line number Diff line change 11use rustc_abi:: { AddressSpace , Float , Integer , Reg } ;
22use rustc_middle:: bug;
3+ use rustc_middle:: ty:: Ty ;
34use rustc_middle:: ty:: layout:: { HasTyCtxt , HasTypingEnv , TyAndLayout } ;
4- use rustc_middle:: ty:: { self , Ty } ;
55use rustc_target:: callconv:: { ArgAbi , CastTarget , FnAbi } ;
66
77use super :: BackendTypes ;
@@ -86,16 +86,7 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
8686 }
8787
8888 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 ( ) )
9990 }
10091}
10192
Original file line number Diff line number Diff line change @@ -208,6 +208,20 @@ impl<'tcx> TyCtxt<'tcx> {
208208 tcx. struct_tail_raw ( ty, |ty| tcx. normalize_erasing_regions ( typing_env, ty) , || { } )
209209 }
210210
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+
211225 /// Returns the deeply last field of nested structures, or the same type if
212226 /// not a structure at all. Corresponds to the only possible unsized field,
213227 /// 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>(
10431043) -> ( Ty < ' tcx > , Ty < ' tcx > ) {
10441044 let ptr_vtable = |inner_source : Ty < ' tcx > , inner_target : Ty < ' tcx > | {
10451045 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) {
10581047 ( inner_source, inner_target)
10591048 } else {
10601049 tcx. struct_lockstep_tails_for_codegen ( inner_source, inner_target, typing_env)
You can’t perform that action at this time.
0 commit comments