Skip to content

Commit

Permalink
Normalize when equating dyn tails in MIR borrowck
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 5, 2024
1 parent 2b78d92 commit c6f8672
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2330,10 +2330,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
match (cast_ty_from, cast_ty_to) {
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
let mut normalize = |t| self.normalize(t, location);

// N.B. `struct_tail_with_normalize` only "structurally resolves"
// the type. It is not fully normalized, so we have to normalize it
// afterwards.
let src_tail =
tcx.struct_tail_with_normalize(src.ty, &mut normalize, || ());
let src_tail = normalize(src_tail);
let dst_tail =
tcx.struct_tail_with_normalize(dst.ty, &mut normalize, || ());
let dst_tail = normalize(dst_tail);

// This checks (lifetime part of) vtable validity for pointer casts,
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).
Expand Down
16 changes: 0 additions & 16 deletions tests/crashes/128621-2.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ known-bug: rust-lang/rust#128621
//@ check-pass

trait Trait {
type Associated;
Expand All @@ -17,3 +17,5 @@ struct Wrap(TraitObject);
fn cast(x: *mut TraitObject) {
x as *mut Wrap;
}

fn main() {}

0 comments on commit c6f8672

Please sign in to comment.