Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 77f57cb

Browse files
authoredAug 5, 2024
Rollup merge of #128694 - compiler-errors:norm, r=WaffleLapkin
Normalize when equating `dyn` tails in MIR borrowck See the explanation in the comment. Fixes #128621 cc `@WaffleLapkin`
2 parents 83155b3 + c6f8672 commit 77f57cb

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
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).

‎tests/crashes/128621-2.rs

-16
This file was deleted.

‎tests/crashes/128621.rs ‎tests/ui/cast/dyn-tails-need-normalization.rs

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

33
trait Trait {
44
type Associated;
@@ -17,3 +17,5 @@ struct Wrap(TraitObject);
1717
fn cast(x: *mut TraitObject) {
1818
x as *mut Wrap;
1919
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)
Failed to load comments.