Skip to content

Commit b927ac4

Browse files
Relax a debug assertion in codegen
1 parent 0399709 commit b927ac4

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

compiler/rustc_codegen_cranelift/src/unsize.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ pub(crate) fn unsized_info<'tcx>(
4343
// some reason, were to relax the `Unsize` trait, it could become
4444
// unsound, so let's assert here that the trait refs are *equal*.
4545
//
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.
46+
// FIXME: We could probably use real subtyping here, but that would require
47+
// us to reimplement something like `relate_types` from `rustc_const_eval`.
4848
debug_assert_eq!(
49-
data_a.principal(),
50-
data_b.principal(),
49+
data_a.principal().map(|p| fx.tcx().instantiate_bound_regions_with_erased(p)),
50+
data_b.principal().map(|p| fx.tcx().instantiate_bound_regions_with_erased(p)),
5151
"NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
5252
);
5353
return old_info;

compiler/rustc_codegen_ssa/src/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
134134
// some reason, were to relax the `Unsize` trait, it could become
135135
// unsound, so let's assert here that the trait refs are *equal*.
136136
//
137-
// We can use `assert_eq` because the binders should have been anonymized,
138-
// and because higher-ranked equality now requires the binders are equal.
137+
// FIXME: We could probably use real subtyping here, but that would require
138+
// us to reimplement something like `relate_types` from `rustc_const_eval`.
139139
debug_assert_eq!(
140-
data_a.principal(),
141-
data_b.principal(),
140+
data_a.principal().map(|p| cx.tcx().instantiate_bound_regions_with_erased(p)),
141+
data_b.principal().map(|p| cx.tcx().instantiate_bound_regions_with_erased(p)),
142142
"NOP unsize vtable changed principal trait ref: {data_a} -> {data_b}"
143143
);
144144

tests/ui/sub-principals-in-codegen.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ build-pass
2+
3+
// Regression test for an overly aggressive assertion in #130855.
4+
5+
fn main() {
6+
let subtype: &(dyn for<'a> Fn(&'a i32) -> &'a i32) = &|x| x;
7+
let supertype: &(dyn Fn(&'static i32) -> &'static i32) = subtype;
8+
}

0 commit comments

Comments
 (0)