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`
This commit is contained in:
Matthias Krüger 2024-08-05 23:35:23 +02:00 committed by GitHub
commit 77f57cbcac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 17 deletions

View File

@ -2330,10 +2330,16 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
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).

View File

@ -1,16 +0,0 @@
//@ known-bug: rust-lang/rust#128621
#![feature(ptr_metadata)]
use std::{ops::FnMut, ptr::Pointee};
pub type EmplacerFn<'a, T> = dyn for<'b> FnMut(<T as Pointee>::Metadata) + 'a;
pub struct Emplacer<'a, T>(EmplacerFn<'a, T>);
impl<'a, T> Emplacer<'a, T> {
pub unsafe fn from_fn<'b>(emplacer_fn: &'b mut EmplacerFn<'a, T>) -> &'b mut Self {
unsafe { &mut *((emplacer_fn as *mut EmplacerFn<'a, T>) as *mut Self) }
}
}
pub fn main() {}

View File

@ -1,4 +1,4 @@
//@ known-bug: rust-lang/rust#128621
//@ check-pass
trait Trait {
type Associated;
@ -17,3 +17,5 @@ trait Generic<T> {}
fn cast(x: *mut TraitObject) {
x as *mut Wrap;
}
fn main() {}