diff options
| author | Maybe Lapkin <waffle.lapkin@gmail.com> | 2024-06-23 19:55:17 +0200 |
|---|---|---|
| committer | Maybe Lapkin <waffle.lapkin@gmail.com> | 2024-07-04 17:57:29 +0200 |
| commit | 340d69be12ffc03709340ec2d342db32406cd25f (patch) | |
| tree | d63bc4b06c1e16d26458338af9b626cb4bd1a669 /compiler/rustc_borrowck | |
| parent | c7435571ad725791494c32a48be1cd2c027af30b (diff) | |
| download | rust-340d69be12ffc03709340ec2d342db32406cd25f.tar.gz rust-340d69be12ffc03709340ec2d342db32406cd25f.zip | |
Align the changes to the lang decision
Diffstat (limited to 'compiler/rustc_borrowck')
| -rw-r--r-- | compiler/rustc_borrowck/src/type_check/mod.rs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 2600c1fbff7..f98ac80a4c9 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -2323,27 +2323,48 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let src_tail = tcx.struct_tail_without_normalization(src.ty); let dst_tail = tcx.struct_tail_without_normalization(dst.ty); - if let ty::Dynamic(..) = src_tail.kind() + if let ty::Dynamic(src_tty, ..) = src_tail.kind() && let ty::Dynamic(dst_tty, ..) = dst_tail.kind() + && src_tty.principal().is_some() && dst_tty.principal().is_some() { - // Erase trait object lifetimes, to allow casts like `*mut dyn FnOnce()` -> `*mut dyn FnOnce() + 'static`. - let src_tail = - erase_single_trait_object_lifetime(tcx, src_tail); - let dst_tail = - erase_single_trait_object_lifetime(tcx, dst_tail); + // Erase trait object lifetimes, to allow casts like `*mut dyn FnOnce()` -> `*mut dyn FnOnce() + 'static` + // and remove auto traits. + let src_obj = tcx.mk_ty_from_kind(ty::Dynamic( + tcx.mk_poly_existential_predicates( + &src_tty.without_auto_traits().collect::<Vec<_>>(), + ), + tcx.lifetimes.re_erased, + ty::Dyn, + )); + let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic( + tcx.mk_poly_existential_predicates( + &dst_tty.without_auto_traits().collect::<Vec<_>>(), + ), + tcx.lifetimes.re_erased, + ty::Dyn, + )); + + // FIXME: + // this currently does nothing, but once we make `ptr_cast_add_auto_to_object` + // into a hard error, we can remove the above removal of auto traits and only + // keep this. + let src_obj = erase_single_trait_object_lifetime(tcx, src_obj); + let dst_obj = erase_single_trait_object_lifetime(tcx, dst_obj); let trait_ref = ty::TraitRef::new( tcx, tcx.require_lang_item(LangItem::Unsize, Some(span)), - [src_tail, dst_tail], + [src_obj, dst_obj], ); + debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj); + self.prove_trait_ref( trait_ref, location.to_locations(), ConstraintCategory::Cast { - unsize_to: Some(tcx.fold_regions(dst_tail, |r, _| { + unsize_to: Some(tcx.fold_regions(dst_obj, |r, _| { if let ty::ReVar(_) = r.kind() { tcx.lifetimes.re_erased } else { |
