1
Fork 0

Remove unnecessary RegionKind:: quals.

The variant names are exported, so we can use them directly (possibly
with a `ty::` qualifier). Lots of places already do this, this commit
just increases consistency.
This commit is contained in:
Nicholas Nethercote 2022-02-01 12:57:04 +11:00
parent 7024dc523a
commit 7eb15509ce
10 changed files with 56 additions and 71 deletions

View file

@ -106,7 +106,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
// verifying these bounds. // verifying these bounds.
if t1.has_placeholders() { if t1.has_placeholders() {
t1 = tcx.fold_regions(t1, &mut false, |r, _| match *r { t1 = tcx.fold_regions(t1, &mut false, |r, _| match *r {
ty::RegionKind::RePlaceholder(placeholder) => { ty::RePlaceholder(placeholder) => {
self.constraints.placeholder_region(self.infcx, placeholder) self.constraints.placeholder_region(self.infcx, placeholder)
} }
_ => r, _ => r,

View file

@ -428,7 +428,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
} }
GenericArgKind::Lifetime(result_value) => { GenericArgKind::Lifetime(result_value) => {
// e.g., here `result_value` might be `'?1` in the example above... // e.g., here `result_value` might be `'?1` in the example above...
if let ty::RegionKind::ReLateBound(debruijn, br) = *result_value { if let ty::ReLateBound(debruijn, br) = *result_value {
// ... in which case we would set `canonical_vars[0]` to `Some('static)`. // ... in which case we would set `canonical_vars[0]` to `Some('static)`.
// We only allow a `ty::INNERMOST` index in substitutions. // We only allow a `ty::INNERMOST` index in substitutions.

View file

@ -937,9 +937,9 @@ impl<'tcx> CommonLifetimes<'tcx> {
}; };
CommonLifetimes { CommonLifetimes {
re_root_empty: mk(RegionKind::ReEmpty(ty::UniverseIndex::ROOT)), re_root_empty: mk(ty::ReEmpty(ty::UniverseIndex::ROOT)),
re_static: mk(RegionKind::ReStatic), re_static: mk(ty::ReStatic),
re_erased: mk(RegionKind::ReErased), re_erased: mk(ty::ReErased),
} }
} }
} }

View file

@ -1685,14 +1685,14 @@ impl<'tcx> Region<'tcx> {
/// Is this region named by the user? /// Is this region named by the user?
pub fn has_name(self) -> bool { pub fn has_name(self) -> bool {
match *self { match *self {
RegionKind::ReEarlyBound(ebr) => ebr.has_name(), ty::ReEarlyBound(ebr) => ebr.has_name(),
RegionKind::ReLateBound(_, br) => br.kind.is_named(), ty::ReLateBound(_, br) => br.kind.is_named(),
RegionKind::ReFree(fr) => fr.bound_region.is_named(), ty::ReFree(fr) => fr.bound_region.is_named(),
RegionKind::ReStatic => true, ty::ReStatic => true,
RegionKind::ReVar(..) => false, ty::ReVar(..) => false,
RegionKind::RePlaceholder(placeholder) => placeholder.name.is_named(), ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
RegionKind::ReEmpty(_) => false, ty::ReEmpty(_) => false,
RegionKind::ReErased => false, ty::ReErased => false,
} }
} }

View file

@ -440,13 +440,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
match (*new_region, *old_region) { match (*new_region, *old_region) {
// If both predicates have an `ReLateBound` (a HRTB) in the // If both predicates have an `ReLateBound` (a HRTB) in the
// same spot, we do nothing. // same spot, we do nothing.
( (ty::ReLateBound(_, _), ty::ReLateBound(_, _)) => {}
ty::RegionKind::ReLateBound(_, _),
ty::RegionKind::ReLateBound(_, _),
) => {}
(ty::RegionKind::ReLateBound(_, _), _) (ty::ReLateBound(_, _), _) | (_, ty::ReVar(_)) => {
| (_, ty::RegionKind::ReVar(_)) => {
// One of these is true: // One of these is true:
// The new predicate has a HRTB in a spot where the old // The new predicate has a HRTB in a spot where the old
// predicate does not (if they both had a HRTB, the previous // predicate does not (if they both had a HRTB, the previous
@ -472,8 +468,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// `user_computed_preds`. // `user_computed_preds`.
return false; return false;
} }
(_, ty::RegionKind::ReLateBound(_, _)) (_, ty::ReLateBound(_, _)) | (ty::ReVar(_), _) => {
| (ty::RegionKind::ReVar(_), _) => {
// This is the opposite situation as the previous arm. // This is the opposite situation as the previous arm.
// One of these is true: // One of these is true:
// //

View file

@ -711,7 +711,7 @@ fn bound_vars_for_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx
var: ty::BoundVar::from_usize(substs.len()), var: ty::BoundVar::from_usize(substs.len()),
kind: ty::BrAnon(substs.len() as u32), kind: ty::BrAnon(substs.len() as u32),
}; };
tcx.mk_region(ty::RegionKind::ReLateBound(ty::INNERMOST, br)).into() tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
} }
ty::GenericParamDefKind::Const { .. } => tcx ty::GenericParamDefKind::Const { .. } => tcx

View file

@ -35,7 +35,7 @@ use rustc_ast::ast;
use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner}; use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner};
use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, Binder, Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor}; use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeVisitor};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use chalk_ir::{FnSig, ForeignDefId}; use chalk_ir::{FnSig, ForeignDefId};
@ -449,32 +449,30 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'tcx> { impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'tcx> {
fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> {
use rustc_middle::ty::RegionKind::*;
match *self { match *self {
ReEarlyBound(_) => { ty::ReEarlyBound(_) => {
panic!("Should have already been substituted."); panic!("Should have already been substituted.");
} }
ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new( ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
chalk_ir::DebruijnIndex::new(db.as_u32()), chalk_ir::DebruijnIndex::new(db.as_u32()),
br.var.as_usize(), br.var.as_usize(),
)) ))
.intern(interner), .intern(interner),
ReFree(_) => unimplemented!(), ty::ReFree(_) => unimplemented!(),
ReStatic => chalk_ir::LifetimeData::Static.intern(interner), ty::ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
ReVar(_) => unimplemented!(), ty::ReVar(_) => unimplemented!(),
RePlaceholder(placeholder_region) => { ty::RePlaceholder(placeholder_region) => {
chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex { chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex {
ui: chalk_ir::UniverseIndex { counter: placeholder_region.universe.index() }, ui: chalk_ir::UniverseIndex { counter: placeholder_region.universe.index() },
idx: 0, idx: 0,
}) })
.intern(interner) .intern(interner)
} }
ReEmpty(ui) => { ty::ReEmpty(ui) => {
chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() }) chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() })
.intern(interner) .intern(interner)
} }
ReErased => chalk_ir::LifetimeData::Erased.intern(interner), ty::ReErased => chalk_ir::LifetimeData::Erased.intern(interner),
} }
} }
} }
@ -482,7 +480,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> { impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> {
fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
let kind = match self.data(interner) { let kind = match self.data(interner) {
chalk_ir::LifetimeData::BoundVar(var) => ty::RegionKind::ReLateBound( chalk_ir::LifetimeData::BoundVar(var) => ty::ReLateBound(
ty::DebruijnIndex::from_u32(var.debruijn.depth()), ty::DebruijnIndex::from_u32(var.debruijn.depth()),
ty::BoundRegion { ty::BoundRegion {
var: ty::BoundVar::from_usize(var.index), var: ty::BoundVar::from_usize(var.index),
@ -490,12 +488,10 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
}, },
), ),
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(), chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
chalk_ir::LifetimeData::Placeholder(p) => { chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder {
ty::RegionKind::RePlaceholder(ty::Placeholder { universe: ty::UniverseIndex::from_usize(p.ui.counter),
universe: ty::UniverseIndex::from_usize(p.ui.counter), name: ty::BoundRegionKind::BrAnon(p.idx as u32),
name: ty::BoundRegionKind::BrAnon(p.idx as u32), }),
})
}
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static, chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
chalk_ir::LifetimeData::Empty(ui) => { chalk_ir::LifetimeData::Empty(ui) => {
ty::ReEmpty(ty::UniverseIndex::from_usize(ui.counter)) ty::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
@ -982,7 +978,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) { ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
Some(idx) => { Some(idx) => {
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*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(ty::ReLateBound(index, new_br));
} }
None => panic!("Missing `BrNamed`."), None => panic!("Missing `BrNamed`."),
}, },
@ -1064,14 +1060,14 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
var: ty::BoundVar::from_u32(*idx), var: ty::BoundVar::from_u32(*idx),
kind: ty::BrAnon(*idx), kind: ty::BrAnon(*idx),
}; };
self.tcx.mk_region(RegionKind::ReLateBound(self.binder_index, br)) self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
} }
None => { None => {
let idx = self.named_regions.len() as u32; let idx = self.named_regions.len() as u32;
let br = let br =
ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(idx) }; ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(idx) };
self.named_regions.insert(_re.def_id, idx); self.named_regions.insert(_re.def_id, idx);
self.tcx.mk_region(RegionKind::ReLateBound(self.binder_index, br)) self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
} }
}, },

