Skip to content

Commit d10a16a

Browse files
Relax a debug assertion in codegen
1 parent 9b31c68 commit d10a16a

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/unsize.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! [`PointerCoercion::Unsize`]: `rustc_middle::ty::adjustment::PointerCoercion::Unsize`
44
5+
use rustc_codegen_ssa::base::validate_trivial_unsize;
56
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
67

78
use crate::base::codegen_panic_nounwind;
@@ -34,20 +35,8 @@ pub(crate) fn unsized_info<'tcx>(
3435
let old_info =
3536
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
3637
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),
5140
"NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
5241
);
5342
return old_info;

0 commit comments

Comments
 (0)