Skip to content

Commit

Permalink
Rollup merge of #128694 - compiler-errors:norm, r=WaffleLapkin
Browse files Browse the repository at this point in the history
Normalize when equating `dyn` tails in MIR borrowck

See the explanation in the comment.

Fixes #128621
cc `@WaffleLapkin`
  • Loading branch information
matthiaskrgr authored Aug 5, 2024
2 parents 83155b3 + c6f8672 commit 77f57cb
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 77f57cb

Please sign in to comment.