From 7024dc523ac712249bb78833dab80c5087e1de36 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Jan 2022 11:25:15 +1100 Subject: Overhaul `RegionKind` and `Region`. Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better. --- compiler/rustc_mir_transform/src/normalize_array_len.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_mir_transform/src') diff --git a/compiler/rustc_mir_transform/src/normalize_array_len.rs b/compiler/rustc_mir_transform/src/normalize_array_len.rs index e4ac57ac925..0392c5a5468 100644 --- a/compiler/rustc_mir_transform/src/normalize_array_len.rs +++ b/compiler/rustc_mir_transform/src/normalize_array_len.rs @@ -3,10 +3,11 @@ use crate::MirPass; use rustc_data_structures::fx::FxIndexMap; +use rustc_data_structures::intern::Interned; use rustc_index::bit_set::BitSet; use rustc_index::vec::IndexVec; use rustc_middle::mir::*; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, ReErased, Region, TyCtxt}; const MAX_NUM_BLOCKS: usize = 800; const MAX_NUM_LOCALS: usize = 3000; @@ -231,11 +232,15 @@ fn normalize_array_len_call<'tcx>( // current way of patching doesn't allow to work with `mut` ( ty::Ref( - ty::RegionKind::ReErased, + Region(Interned(ReErased, _)), operand_ty, Mutability::Not, ), - ty::Ref(ty::RegionKind::ReErased, cast_ty, Mutability::Not), + ty::Ref( + Region(Interned(ReErased, _)), + cast_ty, + Mutability::Not, + ), ) => { match (operand_ty.kind(), cast_ty.kind()) { // current way of patching doesn't allow to work with `mut` -- cgit 1.4.1-3-g733a5