@@ -213,15 +213,16 @@ fn rematch_object<'tcx>(
213213 mut nested : Vec < PredicateObligation < ' tcx > > ,
214214) -> SelectionResult < ' tcx , Selection < ' tcx > > {
215215 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 {
219218 bug ! ( )
220219 } ;
220+ let source_trait_ref = data. principal ( ) . unwrap ( ) . with_self_ty ( infcx. tcx , self_ty) ;
221221
222222 let ( is_upcasting, target_trait_ref_unnormalized) = if Some ( goal. predicate . def_id ( ) )
223223 == infcx. tcx . lang_items ( ) . unsize_trait ( )
224224 {
225+ assert_eq ! ( source_kind, ty:: Dyn , "cannot upcast dyn*" ) ;
225226 if let ty:: Dynamic ( data, _, ty:: Dyn ) = goal. predicate . trait_ref . substs . type_at ( 1 ) . kind ( ) {
226227 ( true , data. principal ( ) . unwrap ( ) . with_self_ty ( infcx. tcx , self_ty) )
227228 } else {
@@ -288,7 +289,8 @@ fn rematch_object<'tcx>(
288289 bug ! ( ) ;
289290 } ;
290291
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.
292294 Ok ( Some ( if is_upcasting {
293295 ImplSource :: TraitUpcasting ( ImplSourceTraitUpcastingData { vtable_vptr_slot, nested } )
294296 } else {
0 commit comments