View file

@ -416,7 +416,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
let tcx = self.fcx.tcx; let tcx = self.fcx.tcx;
let ref_ty = tcx.mk_ref( let ref_ty = tcx.mk_ref(
// Use `ReErased` as `resolve_interior` is going to replace all the regions anyway. // Use `ReErased` as `resolve_interior` is going to replace all the regions anyway.
tcx.mk_region(ty::RegionKind::ReErased), tcx.mk_region(ty::ReErased),
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
); );
self.record( self.record(

View file

@ -355,12 +355,11 @@ fn check_gat_where_clauses(
// Same for the region. In our example, 'a corresponds // Same for the region. In our example, 'a corresponds
// to the 'me parameter. // to the 'me parameter.
let region_param = generics.param_at(*region_idx, tcx); let region_param = generics.param_at(*region_idx, tcx);
let region_param = let region_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { def_id: region_param.def_id,
def_id: region_param.def_id, index: region_param.index,
index: region_param.index, name: region_param.name,
name: region_param.name, }));
}));
// The predicate we expect to see. (In our example, // The predicate we expect to see. (In our example,
// `Self: 'me`.) // `Self: 'me`.)
let clause = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate( let clause = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
@ -397,20 +396,18 @@ fn check_gat_where_clauses(
debug!("required clause: {} must outlive {}", region_a, region_b); debug!("required clause: {} must outlive {}", region_a, region_b);
// Translate into the generic parameters of the GAT. // Translate into the generic parameters of the GAT.
let region_a_param = generics.param_at(*region_a_idx, tcx); let region_a_param = generics.param_at(*region_a_idx, tcx);
let region_a_param = let region_a_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { def_id: region_a_param.def_id,
def_id: region_a_param.def_id, index: region_a_param.index,
index: region_a_param.index, name: region_a_param.name,
name: region_a_param.name, }));
}));
// Same for the region. // Same for the region.
let region_b_param = generics.param_at(*region_b_idx, tcx); let region_b_param = generics.param_at(*region_b_idx, tcx);
let region_b_param = let region_b_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { def_id: region_b_param.def_id,
def_id: region_b_param.def_id, index: region_b_param.index,
index: region_b_param.index, name: region_b_param.name,
name: region_b_param.name, }));
}));
// The predicate we expect to see. // The predicate we expect to see.
let clause = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate( let clause = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
region_a_param, region_a_param,

View file

@ -1,6 +1,6 @@
use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt}; use rustc_middle::ty::{self, Region, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use smallvec::smallvec; use smallvec::smallvec;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -141,7 +141,7 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
// } // }
// //
// We care about these, so fall through. // We care about these, so fall through.
RegionKind::ReEarlyBound(_) => true, ty::ReEarlyBound(_) => true,
// These correspond to `T: 'static` relationships which can be // These correspond to `T: 'static` relationships which can be
// rather surprising. We are therefore putting this behind a // rather surprising. We are therefore putting this behind a
@ -150,7 +150,7 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
// struct Foo<'a, T> { // struct Foo<'a, T> {
// field: &'static T, // this would generate a ReStatic // field: &'static T, // this would generate a ReStatic
// } // }
RegionKind::ReStatic => tcx.sess.features_untracked().infer_static_outlives_requirements, ty::ReStatic => tcx.sess.features_untracked().infer_static_outlives_requirements,
// Late-bound regions can appear in `fn` types: // Late-bound regions can appear in `fn` types:
// //
@ -160,19 +160,16 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
// //
// The type above might generate a `T: 'b` bound, but we can // The type above might generate a `T: 'b` bound, but we can
// ignore it. We can't put it on the struct header anyway. // ignore it. We can't put it on the struct header anyway.
RegionKind::ReLateBound(..) => false, ty::ReLateBound(..) => false,
// This can appear in `where Self: ` bounds (#64855): // This can appear in `where Self: ` bounds (#64855):
// //
// struct Bar<T>(<Self as Foo>::Type) where Self: ; // struct Bar<T>(<Self as Foo>::Type) where Self: ;
// struct Baz<'a>(&'a Self) where Self: ; // struct Baz<'a>(&'a Self) where Self: ;
RegionKind::ReEmpty(_) => false, ty::ReEmpty(_) => false,
// These regions don't appear in types from type declarations: // These regions don't appear in types from type declarations:
RegionKind::ReErased ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
| RegionKind::ReVar(..)
| RegionKind::RePlaceholder(..)
| RegionKind::ReFree(..) => {
bug!("unexpected region in outlives inference: {:?}", region); bug!("unexpected region in outlives inference: {:?}", region);
} }
} }