@@ -40,6 +40,7 @@ use rustc_span::symbol::sym;
4040use rustc_span:: Symbol ;
4141use rustc_span:: { DebuggerVisualizerFile , DebuggerVisualizerType } ;
4242use rustc_target:: abi:: { Align , Size , VariantIdx } ;
43+ use rustc_type_ir:: DynKind ;
4344
4445use std:: collections:: BTreeSet ;
4546use std:: time:: { Duration , Instant } ;
@@ -150,10 +151,8 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
150151 ( & ty:: Array ( _, len) , & ty:: Slice ( _) ) => {
151152 cx. const_usize ( len. eval_usize ( cx. tcx ( ) , ty:: ParamEnv :: reveal_all ( ) ) )
152153 }
153- (
154- & ty:: Dynamic ( ref data_a, _, src_dyn_kind) ,
155- & ty:: Dynamic ( ref data_b, _, target_dyn_kind) ,
156- ) if src_dyn_kind == target_dyn_kind => {
154+ ( & ty:: Dynamic ( ref data_a, _) , & ty:: Dynamic ( ref data_b, _) )
155+ | ( & ty:: DynStar ( ref data_a, _) , & ty:: DynStar ( ref data_b, _) ) => {
157156 let old_info =
158157 old_info. expect ( "unsized_info: missing old info for trait upcasting coercion" ) ;
159158 if data_a. principal_def_id ( ) == data_b. principal_def_id ( ) {
@@ -169,7 +168,15 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
169168 if let Some ( entry_idx) = vptr_entry_idx {
170169 let ptr_ty = cx. type_i8p ( ) ;
171170 let ptr_align = cx. tcx ( ) . data_layout . pointer_align . abi ;
172- let vtable_ptr_ty = vtable_ptr_ty ( cx, target, target_dyn_kind) ;
171+ let vtable_ptr_ty = vtable_ptr_ty (
172+ cx,
173+ target,
174+ match target. kind ( ) {
175+ ty:: Dynamic ( ..) => DynKind :: Dyn ,
176+ ty:: DynStar ( ..) => DynKind :: DynStar ,
177+ _ => unreachable ! ( ) ,
178+ } ,
179+ ) ;
173180 let llvtable = bx. pointercast ( old_info, bx. type_ptr_to ( ptr_ty) ) ;
174181 let gep = bx. inbounds_gep (
175182 ptr_ty,
@@ -185,8 +192,12 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
185192 old_info
186193 }
187194 }
188- ( _, & ty:: Dynamic ( ref data, _, target_dyn_kind) ) => {
189- let vtable_ptr_ty = vtable_ptr_ty ( cx, target, target_dyn_kind) ;
195+ ( _, & ty:: Dynamic ( ref data, _) ) => {
196+ let vtable_ptr_ty = vtable_ptr_ty ( cx, target, DynKind :: Dyn ) ;
197+ cx. const_ptrcast ( meth:: get_vtable ( cx, source, data. principal ( ) ) , vtable_ptr_ty)
198+ }
199+ ( _, & ty:: DynStar ( ref data, _) ) => {
200+ let vtable_ptr_ty = vtable_ptr_ty ( cx, target, DynKind :: DynStar ) ;
190201 cx. const_ptrcast ( meth:: get_vtable ( cx, source, data. principal ( ) ) , vtable_ptr_ty)
191202 }
192203 _ => bug ! ( "unsized_info: invalid unsizing {:?} -> {:?}" , source, target) ,
@@ -197,14 +208,15 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
197208fn vtable_ptr_ty < ' tcx , Cx : CodegenMethods < ' tcx > > (
198209 cx : & Cx ,
199210 target : Ty < ' tcx > ,
211+ // FIXME(dyn-star): This should be only place we need a `DynKind`, so move its definition here.
200212 kind : ty:: DynKind ,
201213) -> <Cx as BackendTypes >:: Type {
202214 cx. scalar_pair_element_backend_type (
203215 cx. layout_of ( match kind {
204216 // vtable is the second field of `*mut dyn Trait`
205- ty :: Dyn => cx. tcx ( ) . mk_mut_ptr ( target) ,
217+ DynKind :: Dyn => cx. tcx ( ) . mk_mut_ptr ( target) ,
206218 // vtable is the second field of `dyn* Trait`
207- ty :: DynStar => target,
219+ DynKind :: DynStar => target,
208220 } ) ,
209221 1 ,
210222 true ,
@@ -269,10 +281,7 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
269281 old_info : Option < Bx :: Value > ,
270282) -> ( Bx :: Value , Bx :: Value ) {
271283 debug ! ( "cast_to_dyn_star: {:?} => {:?}" , src_ty_and_layout. ty, dst_ty) ;
272- assert ! (
273- matches!( dst_ty. kind( ) , ty:: Dynamic ( _, _, ty:: DynStar ) ) ,
274- "destination type must be a dyn*"
275- ) ;
284+ assert ! ( matches!( dst_ty. kind( ) , ty:: DynStar ( _, _) ) , "destination type must be a dyn*" ) ;
276285 // FIXME(dyn-star): this is probably not the best way to check if this is
277286 // a pointer, and really we should ensure that the value is a suitable
278287 // pointer earlier in the compilation process.
0 commit comments