Rollup merge of #129969 - GrigorenkoPV:boxed-ty, r=compiler-errors
Make `Ty::boxed_ty` return an `Option`
Looks like a good place to use Rust's type system.
---
Most of 4ac7bcbaad/compiler/rustc_middle/src/ty/sty.rs (L971-L1963)
looks like it could be moved to `TyKind` (then I guess `Ty` should be made to deref to `TyKind`).
This commit is contained in:
commit
0180b8fff0
21 changed files with 58 additions and 48 deletions
|
@ -62,11 +62,13 @@ impl<'tcx, 'a> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'tcx, 'a> {
|
|||
let base_ty = self.local_decls[place.local].ty;
|
||||
|
||||
// Derefer ensures that derefs are always the first projection
|
||||
if place.projection.first() == Some(&PlaceElem::Deref) && base_ty.is_box() {
|
||||
if let Some(PlaceElem::Deref) = place.projection.first()
|
||||
&& let Some(boxed_ty) = base_ty.boxed_ty()
|
||||
{
|
||||
let source_info = self.local_decls[place.local].source_info;
|
||||
|
||||
let (unique_ty, nonnull_ty, ptr_ty) =
|
||||
build_ptr_tys(tcx, base_ty.boxed_ty(), self.unique_did, self.nonnull_did);
|
||||
build_ptr_tys(tcx, boxed_ty, self.unique_did, self.nonnull_did);
|
||||
|
||||
let ptr_local = self.patch.new_temp(ptr_ty, source_info.span);
|
||||
|
||||
|
@ -120,13 +122,15 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs {
|
|||
for (base, elem) in place.iter_projections() {
|
||||
let base_ty = base.ty(&body.local_decls, tcx).ty;
|
||||
|
||||
if elem == PlaceElem::Deref && base_ty.is_box() {
|
||||
if let PlaceElem::Deref = elem
|
||||
&& let Some(boxed_ty) = base_ty.boxed_ty()
|
||||
{
|
||||
// Clone the projections before us, since now we need to mutate them.
|
||||
let new_projections =
|
||||
new_projections.get_or_insert_with(|| base.projection.to_vec());
|
||||
|
||||
let (unique_ty, nonnull_ty, ptr_ty) =
|
||||
build_ptr_tys(tcx, base_ty.boxed_ty(), unique_did, nonnull_did);
|
||||
build_ptr_tys(tcx, boxed_ty, unique_did, nonnull_did);
|
||||
|
||||
new_projections.extend_from_slice(&build_projection(
|
||||
unique_ty, nonnull_ty, ptr_ty,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue