Skip to content

Commit ca4f422

Browse files
Normalize when equating dyn tails in MIR borrowck
1 parent 5367673 commit ca4f422

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2330,10 +2330,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23302330
match (cast_ty_from, cast_ty_to) {
23312331
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
23322332
let mut normalize = |t| self.normalize(t, location);
2333+
2334+
// N.B. `struct_tail_with_normalize` only "structurally resolves"
2335+
// the type. It is not fully normalized, so we have to normalize it
2336+
// afterwards.
23332337
let src_tail =
23342338
tcx.struct_tail_with_normalize(src.ty, &mut normalize, || ());
2339+
let src_tail = normalize(src_tail);
23352340
let dst_tail =
23362341
tcx.struct_tail_with_normalize(dst.ty, &mut normalize, || ());
2342+
let dst_tail = normalize(dst_tail);
23372343

23382344
// This checks (lifetime part of) vtable validity for pointer casts,
23392345
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ check-pass
2+
3+
trait Trait {
4+
type Associated;
5+
}
6+
7+
impl Trait for i32 {
8+
type Associated = i64;
9+
}
10+
11+
trait Generic<T> {}
12+
13+
type TraitObject = dyn Generic<<i32 as Trait>::Associated>;
14+
15+
struct Wrap(TraitObject);
16+
17+
fn cast(x: *mut TraitObject) {
18+
x as *mut Wrap;
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)