ty::BrK -> ty::BoundRegionKind::K
This commit is contained in:
parent
883f8705d4
commit
d458f850aa
37 changed files with 164 additions and 139 deletions
|
@ -317,7 +317,10 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
|
|||
pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
|
||||
let inner = tcx.fold_regions(ty, |r, depth| match r.kind() {
|
||||
ty::ReVar(vid) => {
|
||||
let br = ty::BoundRegion { var: ty::BoundVar::new(vid.index()), kind: ty::BrAnon };
|
||||
let br = ty::BoundRegion {
|
||||
var: ty::BoundVar::new(vid.index()),
|
||||
kind: ty::BoundRegionKind::Anon,
|
||||
};
|
||||
ty::Region::new_bound(tcx, depth, br)
|
||||
}
|
||||
_ => bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"),
|
||||
|
|
|
@ -1059,7 +1059,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
|
|||
.map(|v| {
|
||||
mk(ty::ReBound(ty::DebruijnIndex::from(i), ty::BoundRegion {
|
||||
var: ty::BoundVar::from(v),
|
||||
kind: ty::BrAnon,
|
||||
kind: ty::BoundRegionKind::Anon,
|
||||
}))
|
||||
})
|
||||
.collect()
|
||||
|
@ -1982,7 +1982,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
region = self.map_opaque_lifetime_to_parent_lifetime(def_id);
|
||||
continue;
|
||||
}
|
||||
break (scope, ty::BrNamed(def_id.into(), self.item_name(def_id.into())));
|
||||
break (
|
||||
scope,
|
||||
ty::BoundRegionKind::Named(def_id.into(), self.item_name(def_id.into())),
|
||||
);
|
||||
};
|
||||
|
||||
let is_impl_item = match self.hir_node_by_def_id(suitable_region_binding_scope) {
|
||||
|
@ -3091,7 +3094,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
return ty::Region::new_late_param(
|
||||
self,
|
||||
new_parent.to_def_id(),
|
||||
ty::BoundRegionKind::BrNamed(
|
||||
ty::BoundRegionKind::Named(
|
||||
lbv.to_def_id(),
|
||||
self.item_name(lbv.to_def_id()),
|
||||
),
|
||||
|
|
|
@ -399,7 +399,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let index = entry.index();
|
||||
let var = ty::BoundVar::from_usize(index);
|
||||
let kind = entry
|
||||
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BrAnon))
|
||||
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon))
|
||||
.expect_region();
|
||||
let br = ty::BoundRegion { var, kind };
|
||||
ty::Region::new_bound(self.tcx, ty::INNERMOST, br)
|
||||
|
|
|
@ -84,7 +84,6 @@ pub use self::predicate::{
|
|||
RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef, TraitPredicate, TraitRef,
|
||||
TypeOutlivesPredicate,
|
||||
};
|
||||
pub use self::region::BoundRegionKind::*;
|
||||
pub use self::region::{
|
||||
BoundRegion, BoundRegionKind, EarlyParamRegion, LateParamRegion, Region, RegionKind, RegionVid,
|
||||
};
|
||||
|
@ -895,7 +894,7 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
|
|||
}
|
||||
|
||||
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: BoundRegion { var, kind: BoundRegionKind::BrAnon } }
|
||||
Placeholder { universe: ui, bound: BoundRegion { var, kind: BoundRegionKind::Anon } }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2483,7 +2483,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
| ty::RePlaceholder(ty::Placeholder {
|
||||
bound: ty::BoundRegion { kind: br, .. }, ..
|
||||
}) => {
|
||||
if let ty::BrNamed(_, name) = br
|
||||
if let ty::BoundRegionKind::Named(_, name) = br
|
||||
&& br.is_named()
|
||||
{
|
||||
p!(write("{}", name));
|
||||
|
@ -2569,7 +2569,7 @@ impl<'a, 'tcx> ty::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
|
|||
// If this is an anonymous placeholder, don't rename. Otherwise, in some
|
||||
// async fns, we get a `for<'r> Send` bound
|
||||
match kind {
|
||||
ty::BrAnon | ty::BrEnv => r,
|
||||
ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => r,
|
||||
_ => {
|
||||
// Index doesn't matter, since this is just for naming and these never get bound
|
||||
let br = ty::BoundRegion { var: ty::BoundVar::ZERO, kind };
|
||||
|
@ -2688,12 +2688,13 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
binder_level_idx: ty::DebruijnIndex,
|
||||
br: ty::BoundRegion| {
|
||||
let (name, kind) = match br.kind {
|
||||
ty::BrAnon | ty::BrEnv => {
|
||||
ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => {
|
||||
let name = next_name(self);
|
||||
|
||||
if let Some(lt_idx) = lifetime_idx {
|
||||
if lt_idx > binder_level_idx {
|
||||
let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name);
|
||||
let kind =
|
||||
ty::BoundRegionKind::Named(CRATE_DEF_ID.to_def_id(), name);
|
||||
return ty::Region::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
|
@ -2702,14 +2703,14 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
(name, ty::BrNamed(CRATE_DEF_ID.to_def_id(), name))
|
||||
(name, ty::BoundRegionKind::Named(CRATE_DEF_ID.to_def_id(), name))
|
||||
}
|
||||
ty::BrNamed(def_id, kw::UnderscoreLifetime | kw::Empty) => {
|
||||
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime | kw::Empty) => {
|
||||
let name = next_name(self);
|
||||
|
||||
if let Some(lt_idx) = lifetime_idx {
|
||||
if lt_idx > binder_level_idx {
|
||||
let kind = ty::BrNamed(def_id, name);
|
||||
let kind = ty::BoundRegionKind::Named(def_id, name);
|
||||
return ty::Region::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
|
@ -2718,9 +2719,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
(name, ty::BrNamed(def_id, name))
|
||||
(name, ty::BoundRegionKind::Named(def_id, name))
|
||||
}
|
||||
ty::BrNamed(_, name) => {
|
||||
ty::BoundRegionKind::Named(_, name) => {
|
||||
if let Some(lt_idx) = lifetime_idx {
|
||||
if lt_idx > binder_level_idx {
|
||||
let kind = br.kind;
|
||||
|
|
|
@ -56,7 +56,7 @@ impl<'tcx> Region<'tcx> {
|
|||
bound_region: ty::BoundRegion,
|
||||
) -> Region<'tcx> {
|
||||
// Use a pre-interned one when possible.
|
||||
if let ty::BoundRegion { var, kind: ty::BrAnon } = bound_region
|
||||
if let ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon } = bound_region
|
||||
&& let Some(inner) = tcx.lifetimes.re_late_bounds.get(debruijn.as_usize())
|
||||
&& let Some(re) = inner.get(var.as_usize()).copied()
|
||||
{
|
||||
|
@ -147,7 +147,7 @@ impl<'tcx> rustc_type_ir::inherent::Region<TyCtxt<'tcx>> for Region<'tcx> {
|
|||
}
|
||||
|
||||
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
|
||||
Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon })
|
||||
Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon })
|
||||
}
|
||||
|
||||
fn new_static(tcx: TyCtxt<'tcx>) -> Self {
|
||||
|
@ -311,7 +311,7 @@ impl<'tcx> Region<'tcx> {
|
|||
Some(tcx.generics_of(binding_item).region_param(ebr, tcx).def_id)
|
||||
}
|
||||
ty::ReLateParam(ty::LateParamRegion {
|
||||
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
|
||||
bound_region: ty::BoundRegionKind::Named(def_id, _),
|
||||
..
|
||||
}) => Some(def_id),
|
||||
_ => None,
|
||||
|
@ -355,7 +355,7 @@ impl std::fmt::Debug for EarlyParamRegion {
|
|||
/// Similar to a placeholder region as we create `LateParam` regions when entering a binder
|
||||
/// except they are always in the root universe and instead of using a boundvar to distinguish
|
||||
/// between others we use the `DefId` of the parameter. For this reason the `bound_region` field
|
||||
/// should basically always be `BoundRegionKind::BrNamed` as otherwise there is no way of telling
|
||||
/// should basically always be `BoundRegionKind::Named` as otherwise there is no way of telling
|
||||
/// different parameters apart.
|
||||
pub struct LateParamRegion {
|
||||
pub scope: DefId,
|
||||
|
@ -366,17 +366,17 @@ pub struct LateParamRegion {
|
|||
#[derive(HashStable)]
|
||||
pub enum BoundRegionKind {
|
||||
/// An anonymous region parameter for a given fn (&T)
|
||||
BrAnon,
|
||||
Anon,
|
||||
|
||||
/// Named region parameters for functions (a in &'a T)
|
||||
///
|
||||
/// The `DefId` is needed to distinguish free regions in
|
||||
/// the event of shadowing.
|
||||
BrNamed(DefId, Symbol),
|
||||
Named(DefId, Symbol),
|
||||
|
||||
/// Anonymous region for the implicit env pointer parameter
|
||||
/// to a closure
|
||||
BrEnv,
|
||||
ClosureEnv,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
|
@ -399,9 +399,9 @@ impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundRegion {
|
|||
impl core::fmt::Debug for BoundRegion {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.kind {
|
||||
BoundRegionKind::BrAnon => write!(f, "{:?}", self.var),
|
||||
BoundRegionKind::BrEnv => write!(f, "{:?}.Env", self.var),
|
||||
BoundRegionKind::BrNamed(def, symbol) => {
|
||||
BoundRegionKind::Anon => write!(f, "{:?}", self.var),
|
||||
BoundRegionKind::ClosureEnv => write!(f, "{:?}.Env", self.var),
|
||||
BoundRegionKind::Named(def, symbol) => {
|
||||
write!(f, "{:?}.Named({:?}, {:?})", self.var, def, symbol)
|
||||
}
|
||||
}
|
||||
|
@ -411,9 +411,7 @@ impl core::fmt::Debug for BoundRegion {
|
|||
impl BoundRegionKind {
|
||||
pub fn is_named(&self) -> bool {
|
||||
match *self {
|
||||
BoundRegionKind::BrNamed(_, name) => {
|
||||
name != kw::UnderscoreLifetime && name != kw::Empty
|
||||
}
|
||||
BoundRegionKind::Named(_, name) => name != kw::UnderscoreLifetime && name != kw::Empty,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -421,7 +419,7 @@ impl BoundRegionKind {
|
|||
pub fn get_name(&self) -> Option<Symbol> {
|
||||
if self.is_named() {
|
||||
match *self {
|
||||
BoundRegionKind::BrNamed(_, name) => return Some(name),
|
||||
BoundRegionKind::Named(_, name) => return Some(name),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -431,7 +429,7 @@ impl BoundRegionKind {
|
|||
|
||||
pub fn get_id(&self) -> Option<DefId> {
|
||||
match *self {
|
||||
BoundRegionKind::BrNamed(id, _) => Some(id),
|
||||
BoundRegionKind::Named(id, _) => Some(id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,15 +62,15 @@ impl<'tcx> fmt::Debug for ty::adjustment::Adjustment<'tcx> {
|
|||
impl fmt::Debug for ty::BoundRegionKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::BrAnon => write!(f, "BrAnon"),
|
||||
ty::BrNamed(did, name) => {
|
||||
ty::BoundRegionKind::Anon => write!(f, "BrAnon"),
|
||||
ty::BoundRegionKind::Named(did, name) => {
|
||||
if did.is_crate_root() {
|
||||
write!(f, "BrNamed({name})")
|
||||
} else {
|
||||
write!(f, "BrNamed({did:?}, {name})")
|
||||
}
|
||||
}
|
||||
ty::BrEnv => write!(f, "BrEnv"),
|
||||
ty::BoundRegionKind::ClosureEnv => write!(f, "BrEnv"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -735,8 +735,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let ty = self.fold_regions(decl.ty, |re, debruijn| {
|
||||
assert_eq!(re, self.lifetimes.re_erased);
|
||||
let var = ty::BoundVar::from_usize(vars.len());
|
||||
vars.push(ty::BoundVariableKind::Region(ty::BrAnon));
|
||||
ty::Region::new_bound(self, debruijn, ty::BoundRegion { var, kind: ty::BrAnon })
|
||||
vars.push(ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon));
|
||||
ty::Region::new_bound(self, debruijn, ty::BoundRegion {
|
||||
var,
|
||||
kind: ty::BoundRegionKind::Anon,
|
||||
})
|
||||
});
|
||||
ty::EarlyBinder::bind(ty::Binder::bind_with_vars(
|
||||
ty,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue