@@ -213,15 +213,16 @@ fn rematch_object<'tcx>(
213
213
mut nested : Vec < PredicateObligation < ' tcx > > ,
214
214
) -> SelectionResult < ' tcx , Selection < ' tcx > > {
215
215
let self_ty = goal. predicate . self_ty ( ) ;
216
- let source_trait_ref = if let ty:: Dynamic ( data, _, ty:: Dyn ) = self_ty. kind ( ) {
217
- data. principal ( ) . unwrap ( ) . with_self_ty ( infcx. tcx , self_ty)
218
- } else {
216
+ let ty:: Dynamic ( data, _, source_kind) = * self_ty. kind ( )
217
+ else {
219
218
bug ! ( )
220
219
} ;
220
+ let source_trait_ref = data. principal ( ) . unwrap ( ) . with_self_ty ( infcx. tcx , self_ty) ;
221
221
222
222
let ( is_upcasting, target_trait_ref_unnormalized) = if Some ( goal. predicate . def_id ( ) )
223
223
== infcx. tcx . lang_items ( ) . unsize_trait ( )
224
224
{
225
+ assert_eq ! ( source_kind, ty:: Dyn , "cannot upcast dyn*" ) ;
225
226
if let ty:: Dynamic ( data, _, ty:: Dyn ) = goal. predicate . trait_ref . substs . type_at ( 1 ) . kind ( ) {
226
227
( true , data. principal ( ) . unwrap ( ) . with_self_ty ( infcx. tcx , self_ty) )
227
228
} else {
@@ -288,7 +289,8 @@ fn rematch_object<'tcx>(
288
289
bug ! ( ) ;
289
290
} ;
290
291
291
- // If we're upcasting, get the offset of the vtable pointer, which is
292
+ // If we're upcasting, get the offset of the vtable pointer, otherwise get
293
+ // the base of the vtable.
292
294
Ok ( Some ( if is_upcasting {
293
295
ImplSource :: TraitUpcasting ( ImplSourceTraitUpcastingData { vtable_vptr_slot, nested } )
294
296
} else {
0 commit comments