Overhaul RegionKind
and Region
.
Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned<RegionKind>); ``` 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.
This commit is contained in:
parent
925ec0d3c7
commit
7024dc523a
80 changed files with 443 additions and 346 deletions
|
@ -451,7 +451,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
|||
fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> {
|
||||
use rustc_middle::ty::RegionKind::*;
|
||||
|
||||
match self {
|
||||
match *self {
|
||||
ReEarlyBound(_) => {
|
||||
panic!("Should have already been substituted.");
|
||||
}
|
||||
|
@ -915,8 +915,8 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match r {
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
|
||||
match *r {
|
||||
ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
|
||||
ty::BoundRegionKind::BrNamed(def_id, _name) => {
|
||||
if !self.named_parameters.iter().any(|d| *d == def_id) {
|
||||
self.named_parameters.push(def_id);
|
||||
|
@ -977,12 +977,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||
match r {
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
|
||||
match *r {
|
||||
ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
|
||||
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
|
||||
Some(idx) => {
|
||||
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
|
||||
return self.tcx.mk_region(RegionKind::ReLateBound(*index, new_br));
|
||||
return self.tcx.mk_region(RegionKind::ReLateBound(index, new_br));
|
||||
}
|
||||
None => panic!("Missing `BrNamed`."),
|
||||
},
|
||||
|
@ -1054,7 +1054,7 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
|
|||
}
|
||||
|
||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||
match r {
|
||||
match *r {
|
||||
// FIXME(chalk) - jackh726 - this currently isn't hit in any tests,
|
||||
// since canonicalization will already change these to canonical
|
||||
// variables (ty::ReLateBound).
|
||||
|
@ -1144,7 +1144,7 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
|
|||
}
|
||||
|
||||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match r {
|
||||
match *r {
|
||||
ty::RePlaceholder(p) if p.universe == self.universe_index => {
|
||||
if let ty::BoundRegionKind::BrAnon(anon) = p.name {
|
||||
self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue