1
Fork 0

clean code: remove Deref<Target=RegionKind> impl for Region and use .kind()

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
xizheyin 2025-04-08 10:51:41 +08:00
parent c6c179662d
commit c7272a6cbc
No known key found for this signature in database
GPG key ID: 0A0D90BE99CEDEAD
49 changed files with 107 additions and 118 deletions

View file

@ -487,7 +487,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
let (sub_region, cause) = info?; let (sub_region, cause) = info?;
debug!(?sub_region, "cause = {:#?}", cause); debug!(?sub_region, "cause = {:#?}", cause);
let error = match (error_region, *sub_region) { let error = match (error_region, sub_region.kind()) {
(Some(error_region), ty::ReVar(vid)) => RegionResolutionError::SubSupConflict( (Some(error_region), ty::ReVar(vid)) => RegionResolutionError::SubSupConflict(
vid, vid,
region_var_origin(vid), region_var_origin(vid),

View file

@ -587,7 +587,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// this by hooking into the pretty printer and telling it to label the // this by hooking into the pretty printer and telling it to label the
// lifetimes without names with the value `'0`. // lifetimes without names with the value `'0`.
if let ty::Ref(region, ..) = ty.kind() { if let ty::Ref(region, ..) = ty.kind() {
match **region { match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. }) ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion { | ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. }, bound: ty::BoundRegion { kind: br, .. },
@ -607,7 +607,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS); let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
let region = if let ty::Ref(region, ..) = ty.kind() { let region = if let ty::Ref(region, ..) = ty.kind() {
match **region { match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. }) ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion { | ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. }, bound: ty::BoundRegion { kind: br, .. },

View file

@ -190,7 +190,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
where where
T: TypeFoldable<TyCtxt<'tcx>>, T: TypeFoldable<TyCtxt<'tcx>>,
{ {
fold_regions(tcx, ty, |region, _| match *region { fold_regions(tcx, ty, |region, _| match region.kind() {
ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region), ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region),
_ => region, _ => region,
}) })
@ -198,7 +198,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// Returns `true` if a closure is inferred to be an `FnMut` closure. /// Returns `true` if a closure is inferred to be an `FnMut` closure.
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool { fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref() if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).map(|r| r.kind())
&& let ty::LateParamRegionKind::ClosureEnv = late_param.kind && let ty::LateParamRegionKind::ClosureEnv = late_param.kind
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty && let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
{ {
@ -832,7 +832,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let (Some(f), Some(outlived_f)) = if let (Some(f), Some(outlived_f)) =
(self.to_error_region(fr), self.to_error_region(outlived_fr)) (self.to_error_region(fr), self.to_error_region(outlived_fr))
{ {
if *outlived_f != ty::ReStatic { if outlived_f.kind() != ty::ReStatic {
return; return;
} }
let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f); let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f);

View file

@ -288,7 +288,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
debug!("give_region_a_name: error_region = {:?}", error_region); debug!("give_region_a_name: error_region = {:?}", error_region);
match *error_region { match error_region.kind() {
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| { ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id; let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP); let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
@ -896,7 +896,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
&self, &self,
fr: RegionVid, fr: RegionVid,
) -> Option<RegionName> { ) -> Option<RegionName> {
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else { let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
return None; return None;
}; };
if region.has_name() { if region.has_name() {
@ -912,7 +912,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let found = tcx let found = tcx
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| { .any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
*r == ty::ReEarlyParam(region) r.kind() == ty::ReEarlyParam(region)
}); });
Some(RegionName { Some(RegionName {
@ -931,7 +931,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
&self, &self,
fr: RegionVid, fr: RegionVid,
) -> Option<RegionName> { ) -> Option<RegionName> {
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else { let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
return None; return None;
}; };
if region.has_name() { if region.has_name() {
@ -1007,7 +1007,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
if data.projection_term.self_ty() == ty => {} if data.projection_term.self_ty() == ty => {}
_ => return false, _ => return false,
} }
tcx.any_free_region_meets(pred, |r| *r == ty::ReEarlyParam(region)) tcx.any_free_region_meets(pred, |r| r.kind() == ty::ReEarlyParam(region))
}) })
} else { } else {
false false

View file

@ -186,7 +186,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
where where
T: TypeFoldable<TyCtxt<'tcx>>, T: TypeFoldable<TyCtxt<'tcx>>,
{ {
fold_regions(tcx, ty, |region, _| match *region { fold_regions(tcx, ty, |region, _| match region.kind() {
ty::ReVar(vid) => { ty::ReVar(vid) => {
let scc = self.constraint_sccs.scc(vid); let scc = self.constraint_sccs.scc(vid);

View file

@ -205,7 +205,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
/// are dealt with during trait solving. /// are dealt with during trait solving.
fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T { fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
if value.has_placeholders() { if value.has_placeholders() {
fold_regions(self.tcx, value, |r, _| match *r { fold_regions(self.tcx, value, |r, _| match r.kind() {
ty::RePlaceholder(placeholder) => { ty::RePlaceholder(placeholder) => {
self.constraints.placeholder_region(self.infcx, placeholder) self.constraints.placeholder_region(self.infcx, placeholder)
} }
@ -227,7 +227,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
} }
fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid { fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
if let ty::RePlaceholder(placeholder) = *r { if let ty::RePlaceholder(placeholder) = r.kind() {
self.constraints.placeholder_region(self.infcx, placeholder).as_var() self.constraints.placeholder_region(self.infcx, placeholder).as_var()
} else { } else {
self.universal_regions.to_region_vid(r) self.universal_regions.to_region_vid(r)

View file

@ -271,7 +271,7 @@ where
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
match *r { match r.kind() {
// ignore bound regions, keep visiting // ignore bound regions, keep visiting
ty::ReBound(_, _) => {} ty::ReBound(_, _) => {}
_ => (self.op)(r), _ => (self.op)(r),

View file

@ -909,9 +909,9 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
/// if it is a placeholder. Handling placeholders requires access to the /// if it is a placeholder. Handling placeholders requires access to the
/// `MirTypeckRegionConstraints`. /// `MirTypeckRegionConstraints`.
fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
if let ty::ReVar(..) = *r { if let ty::ReVar(..) = r.kind() {
r.as_var() r.as_var()
} else if let ty::ReError(guar) = *r { } else if let ty::ReError(guar) = r.kind() {
self.tainted_by_errors.set(Some(guar)); self.tainted_by_errors.set(Some(guar));
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the // We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if // `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if

View file

@ -442,7 +442,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
if let ty::ReLateParam(fr) = *r { if let ty::ReLateParam(fr) = r.kind() {
ty::Region::new_late_param( ty::Region::new_late_param(
self.tcx, self.tcx,
fr.scope, fr.scope,

View file

@ -631,7 +631,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Ignore `'static` lifetimes for the purpose of this lint: it's // Ignore `'static` lifetimes for the purpose of this lint: it's
// because we know it outlives everything and so doesn't give meaningful // because we know it outlives everything and so doesn't give meaningful
// clues. Also ignore `ReError`, to avoid knock-down errors. // clues. Also ignore `ReError`, to avoid knock-down errors.
if let ty::ReStatic | ty::ReError(_) = **region_a { if let ty::ReStatic | ty::ReError(_) = region_a.kind() {
continue; continue;
} }
// For each region argument (e.g., `'a` in our example), check for a // For each region argument (e.g., `'a` in our example), check for a
@ -672,7 +672,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Again, skip `'static` because it outlives everything. Also, we trivially // Again, skip `'static` because it outlives everything. Also, we trivially
// know that a region outlives itself. Also ignore `ReError`, to avoid // know that a region outlives itself. Also ignore `ReError`, to avoid
// knock-down errors. // knock-down errors.
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b { if matches!(region_b.kind(), ty::ReStatic | ty::ReError(_)) || region_a == region_b {
continue; continue;
} }
if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) { if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) {

View file

@ -656,7 +656,7 @@ fn infringing_fields_error<'tcx>(
.entry((ty.clone(), predicate.clone())) .entry((ty.clone(), predicate.clone()))
.or_default() .or_default()
.push(origin.span()); .push(origin.span());
if let ty::RegionKind::ReEarlyParam(ebr) = *b if let ty::RegionKind::ReEarlyParam(ebr) = b.kind()
&& ebr.has_name() && ebr.has_name()
{ {
bounds.push((b.to_string(), a.to_string(), None)); bounds.push((b.to_string(), a.to_string(), None));

View file

@ -1416,7 +1416,7 @@ fn recover_infer_ret_ty<'tcx>(
GenericParamKind::Lifetime { .. } => true, GenericParamKind::Lifetime { .. } => true,
_ => false, _ => false,
}); });
let fn_sig = fold_regions(tcx, fn_sig, |r, _| match *r { let fn_sig = fold_regions(tcx, fn_sig, |r, _| match r.kind() {
ty::ReErased => { ty::ReErased => {
if has_region_params { if has_region_params {
ty::Region::new_error_with_message( ty::Region::new_error_with_message(

View file

@ -359,7 +359,7 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
) { ) {
for param in opaque_own_params { for param in opaque_own_params {
let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local()); let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
if let ty::ReEarlyParam(..) = *orig_lifetime { if let ty::ReEarlyParam(..) = orig_lifetime.kind() {
let dup_lifetime = ty::Region::new_early_param( let dup_lifetime = ty::Region::new_early_param(
tcx, tcx,
ty::EarlyParamRegion { index: param.index, name: param.name }, ty::EarlyParamRegion { index: param.index, name: param.name },

View file

@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
if let ty::ReEarlyParam(data) = *r { if let ty::ReEarlyParam(data) = r.kind() {
self.parameters.push(Parameter::from(data)); self.parameters.push(Parameter::from(data));
} }
} }

View file

@ -146,7 +146,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
fn is_free_region(region: Region<'_>) -> bool { fn is_free_region(region: Region<'_>) -> bool {
// First, screen for regions that might appear in a type header. // First, screen for regions that might appear in a type header.
match *region { match region.kind() {
// These correspond to `T: 'a` relationships: // These correspond to `T: 'a` relationships:
// //
// struct Foo<'a, T> { // struct Foo<'a, T> {

View file

@ -428,7 +428,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
variance: VarianceTermPtr<'a>, variance: VarianceTermPtr<'a>,
) { ) {
match *region { match region.kind() {
ty::ReEarlyParam(ref data) => { ty::ReEarlyParam(ref data) => {
self.add_constraint(current, data.index, variance); self.add_constraint(current, data.index, variance);
} }

View file

@ -159,7 +159,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
) -> ty::Region<'tcx> { ) -> ty::Region<'tcx> {
let infcx = canonicalizer.infcx.unwrap(); let infcx = canonicalizer.infcx.unwrap();
if let ty::ReVar(vid) = *r { if let ty::ReVar(vid) = r.kind() {
r = infcx r = infcx
.inner .inner
.borrow_mut() .borrow_mut()
@ -171,7 +171,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
); );
}; };
match *r { match r.kind() {
ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r, ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r,
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region( ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
@ -227,7 +227,7 @@ impl CanonicalizeMode for CanonicalizeUserTypeAnnotation {
canonicalizer: &mut Canonicalizer<'_, 'tcx>, canonicalizer: &mut Canonicalizer<'_, 'tcx>,
r: ty::Region<'tcx>, r: ty::Region<'tcx>,
) -> ty::Region<'tcx> { ) -> ty::Region<'tcx> {
match *r { match r.kind() {
ty::ReEarlyParam(_) ty::ReEarlyParam(_)
| ty::ReLateParam(_) | ty::ReLateParam(_)
| ty::ReErased | ty::ReErased
@ -321,7 +321,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { match r.kind() {
ty::ReBound(index, ..) => { ty::ReBound(index, ..) => {
if index >= self.binder_index { if index >= self.binder_index {
bug!("escaping late-bound region during canonicalization"); bug!("escaping late-bound region during canonicalization");

View file

@ -432,7 +432,7 @@ impl<'tcx> InferCtxt<'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::ReBound(debruijn, br) = *result_value { if let ty::ReBound(debruijn, br) = result_value.kind() {
// ... 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 generic parameters. // We only allow a `ty::INNERMOST` index in generic parameters.

View file

@ -109,7 +109,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { match r.kind() {
ty::ReBound(..) => { ty::ReBound(..) => {
// leave bound regions alone // leave bound regions alone
r r

View file

@ -218,7 +218,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
true true
} }
VarValue::Value(cur_region) => { VarValue::Value(cur_region) => {
match *cur_region { match cur_region.kind() {
// If this empty region is from a universe that can name the // If this empty region is from a universe that can name the
// placeholder universe, then the LUB is the Placeholder region // placeholder universe, then the LUB is the Placeholder region
// (which is the cur_region). Otherwise, the LUB is the Static // (which is the cur_region). Otherwise, the LUB is the Static
@ -310,7 +310,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
match *b_data { match *b_data {
VarValue::Empty(empty_ui) => { VarValue::Empty(empty_ui) => {
let lub = match *a_region { let lub = match a_region.kind() {
RePlaceholder(placeholder) => { RePlaceholder(placeholder) => {
// If this empty region is from a universe that can // If this empty region is from a universe that can
// name the placeholder, then the placeholder is // name the placeholder, then the placeholder is
@ -350,7 +350,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
// tighter bound than `'static`. // tighter bound than `'static`.
// //
// (This might e.g. arise from being asked to prove `for<'a> { 'b: 'a }`.) // (This might e.g. arise from being asked to prove `for<'a> { 'b: 'a }`.)
if let ty::RePlaceholder(p) = *lub if let ty::RePlaceholder(p) = lub.kind()
&& b_universe.cannot_name(p.universe) && b_universe.cannot_name(p.universe)
{ {
lub = self.tcx().lifetimes.re_static; lub = self.tcx().lifetimes.re_static;
@ -377,7 +377,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
a_ui.min(b_ui) == b_ui a_ui.min(b_ui) == b_ui
} }
(VarValue::Value(a), VarValue::Empty(_)) => { (VarValue::Value(a), VarValue::Empty(_)) => {
match *a { match a.kind() {
// this is always on an error path, // this is always on an error path,
// so it doesn't really matter if it's shorter or longer than an empty region // so it doesn't really matter if it's shorter or longer than an empty region
ReError(_) => false, ReError(_) => false,
@ -410,7 +410,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
} }
} }
(VarValue::Empty(a_ui), VarValue::Value(b)) => { (VarValue::Empty(a_ui), VarValue::Value(b)) => {
match *b { match b.kind() {
// this is always on an error path, // this is always on an error path,
// so it doesn't really matter if it's shorter or longer than an empty region // so it doesn't really matter if it's shorter or longer than an empty region
ReError(_) => false, ReError(_) => false,
@ -479,7 +479,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
/// term "concrete regions"). /// term "concrete regions").
#[instrument(level = "trace", skip(self), ret)] #[instrument(level = "trace", skip(self), ret)]
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> { fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
match (*a, *b) { match (a.kind(), b.kind()) {
(ReBound(..), _) | (_, ReBound(..)) | (ReErased, _) | (_, ReErased) => { (ReBound(..), _) | (_, ReBound(..)) | (ReErased, _) | (_, ReErased) => {
bug!("cannot relate region: LUB({:?}, {:?})", a, b); bug!("cannot relate region: LUB({:?}, {:?})", a, b);
} }
@ -725,7 +725,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
// SubSupConflict(ReLateParam, ReLateParam) when reporting error, and so // SubSupConflict(ReLateParam, ReLateParam) when reporting error, and so
// the user will more likely get a specific suggestion. // the user will more likely get a specific suggestion.
fn region_order_key(x: &RegionAndOrigin<'_>) -> u8 { fn region_order_key(x: &RegionAndOrigin<'_>) -> u8 {
match *x.region { match x.region.kind() {
ReEarlyParam(_) => 0, ReEarlyParam(_) => 0,
ReLateParam(_) => 1, ReLateParam(_) => 1,
_ => 2, _ => 2,
@ -737,7 +737,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
let node_universe = self.var_infos[node_idx].universe; let node_universe = self.var_infos[node_idx].universe;
for lower_bound in &lower_bounds { for lower_bound in &lower_bounds {
let effective_lower_bound = if let ty::RePlaceholder(p) = *lower_bound.region { let effective_lower_bound = if let ty::RePlaceholder(p) = lower_bound.region.kind() {
if node_universe.cannot_name(p.universe) { if node_universe.cannot_name(p.universe) {
self.tcx().lifetimes.re_static self.tcx().lifetimes.re_static
} else { } else {
@ -785,7 +785,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
.expect("lower_vid_bounds should at least include `node_idx`"); .expect("lower_vid_bounds should at least include `node_idx`");
for upper_bound in &upper_bounds { for upper_bound in &upper_bounds {
if let ty::RePlaceholder(p) = *upper_bound.region { if let ty::RePlaceholder(p) = upper_bound.region.kind() {
if min_universe.cannot_name(p.universe) { if min_universe.cannot_name(p.universe) {
let origin = self.var_infos[node_idx].origin; let origin = self.var_infos[node_idx].origin;
errors.push(RegionResolutionError::UpperBoundUniverseConflict( errors.push(RegionResolutionError::UpperBoundUniverseConflict(
@ -913,7 +913,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
generic_ty: Ty<'tcx>, generic_ty: Ty<'tcx>,
min: ty::Region<'tcx>, min: ty::Region<'tcx>,
) -> bool { ) -> bool {
if let ty::ReError(_) = *min { if let ty::ReError(_) = min.kind() {
return true; return true;
} }
@ -931,18 +931,18 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
} }
VerifyBound::OutlivedBy(r) => { VerifyBound::OutlivedBy(r) => {
let a = match *min { let a = match min.kind() {
ty::ReVar(rid) => var_values.values[rid], ty::ReVar(rid) => var_values.values[rid],
_ => VarValue::Value(min), _ => VarValue::Value(min),
}; };
let b = match **r { let b = match r.kind() {
ty::ReVar(rid) => var_values.values[rid], ty::ReVar(rid) => var_values.values[rid],
_ => VarValue::Value(*r), _ => VarValue::Value(*r),
}; };
self.sub_region_values(a, b) self.sub_region_values(a, b)
} }
VerifyBound::IsEmpty => match *min { VerifyBound::IsEmpty => match min.kind() {
ty::ReVar(rid) => match var_values.values[rid] { ty::ReVar(rid) => match var_values.values[rid] {
VarValue::ErrorValue => false, VarValue::ErrorValue => false,
VarValue::Empty(_) => true, VarValue::Empty(_) => true,
@ -989,7 +989,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
r: ty::Region<'tcx>, r: ty::Region<'tcx>,
) -> ty::Region<'tcx> { ) -> ty::Region<'tcx> {
let result = match *r { let result = match r.kind() {
ty::ReVar(rid) => match self.values[rid] { ty::ReVar(rid) => match self.values[rid] {
VarValue::Empty(_) => r, VarValue::Empty(_) => r,
VarValue::Value(r) => r, VarValue::Value(r) => r,

View file

@ -69,7 +69,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
region_bound_pairs region_bound_pairs
.insert(ty::OutlivesPredicate(GenericKind::Alias(alias_b), r_a)); .insert(ty::OutlivesPredicate(GenericKind::Alias(alias_b), r_a));
} }
OutlivesBound::RegionSubRegion(r_a, r_b) => match (*r_a, *r_b) { OutlivesBound::RegionSubRegion(r_a, r_b) => match (r_a.kind(), r_b.kind()) {
( (
ty::ReStatic | ty::ReEarlyParam(_) | ty::ReLateParam(_), ty::ReStatic | ty::ReEarlyParam(_) | ty::ReLateParam(_),
ty::ReStatic | ty::ReEarlyParam(_) | ty::ReLateParam(_), ty::ReStatic | ty::ReEarlyParam(_) | ty::ReLateParam(_),

View file

@ -29,7 +29,7 @@ where
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
match *r { match r.kind() {
// ignore bound regions, keep visiting // ignore bound regions, keep visiting
ty::ReBound(_, _) => {} ty::ReBound(_, _) => {}
_ => (self.op)(r), _ => (self.op)(r),

View file

@ -155,7 +155,7 @@ impl<'a, 'tcx> LeakCheck<'a, 'tcx> {
self.scc_universes[scc].take_min(universe, *region); self.scc_universes[scc].take_min(universe, *region);
// Detect those SCCs that directly contain a placeholder // Detect those SCCs that directly contain a placeholder
if let ty::RePlaceholder(placeholder) = **region { if let ty::RePlaceholder(placeholder) = region.kind() {
if self.outer_universe.cannot_name(placeholder.universe) { if self.outer_universe.cannot_name(placeholder.universe) {
// Update `scc_placeholders` to account for the fact that `P: S` must hold. // Update `scc_placeholders` to account for the fact that `P: S` must hold.
match self.scc_placeholders[scc] { match self.scc_placeholders[scc] {

View file

@ -463,7 +463,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
// cannot add constraints once regions are resolved // cannot add constraints once regions are resolved
debug!("origin = {:#?}", origin); debug!("origin = {:#?}", origin);
match (*sub, *sup) { match (sub.kind(), sup.kind()) {
(ReBound(..), _) | (_, ReBound(..)) => { (ReBound(..), _) | (_, ReBound(..)) => {
span_bug!(origin.span(), "cannot relate bound region: {:?} <= {:?}", sub, sup); span_bug!(origin.span(), "cannot relate bound region: {:?} <= {:?}", sub, sup);
} }
@ -595,7 +595,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
} }
pub fn universe(&mut self, region: Region<'tcx>) -> ty::UniverseIndex { pub fn universe(&mut self, region: Region<'tcx>) -> ty::UniverseIndex {
match *region { match region.kind() {
ty::ReStatic ty::ReStatic
| ty::ReErased | ty::ReErased
| ty::ReLateParam(..) | ty::ReLateParam(..)

View file

@ -571,7 +571,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
) -> RelateResult<'tcx, ty::Region<'tcx>> { ) -> RelateResult<'tcx, ty::Region<'tcx>> {
assert_eq!(r, r2); // we are misusing TypeRelation here; both LHS and RHS ought to be == assert_eq!(r, r2); // we are misusing TypeRelation here; both LHS and RHS ought to be ==
match *r { match r.kind() {
// Never make variables for regions bound within the type itself, // Never make variables for regions bound within the type itself,
// nor for erased regions. // nor for erased regions.
ty::ReBound(..) | ty::ReErased => { ty::ReBound(..) | ty::ReErased => {

View file

@ -89,7 +89,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticRegionResolver<'a, 'tcx
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { match r.kind() {
ty::ReVar(vid) => self ty::ReVar(vid) => self
.infcx .infcx
.inner .inner
@ -153,7 +153,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
} }
fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> { fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
match *r { match r.kind() {
ty::ReVar(_) => Ok(self ty::ReVar(_) => Ok(self
.infcx .infcx
.lexical_region_resolutions .lexical_region_resolutions

View file

@ -1988,7 +1988,7 @@ impl ExplicitOutlivesRequirements {
inferred_outlives inferred_outlives
.filter_map(|(clause, _)| match clause.kind().skip_binder() { .filter_map(|(clause, _)| match clause.kind().skip_binder() {
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a { ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match a.kind() {
ty::ReEarlyParam(ebr) ty::ReEarlyParam(ebr)
if item_generics.region_param(ebr, tcx).def_id == lifetime.to_def_id() => if item_generics.region_param(ebr, tcx).def_id == lifetime.to_def_id() =>
{ {
@ -2038,7 +2038,7 @@ impl ExplicitOutlivesRequirements {
let is_inferred = match tcx.named_bound_var(lifetime.hir_id) { let is_inferred = match tcx.named_bound_var(lifetime.hir_id) {
Some(ResolvedArg::EarlyBound(def_id)) => inferred_outlives Some(ResolvedArg::EarlyBound(def_id)) => inferred_outlives
.iter() .iter()
.any(|r| matches!(**r, ty::ReEarlyParam(ebr) if { item_generics.region_param(ebr, tcx).def_id == def_id.to_def_id() })), .any(|r| matches!(r.kind(), ty::ReEarlyParam(ebr) if { item_generics.region_param(ebr, tcx).def_id == def_id.to_def_id() })),
_ => false, _ => false,
}; };

View file

@ -461,7 +461,7 @@ fn extract_def_id_from_arg<'tcx>(
arg: ty::GenericArg<'tcx>, arg: ty::GenericArg<'tcx>,
) -> DefId { ) -> DefId {
match arg.unpack() { match arg.unpack() {
ty::GenericArgKind::Lifetime(re) => match *re { ty::GenericArgKind::Lifetime(re) => match re.kind() {
ty::ReEarlyParam(ebr) => generics.region_param(ebr, tcx).def_id, ty::ReEarlyParam(ebr) => generics.region_param(ebr, tcx).def_id,
ty::ReBound( ty::ReBound(
_, _,
@ -530,7 +530,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for FunctionalVariances<'tcx> {
a: ty::Region<'tcx>, a: ty::Region<'tcx>,
_: ty::Region<'tcx>, _: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> { ) -> RelateResult<'tcx, ty::Region<'tcx>> {
let def_id = match *a { let def_id = match a.kind() {
ty::ReEarlyParam(ebr) => self.generics.region_param(ebr, self.tcx).def_id, ty::ReEarlyParam(ebr) => self.generics.region_param(ebr, self.tcx).def_id,
ty::ReBound( ty::ReBound(
_, _,

View file

@ -65,7 +65,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RegionEraserVisitor<'tcx> {
// We must not erase bound regions. `for<'a> fn(&'a ())` and // We must not erase bound regions. `for<'a> fn(&'a ())` and
// `fn(&'free ())` are different types: they may implement different // `fn(&'free ())` are different types: they may implement different
// traits and have a different `TypeId`. // traits and have a different `TypeId`.
match *r { match r.kind() {
ty::ReBound(..) => r, ty::ReBound(..) => r,
_ => self.tcx.lifetimes.re_erased, _ => self.tcx.lifetimes.re_erased,
} }

View file

@ -288,7 +288,7 @@ impl FlagComputation {
fn add_region(&mut self, r: ty::Region<'_>) { fn add_region(&mut self, r: ty::Region<'_>) {
self.add_flags(r.type_flags()); self.add_flags(r.type_flags());
if let ty::ReBound(debruijn, _) = *r { if let ty::ReBound(debruijn, _) = r.kind() {
self.add_bound_var(debruijn); self.add_bound_var(debruijn);
} }
} }

View file

@ -145,10 +145,10 @@ where
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { match r.kind() {
ty::ReBound(debruijn, br) if debruijn == self.current_index => { ty::ReBound(debruijn, br) if debruijn == self.current_index => {
let region = self.delegate.replace_region(br); let region = self.delegate.replace_region(br);
if let ty::ReBound(debruijn1, br) = *region { if let ty::ReBound(debruijn1, br) = region.kind() {
// If the callback returns a bound region, // If the callback returns a bound region,
// that region should always use the INNERMOST // that region should always use the INNERMOST
// debruijn index. Then we adjust it to the // debruijn index. Then we adjust it to the

View file

@ -95,7 +95,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { match r.kind() {
// Ignore bound regions and `'static` regions that appear in the // Ignore bound regions and `'static` regions that appear in the
// type, we only need to remap regions that reference lifetimes // type, we only need to remap regions that reference lifetimes
// from the function declaration. // from the function declaration.

View file

@ -2520,7 +2520,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
let identify_regions = self.tcx.sess.opts.unstable_opts.identify_regions; let identify_regions = self.tcx.sess.opts.unstable_opts.identify_regions;
match *region { match region.kind() {
ty::ReEarlyParam(ref data) => data.has_name(), ty::ReEarlyParam(ref data) => data.has_name(),
ty::ReLateParam(ty::LateParamRegion { kind, .. }) => kind.is_named(), ty::ReLateParam(ty::LateParamRegion { kind, .. }) => kind.is_named(),
@ -2590,7 +2590,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
// the user might want to diagnose an error, but there is basically no way // the user might want to diagnose an error, but there is basically no way
// to fit that into a short string. Hence the recommendation to use // to fit that into a short string. Hence the recommendation to use
// `explain_region()` or `note_and_explain_region()`. // `explain_region()` or `note_and_explain_region()`.
match *region { match region.kind() {
ty::ReEarlyParam(data) => { ty::ReEarlyParam(data) => {
p!(write("{}", data.name)); p!(write("{}", data.name));
return Ok(()); return Ok(());
@ -2680,7 +2680,7 @@ impl<'a, 'tcx> ty::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
let name = &mut self.name; let name = &mut self.name;
let region = match *r { let region = match r.kind() {
ty::ReBound(db, br) if db >= self.current_index => { ty::ReBound(db, br) if db >= self.current_index => {
*self.region_map.entry(br).or_insert_with(|| name(Some(db), self.current_index, br)) *self.region_map.entry(br).or_insert_with(|| name(Some(db), self.current_index, br))
} }
@ -2704,7 +2704,7 @@ impl<'a, 'tcx> ty::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
} }
_ => return r, _ => return r,
}; };
if let ty::ReBound(debruijn1, br) = *region { if let ty::ReBound(debruijn1, br) = region.kind() {
assert_eq!(debruijn1, ty::INNERMOST); assert_eq!(debruijn1, ty::INNERMOST);
ty::Region::new_bound(self.tcx, self.current_index, br) ty::Region::new_bound(self.tcx, self.current_index, br)
} else { } else {

View file

@ -1,5 +1,3 @@
use std::ops::Deref;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_errors::MultiSpan; use rustc_errors::MultiSpan;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -22,7 +20,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Region<'tcx> {
type Kind = RegionKind<'tcx>; type Kind = RegionKind<'tcx>;
fn kind(self) -> RegionKind<'tcx> { fn kind(self) -> RegionKind<'tcx> {
*self *self.0.0
} }
} }
@ -32,7 +30,7 @@ impl<'tcx> rustc_type_ir::Flags for Region<'tcx> {
} }
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex { fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
match **self { match self.kind() {
ty::ReBound(debruijn, _) => debruijn.shifted_in(1), ty::ReBound(debruijn, _) => debruijn.shifted_in(1),
_ => ty::INNERMOST, _ => ty::INNERMOST,
} }
@ -163,7 +161,7 @@ impl<'tcx> Region<'tcx> {
pub fn get_name(self) -> Option<Symbol> { pub fn get_name(self) -> Option<Symbol> {
if self.has_name() { if self.has_name() {
match *self { match self.kind() {
ty::ReEarlyParam(ebr) => Some(ebr.name), ty::ReEarlyParam(ebr) => Some(ebr.name),
ty::ReBound(_, br) => br.kind.get_name(), ty::ReBound(_, br) => br.kind.get_name(),
ty::ReLateParam(fr) => fr.kind.get_name(), ty::ReLateParam(fr) => fr.kind.get_name(),
@ -185,7 +183,7 @@ 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.kind() {
ty::ReEarlyParam(ebr) => ebr.has_name(), ty::ReEarlyParam(ebr) => ebr.has_name(),
ty::ReBound(_, br) => br.kind.is_named(), ty::ReBound(_, br) => br.kind.is_named(),
ty::ReLateParam(fr) => fr.kind.is_named(), ty::ReLateParam(fr) => fr.kind.is_named(),
@ -199,32 +197,32 @@ impl<'tcx> Region<'tcx> {
#[inline] #[inline]
pub fn is_error(self) -> bool { pub fn is_error(self) -> bool {
matches!(*self, ty::ReError(_)) matches!(self.kind(), ty::ReError(_))
} }
#[inline] #[inline]
pub fn is_static(self) -> bool { pub fn is_static(self) -> bool {
matches!(*self, ty::ReStatic) matches!(self.kind(), ty::ReStatic)
} }
#[inline] #[inline]
pub fn is_erased(self) -> bool { pub fn is_erased(self) -> bool {
matches!(*self, ty::ReErased) matches!(self.kind(), ty::ReErased)
} }
#[inline] #[inline]
pub fn is_bound(self) -> bool { pub fn is_bound(self) -> bool {
matches!(*self, ty::ReBound(..)) matches!(self.kind(), ty::ReBound(..))
} }
#[inline] #[inline]
pub fn is_placeholder(self) -> bool { pub fn is_placeholder(self) -> bool {
matches!(*self, ty::RePlaceholder(..)) matches!(self.kind(), ty::RePlaceholder(..))
} }
#[inline] #[inline]
pub fn bound_at_or_above_binder(self, index: ty::DebruijnIndex) -> bool { pub fn bound_at_or_above_binder(self, index: ty::DebruijnIndex) -> bool {
match *self { match self.kind() {
ty::ReBound(debruijn, _) => debruijn >= index, ty::ReBound(debruijn, _) => debruijn >= index,
_ => false, _ => false,
} }
@ -233,7 +231,7 @@ impl<'tcx> Region<'tcx> {
pub fn type_flags(self) -> TypeFlags { pub fn type_flags(self) -> TypeFlags {
let mut flags = TypeFlags::empty(); let mut flags = TypeFlags::empty();
match *self { match self.kind() {
ty::ReVar(..) => { ty::ReVar(..) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS; flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
@ -275,14 +273,14 @@ impl<'tcx> Region<'tcx> {
/// True for free regions other than `'static`. /// True for free regions other than `'static`.
pub fn is_param(self) -> bool { pub fn is_param(self) -> bool {
matches!(*self, ty::ReEarlyParam(_) | ty::ReLateParam(_)) matches!(self.kind(), ty::ReEarlyParam(_) | ty::ReLateParam(_))
} }
/// True for free region in the current context. /// True for free region in the current context.
/// ///
/// This is the case for `'static` and param regions. /// This is the case for `'static` and param regions.
pub fn is_free(self) -> bool { pub fn is_free(self) -> bool {
match *self { match self.kind() {
ty::ReStatic | ty::ReEarlyParam(..) | ty::ReLateParam(..) => true, ty::ReStatic | ty::ReEarlyParam(..) | ty::ReLateParam(..) => true,
ty::ReVar(..) ty::ReVar(..)
| ty::RePlaceholder(..) | ty::RePlaceholder(..)
@ -319,15 +317,6 @@ impl<'tcx> Region<'tcx> {
} }
} }
impl<'tcx> Deref for Region<'tcx> {
type Target = RegionKind<'tcx>;
#[inline]
fn deref(&self) -> &RegionKind<'tcx> {
self.0.0
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable)] #[derive(HashStable)]
pub struct EarlyParamRegion { pub struct EarlyParamRegion {

View file

@ -758,7 +758,7 @@ impl<'tcx> IsIdentity for CanonicalUserType<'tcx> {
_ => false, _ => false,
}, },
GenericArgKind::Lifetime(r) => match *r { GenericArgKind::Lifetime(r) => match r.kind() {
ty::ReBound(debruijn, br) => { ty::ReBound(debruijn, br) => {
// We only allow a `ty::INNERMOST` index in generic parameters. // We only allow a `ty::INNERMOST` index in generic parameters.
assert_eq!(debruijn, ty::INNERMOST); assert_eq!(debruijn, ty::INNERMOST);

View file

@ -77,7 +77,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) -> Self::Result { fn visit_region(&mut self, r: ty::Region<'tcx>) -> Self::Result {
match *r { match r.kind() {
ty::ReBound(debruijn, _) if debruijn < self.outer_index => { ty::ReBound(debruijn, _) if debruijn < self.outer_index => {
ControlFlow::Continue(()) ControlFlow::Continue(())
} }
@ -205,7 +205,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector {
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
if let ty::ReBound(debruijn, br) = *r { if let ty::ReBound(debruijn, br) = r.kind() {
if debruijn == self.current_index { if debruijn == self.current_index {
self.regions.insert(br.kind); self.regions.insert(br.kind);
} }
@ -250,7 +250,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MaxUniverse {
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
if let ty::RePlaceholder(placeholder) = *r { if let ty::RePlaceholder(placeholder) = r.kind() {
self.max_universe = ty::UniverseIndex::from_u32( self.max_universe = ty::UniverseIndex::from_u32(
self.max_universe.as_u32().max(placeholder.universe.as_u32()), self.max_universe.as_u32().max(placeholder.universe.as_u32()),
); );

View file

@ -368,7 +368,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
} }
fn print_region(&mut self, region: ty::Region<'_>) -> Result<(), PrintError> { fn print_region(&mut self, region: ty::Region<'_>) -> Result<(), PrintError> {
let i = match *region { let i = match region.kind() {
// Erased lifetimes use the index 0, for a // Erased lifetimes use the index 0, for a
// shorter mangling of `L_`. // shorter mangling of `L_`.
ty::ReErased => 0, ty::ReErased => 0,

View file

@ -42,7 +42,7 @@ pub fn find_param_with_region<'tcx>(
anon_region: Region<'tcx>, anon_region: Region<'tcx>,
replace_region: Region<'tcx>, replace_region: Region<'tcx>,
) -> Option<AnonymousParamInfo<'tcx>> { ) -> Option<AnonymousParamInfo<'tcx>> {
let (id, kind) = match *anon_region { let (id, kind) = match anon_region.kind() {
ty::ReLateParam(late_param) => (late_param.scope, late_param.kind), ty::ReLateParam(late_param) => (late_param.scope, late_param.kind),
ty::ReEarlyParam(ebr) => { ty::ReEarlyParam(ebr) => {
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id; let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;

View file

@ -299,7 +299,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
self.tcx.param_env(generic_param_scope), self.tcx.param_env(generic_param_scope),
terr, terr,
); );
match (*sub, *sup) { match (sub.kind(), sup.kind()) {
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {} (ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
(ty::RePlaceholder(_), _) => { (ty::RePlaceholder(_), _) => {
note_and_explain_region( note_and_explain_region(
@ -391,7 +391,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}) })
} }
infer::RelateParamBound(span, ty, opt_span) => { infer::RelateParamBound(span, ty, opt_span) => {
let prefix = match *sub { let prefix = match sub.kind() {
ty::ReStatic => note_and_explain::PrefixKind::TypeSatisfy, ty::ReStatic => note_and_explain::PrefixKind::TypeSatisfy,
_ => note_and_explain::PrefixKind::TypeOutlive, _ => note_and_explain::PrefixKind::TypeOutlive,
}; };
@ -1048,7 +1048,7 @@ pub(super) fn note_and_explain_region<'tcx>(
suffix: &str, suffix: &str,
alt_span: Option<Span>, alt_span: Option<Span>,
) { ) {
let (description, span) = match *region { let (description, span) = match region.kind() {
ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::RePlaceholder(_) | ty::ReStatic => { ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::RePlaceholder(_) | ty::ReStatic => {
msg_span_from_named_region(tcx, generic_param_scope, region, alt_span) msg_span_from_named_region(tcx, generic_param_scope, region, alt_span)
} }
@ -1085,7 +1085,7 @@ fn msg_span_from_named_region<'tcx>(
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
alt_span: Option<Span>, alt_span: Option<Span>,
) -> (String, Option<Span>) { ) -> (String, Option<Span>) {
match *region { match region.kind() {
ty::ReEarlyParam(br) => { ty::ReEarlyParam(br) => {
let param_def_id = tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id; let param_def_id = tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id;
let span = tcx.def_span(param_def_id); let span = tcx.def_span(param_def_id);
@ -1185,7 +1185,7 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
}); });
// Explain the region we are capturing. // Explain the region we are capturing.
match *hidden_region { match hidden_region.kind() {
ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReStatic => { ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReStatic => {
// Assuming regionck succeeded (*), we ought to always be // Assuming regionck succeeded (*), we ought to always be
// capturing *some* region from the fn header, and hence it // capturing *some* region from the fn header, and hence it

View file

@ -20,7 +20,7 @@ impl<'a> DescriptionCtx<'a> {
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
alt_span: Option<Span>, alt_span: Option<Span>,
) -> Option<Self> { ) -> Option<Self> {
let (span, kind, arg) = match *region { let (span, kind, arg) = match region.kind() {
ty::ReEarlyParam(br) => { ty::ReEarlyParam(br) => {
let scope = tcx let scope = tcx
.parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id) .parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id)

View file

@ -46,7 +46,7 @@ pub fn check_opaque_type_parameter_valid<'tcx>(
GenericArgKind::Lifetime(lt) => match defining_scope_kind { GenericArgKind::Lifetime(lt) => match defining_scope_kind {
DefiningScopeKind::HirTypeck => continue, DefiningScopeKind::HirTypeck => continue,
DefiningScopeKind::MirBorrowck => { DefiningScopeKind::MirBorrowck => {
matches!(*lt, ty::ReEarlyParam(_) | ty::ReLateParam(_)) matches!(lt.kind(), ty::ReEarlyParam(_) | ty::ReLateParam(_))
|| (lt.is_static() && opaque_env.param_equal_static(i)) || (lt.is_static() && opaque_env.param_equal_static(i))
} }
}, },

View file

@ -382,7 +382,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
for (new_region, old_region) in for (new_region, old_region) in
iter::zip(new_args.regions(), old_args.regions()) iter::zip(new_args.regions(), old_args.regions())
{ {
match (*new_region, *old_region) { match (new_region.kind(), old_region.kind()) {
// If both predicates have an `ReBound` (a HRTB) in the // If both predicates have an `ReBound` (a HRTB) in the
// same spot, we do nothing. // same spot, we do nothing.
(ty::ReBound(_, _), ty::ReBound(_, _)) => {} (ty::ReBound(_, _), ty::ReBound(_, _)) => {}

View file

@ -537,7 +537,7 @@ fn plug_infer_with_placeholders<'tcx>(
} }
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
if let ty::ReVar(vid) = *r { if let ty::ReVar(vid) = r.kind() {
let r = self let r = self
.infcx .infcx
.inner .inner

View file

@ -797,7 +797,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EraseEscapingBoundRegions<'tcx> {
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
if let ty::ReBound(debruijn, _) = *r if let ty::ReBound(debruijn, _) = r.kind()
&& debruijn < self.binder && debruijn < self.binder
{ {
r r

View file

@ -144,7 +144,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MaxEscapingBoundVarVisitor {
#[inline] #[inline]
fn visit_region(&mut self, r: ty::Region<'tcx>) { fn visit_region(&mut self, r: ty::Region<'tcx>) {
match *r { match r.kind() {
ty::ReBound(debruijn, _) if debruijn > self.outer_index => { ty::ReBound(debruijn, _) if debruijn > self.outer_index => {
self.escaping = self.escaping =
self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize()); self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize());

View file

@ -289,7 +289,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarReplacer<'_, 'tcx> {
} }
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r { match r.kind() {
ty::ReBound(debruijn, _) ty::ReBound(debruijn, _)
if debruijn.as_usize() if debruijn.as_usize()
>= self.current_index.as_usize() + self.universe_indices.len() => >= self.current_index.as_usize() + self.universe_indices.len() =>
@ -407,7 +407,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> {
} }
fn fold_region(&mut self, r0: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r0: ty::Region<'tcx>) -> ty::Region<'tcx> {
let r1 = match *r0 { let r1 = match r0.kind() {
ty::ReVar(vid) => self ty::ReVar(vid) => self
.infcx .infcx
.inner .inner
@ -417,7 +417,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> {
_ => r0, _ => r0,
}; };
let r2 = match *r1 { let r2 = match r1.kind() {
ty::RePlaceholder(p) => { ty::RePlaceholder(p) => {
let replace_var = self.mapped_regions.get(&p); let replace_var = self.mapped_regions.get(&p);
match replace_var { match replace_var {

View file

@ -75,7 +75,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
{ {
let orig_lt = let orig_lt =
tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local()); tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
if matches!(*orig_lt, ty::ReLateParam(..)) { if matches!(orig_lt.kind(), ty::ReLateParam(..)) {
mapping.insert( mapping.insert(
orig_lt, orig_lt,
ty::Region::new_early_param( ty::Region::new_early_param(

View file

@ -182,7 +182,7 @@ fn clean_param_env<'tcx>(
.is_some_and(|pred| tcx.lang_items().sized_trait() == Some(pred.def_id())) .is_some_and(|pred| tcx.lang_items().sized_trait() == Some(pred.def_id()))
}) })
.map(|pred| { .map(|pred| {
fold_regions(tcx, pred, |r, _| match *r { fold_regions(tcx, pred, |r, _| match r.kind() {
// FIXME: Don't `unwrap_or`, I think we should panic if we encounter an infer var that // FIXME: Don't `unwrap_or`, I think we should panic if we encounter an infer var that
// we can't map to a concrete region. However, `AutoTraitFinder` *does* leak those kinds // we can't map to a concrete region. However, `AutoTraitFinder` *does* leak those kinds
// of `ReVar`s for some reason at the time of writing. See `rustdoc-ui/` tests. // of `ReVar`s for some reason at the time of writing. See `rustdoc-ui/` tests.
@ -362,7 +362,7 @@ fn clean_region_outlives_constraints<'tcx>(
} }
fn early_bound_region_name(region: Region<'_>) -> Option<Symbol> { fn early_bound_region_name(region: Region<'_>) -> Option<Symbol> {
match *region { match region.kind() {
ty::ReEarlyParam(r) => Some(r.name), ty::ReEarlyParam(r) => Some(r.name),
_ => None, _ => None,
} }

View file

@ -320,7 +320,7 @@ pub(crate) fn clean_middle_const<'tcx>(
} }
pub(crate) fn clean_middle_region(region: ty::Region<'_>) -> Option<Lifetime> { pub(crate) fn clean_middle_region(region: ty::Region<'_>) -> Option<Lifetime> {
match *region { match region.kind() {
ty::ReStatic => Some(Lifetime::statik()), ty::ReStatic => Some(Lifetime::statik()),
_ if !region.has_name() => None, _ if !region.has_name() => None,
ty::ReBound(_, ty::BoundRegion { kind: ty::BoundRegionKind::Named(_, name), .. }) => { ty::ReBound(_, ty::BoundRegion { kind: ty::BoundRegionKind::Named(_, name), .. }) => {
@ -1941,7 +1941,7 @@ fn clean_trait_object_lifetime_bound<'tcx>(
// Since there is a semantic difference between an implicitly elided (i.e. "defaulted") object // Since there is a semantic difference between an implicitly elided (i.e. "defaulted") object
// lifetime and an explicitly elided object lifetime (`'_`), we intentionally don't hide the // lifetime and an explicitly elided object lifetime (`'_`), we intentionally don't hide the
// latter contrary to `clean_middle_region`. // latter contrary to `clean_middle_region`.
match *region { match region.kind() {
ty::ReStatic => Some(Lifetime::statik()), ty::ReStatic => Some(Lifetime::statik()),
ty::ReEarlyParam(region) => Some(Lifetime(region.name)), ty::ReEarlyParam(region) => Some(Lifetime(region.name)),
ty::ReBound(_, ty::BoundRegion { kind: ty::BoundRegionKind::Named(_, name), .. }) => { ty::ReBound(_, ty::BoundRegion { kind: ty::BoundRegionKind::Named(_, name), .. }) => {
@ -1972,7 +1972,7 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
// > If there is a unique bound from the containing type then that is the default // > If there is a unique bound from the containing type then that is the default
// If there is a default object lifetime and the given region is lexically equal to it, elide it. // If there is a default object lifetime and the given region is lexically equal to it, elide it.
match default { match default {
ObjectLifetimeDefault::Static => return *region == ty::ReStatic, ObjectLifetimeDefault::Static => return region.kind() == ty::ReStatic,
// FIXME(fmease): Don't compare lexically but respect de Bruijn indices etc. to handle shadowing correctly. // FIXME(fmease): Don't compare lexically but respect de Bruijn indices etc. to handle shadowing correctly.
ObjectLifetimeDefault::Arg(default) => return region.get_name() == default.get_name(), ObjectLifetimeDefault::Arg(default) => return region.get_name() == default.get_name(),
// > If there is more than one bound from the containing type then an explicit bound must be specified // > If there is more than one bound from the containing type then an explicit bound must be specified
@ -1992,7 +1992,7 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
// Note however that at the time of this writing it should be fine to disregard this subtlety // Note however that at the time of this writing it should be fine to disregard this subtlety
// as we neither render const exprs faithfully anyway (hiding them in some places or using `_` instead) // as we neither render const exprs faithfully anyway (hiding them in some places or using `_` instead)
// nor show the contents of fn bodies. // nor show the contents of fn bodies.
[] => *region == ty::ReStatic, [] => region.kind() == ty::ReStatic,
// > If the trait is defined with a single lifetime bound then that bound is used. // > If the trait is defined with a single lifetime bound then that bound is used.
// > If 'static is used for any lifetime bound then 'static is used. // > If 'static is used for any lifetime bound then 'static is used.
// FIXME(fmease): Don't compare lexically but respect de Bruijn indices etc. to handle shadowing correctly. // FIXME(fmease): Don't compare lexically but respect de Bruijn indices etc. to handle shadowing correctly.