Skip to content

Commit 9fce4e1

Browse files
compiler-errorscuviper
authored andcommitted
Normalize when equating dyn tails in MIR borrowck
(cherry picked from commit c6f8672)
1 parent 73f1331 commit 9fce4e1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,10 +2337,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23372337
match (cast_ty_from, cast_ty_to) {
23382338
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
23392339
let mut normalize = |t| self.normalize(t, location);
2340+
2341+
// N.B. `struct_tail_with_normalize` only "structurally resolves"
2342+
// the type. It is not fully normalized, so we have to normalize it
2343+
// afterwards.
23402344
let src_tail =
23412345
tcx.struct_tail_with_normalize(src.ty, &mut normalize, || ());
2346+
let src_tail = normalize(src_tail);
23422347
let dst_tail =
23432348
tcx.struct_tail_with_normalize(dst.ty, &mut normalize, || ());
2349+
let dst_tail = normalize(dst_tail);
23442350

23452351
// This checks (lifetime part of) vtable validity for pointer casts,
23462352
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).
Lines changed: 21 additions & 0 deletions
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)