@@ -232,6 +232,11 @@ fn vtable_entries<'tcx>(
232
232
"vtable trait ref should be normalized"
233
233
) ;
234
234
235
+ // We're monomorphizing a dyn trait object that can never be constructed.
236
+ if tcx. instantiate_and_check_impossible_predicates ( ( trait_ref. def_id , trait_ref. args ) ) {
237
+ return TyCtxt :: COMMON_VTABLE_ENTRIES ;
238
+ }
239
+
235
240
debug ! ( "vtable_entries({:?})" , trait_ref) ;
236
241
237
242
let mut entries = vec ! [ ] ;
@@ -318,9 +323,17 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
318
323
bug ! ( ) ;
319
324
} ;
320
325
let source_principal = tcx. instantiate_bound_regions_with_erased (
321
- source. principal ( ) . unwrap ( ) . with_self_ty ( tcx, tcx . types . trait_object_dummy_self ) ,
326
+ source. principal ( ) . unwrap ( ) . with_self_ty ( tcx, key . self_ty ( ) ) ,
322
327
) ;
323
328
329
+ // We're monomorphizing a dyn trait object that can never be constructed.
330
+ if tcx. instantiate_and_check_impossible_predicates ( (
331
+ source_principal. def_id ,
332
+ source_principal. args ,
333
+ ) ) {
334
+ return 0 ;
335
+ }
336
+
324
337
let target_principal = ty:: ExistentialTraitRef :: erase_self_ty ( tcx, key) ;
325
338
326
339
let vtable_segment_callback = {
@@ -373,19 +386,27 @@ pub(crate) fn supertrait_vtable_slot<'tcx>(
373
386
let ( source, target) = key;
374
387
375
388
// If the target principal is `None`, we can just return `None`.
376
- let ty:: Dynamic ( target , _, _) = * target. kind ( ) else {
389
+ let ty:: Dynamic ( target_data , _, _) = * target. kind ( ) else {
377
390
bug ! ( ) ;
378
391
} ;
379
- let target_principal = tcx. instantiate_bound_regions_with_erased ( target . principal ( ) ?) ;
392
+ let target_principal = tcx. instantiate_bound_regions_with_erased ( target_data . principal ( ) ?) ;
380
393
381
394
// Given that we have a target principal, it is a bug for there not to be a source principal.
382
- let ty:: Dynamic ( source , _, _) = * source. kind ( ) else {
395
+ let ty:: Dynamic ( source_data , _, _) = * source. kind ( ) else {
383
396
bug ! ( ) ;
384
397
} ;
385
398
let source_principal = tcx. instantiate_bound_regions_with_erased (
386
- source . principal ( ) . unwrap ( ) . with_self_ty ( tcx, tcx . types . trait_object_dummy_self ) ,
399
+ source_data . principal ( ) . unwrap ( ) . with_self_ty ( tcx, source ) ,
387
400
) ;
388
401
402
+ // We're monomorphizing a dyn trait object that can never be constructed.
403
+ if tcx. instantiate_and_check_impossible_predicates ( (
404
+ source_principal. def_id ,
405
+ source_principal. args ,
406
+ ) ) {
407
+ return None ;
408
+ }
409
+
389
410
let vtable_segment_callback = {
390
411
let mut vptr_offset = 0 ;
391
412
move |segment| {
0 commit comments