Auto merge of #136311 - compiler-errors:vtable-fixes-2, r= · rust-lang/rust@cf8986d (original) (raw)
`@@ -318,9 +318,17 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe
`
318
318
`bug!();
`
319
319
`};
`
320
320
`let source_principal = tcx.instantiate_bound_regions_with_erased(
`
321
``
`-
source.principal().unwrap().with_self_ty(tcx, tcx.types.trait_object_dummy_self),
`
``
321
`+
source.principal().unwrap().with_self_ty(tcx, key.self_ty()),
`
322
322
`);
`
323
323
``
``
324
`+
// We're monomorphizing a call to a dyn trait object that can never be constructed.
`
``
325
`+
if tcx.instantiate_and_check_impossible_predicates((
`
``
326
`+
source_principal.def_id,
`
``
327
`+
source_principal.args,
`
``
328
`+
)) {
`
``
329
`+
return 0;
`
``
330
`+
}
`
``
331
+
324
332
`let target_principal = ty::ExistentialTraitRef::erase_self_ty(tcx, key);
`
325
333
``
326
334
`let vtable_segment_callback = {
`
`@@ -373,19 +381,27 @@ pub(crate) fn supertrait_vtable_slot<'tcx>(
`
373
381
`let (source, target) = key;
`
374
382
``
375
383
`` // If the target principal is None
, we can just return None
.
``
376
``
`-
let ty::Dynamic(target, _, _) = *target.kind() else {
`
``
384
`+
let ty::Dynamic(target_data, _, _) = *target.kind() else {
`
377
385
`bug!();
`
378
386
`};
`
379
``
`-
let target_principal = tcx.instantiate_bound_regions_with_erased(target.principal()?);
`
``
387
`+
let target_principal = tcx.instantiate_bound_regions_with_erased(target_data.principal()?);
`
380
388
``
381
389
`// 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 {
`
``
390
`+
let ty::Dynamic(source_data, _, _) = *source.kind() else {
`
383
391
`bug!();
`
384
392
`};
`
385
393
`let source_principal = tcx.instantiate_bound_regions_with_erased(
`
386
``
`-
source.principal().unwrap().with_self_ty(tcx, tcx.types.trait_object_dummy_self),
`
``
394
`+
source_data.principal().unwrap().with_self_ty(tcx, source),
`
387
395
`);
`
388
396
``
``
397
`+
// We're monomorphizing a dyn trait object upcast that can never be constructed.
`
``
398
`+
if tcx.instantiate_and_check_impossible_predicates((
`
``
399
`+
source_principal.def_id,
`
``
400
`+
source_principal.args,
`
``
401
`+
)) {
`
``
402
`+
return None;
`
``
403
`+
}
`
``
404
+
389
405
`let vtable_segment_callback = {
`
390
406
`let mut vptr_offset = 0;
`
391
407
`move |segment| {
`