|
2 | 2 | //!
|
3 | 3 | //! [`PointerCoercion::Unsize`]: `rustc_middle::ty::adjustment::PointerCoercion::Unsize`
|
4 | 4 |
|
| 5 | +use rustc_codegen_ssa::base::validate_trivial_unsize; |
5 | 6 | use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
6 | 7 |
|
7 | 8 | use crate::base::codegen_panic_nounwind;
|
@@ -34,20 +35,8 @@ pub(crate) fn unsized_info<'tcx>(
|
34 | 35 | let old_info =
|
35 | 36 | old_info.expect("unsized_info: missing old info for trait upcasting coercion");
|
36 | 37 | if data_a.principal_def_id() == data_b.principal_def_id() {
|
37 |
| - // Codegen takes advantage of the additional assumption, where if the |
38 |
| - // principal trait def id of what's being casted doesn't change, |
39 |
| - // then we don't need to adjust the vtable at all. This |
40 |
| - // corresponds to the fact that `dyn Tr<A>: Unsize<dyn Tr<B>>` |
41 |
| - // requires that `A = B`; we don't allow *upcasting* objects |
42 |
| - // between the same trait with different args. If we, for |
43 |
| - // some reason, were to relax the `Unsize` trait, it could become |
44 |
| - // unsound, so let's assert here that the trait refs are *equal*. |
45 |
| - // |
46 |
| - // We can use `assert_eq` because the binders should have been anonymized, |
47 |
| - // and because higher-ranked equality now requires the binders are equal. |
48 |
| - debug_assert_eq!( |
49 |
| - data_a.principal(), |
50 |
| - data_b.principal(), |
| 38 | + debug_assert!( |
| 39 | + validate_trivial_unsize(fx.tcx, data_a, data_b), |
51 | 40 | "NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
|
52 | 41 | );
|
53 | 42 | return old_info;
|
|
0 commit comments