Skip to content

Commit 7eb1550

Browse files
committed
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.
1 parent 7024dc5 commit 7eb1550

File tree

10 files changed

+56
-71
lines changed

10 files changed

+56
-71
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
106106
// verifying these bounds.
107107
if t1.has_placeholders() {
108108
t1 = tcx.fold_regions(t1, &mut false, |r, _| match *r {
109-
ty::RegionKind::RePlaceholder(placeholder) => {
109+
ty::RePlaceholder(placeholder) => {
110110
self.constraints.placeholder_region(self.infcx, placeholder)
111111
}
112112
_ => r,

compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
428428
}
429429
GenericArgKind::Lifetime(result_value) => {
430430
// e.g., here `result_value` might be `'?1` in the example above...
431-
if let ty::RegionKind::ReLateBound(debruijn, br) = *result_value {
431+
if let ty::ReLateBound(debruijn, br) = *result_value {
432432
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
433433

434434
// We only allow a `ty::INNERMOST` index in substitutions.

compiler/rustc_middle/src/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,9 @@ impl<'tcx> CommonLifetimes<'tcx> {
937937
};
938938

939939
CommonLifetimes {
940-
re_root_empty: mk(RegionKind::ReEmpty(ty::UniverseIndex::ROOT)),
941-
re_static: mk(RegionKind::ReStatic),
942-
re_erased: mk(RegionKind::ReErased),
940+
re_root_empty: mk(ty::ReEmpty(ty::UniverseIndex::ROOT)),
941+
re_static: mk(ty::ReStatic),
942+
re_erased: mk(ty::ReErased),
943943
}
944944
}
945945
}

compiler/rustc_middle/src/ty/sty.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1685,14 +1685,14 @@ impl<'tcx> Region<'tcx> {
16851685
/// Is this region named by the user?
16861686
pub fn has_name(self) -> bool {
16871687
match *self {
1688-
RegionKind::ReEarlyBound(ebr) => ebr.has_name(),
1689-
RegionKind::ReLateBound(_, br) => br.kind.is_named(),
1690-
RegionKind::ReFree(fr) => fr.bound_region.is_named(),
1691-
RegionKind::ReStatic => true,
1692-
RegionKind::ReVar(..) => false,
1693-
RegionKind::RePlaceholder(placeholder) => placeholder.name.is_named(),
1694-
RegionKind::ReEmpty(_) => false,
1695-
RegionKind::ReErased => false,
1688+
ty::ReEarlyBound(ebr) => ebr.has_name(),
1689+
ty::ReLateBound(_, br) => br.kind.is_named(),
1690+
ty::ReFree(fr) => fr.bound_region.is_named(),
1691+
ty::ReStatic => true,
1692+
ty::ReVar(..) => false,
1693+
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
1694+
ty::ReEmpty(_) => false,
1695+
ty::ReErased => false,
16961696
}
16971697
}
16981698

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
440440
match (*new_region, *old_region) {
441441
// If both predicates have an `ReLateBound` (a HRTB) in the
442442
// same spot, we do nothing.
443-
(
444-
ty::RegionKind::ReLateBound(_, _),
445-
ty::RegionKind::ReLateBound(_, _),
446-
) => {}
443+
(ty::ReLateBound(_, _), ty::ReLateBound(_, _)) => {}
447444

448-
(ty::RegionKind::ReLateBound(_, _), _)
449-
| (_, ty::RegionKind::ReVar(_)) => {
445+
(ty::ReLateBound(_, _), _) | (_, ty::ReVar(_)) => {
450446
// One of these is true:
451447
// The new predicate has a HRTB in a spot where the old
452448
// predicate does not (if they both had a HRTB, the previous
@@ -472,8 +468,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
472468
// `user_computed_preds`.
473469
return false;
474470
}
475-
(_, ty::RegionKind::ReLateBound(_, _))
476-
| (ty::RegionKind::ReVar(_), _) => {
471+
(_, ty::ReLateBound(_, _)) | (ty::ReVar(_), _) => {
477472
// This is the opposite situation as the previous arm.
478473
// One of these is true:
479474
//

compiler/rustc_traits/src/chalk/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ fn bound_vars_for_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx
711711
var: ty::BoundVar::from_usize(substs.len()),
712712
kind: ty::BrAnon(substs.len() as u32),
713713
};
714-
tcx.mk_region(ty::RegionKind::ReLateBound(ty::INNERMOST, br)).into()
714+
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
715715
}
716716

717717
ty::GenericParamDefKind::Const { .. } => tcx

compiler/rustc_traits/src/chalk/lowering.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_ast::ast;
3535
use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner};
3636
use rustc_middle::ty::fold::TypeFolder;
3737
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
38-
use rustc_middle::ty::{self, Binder, Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor};
38+
use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeVisitor};
3939
use rustc_span::def_id::DefId;
4040

4141
use chalk_ir::{FnSig, ForeignDefId};
@@ -449,53 +449,49 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
449449

450450
impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'tcx> {
451451
fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> {
452-
use rustc_middle::ty::RegionKind::*;
453-
454452
match *self {
455-
ReEarlyBound(_) => {
453+
ty::ReEarlyBound(_) => {
456454
panic!("Should have already been substituted.");
457455
}
458-
ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
456+
ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
459457
chalk_ir::DebruijnIndex::new(db.as_u32()),
460458
br.var.as_usize(),
461459
))
462460
.intern(interner),
463-
ReFree(_) => unimplemented!(),
464-
ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
465-
ReVar(_) => unimplemented!(),
466-
RePlaceholder(placeholder_region) => {
461+
ty::ReFree(_) => unimplemented!(),
462+
ty::ReStatic => chalk_ir::LifetimeData::Static.intern(interner),
463+
ty::ReVar(_) => unimplemented!(),
464+
ty::RePlaceholder(placeholder_region) => {
467465
chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex {
468466
ui: chalk_ir::UniverseIndex { counter: placeholder_region.universe.index() },
469467
idx: 0,
470468
})
471469
.intern(interner)
472470
}
473-
ReEmpty(ui) => {
471+
ty::ReEmpty(ui) => {
474472
chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() })
475473
.intern(interner)
476474
}
477-
ReErased => chalk_ir::LifetimeData::Erased.intern(interner),
475+
ty::ReErased => chalk_ir::LifetimeData::Erased.intern(interner),
478476
}
479477
}
480478
}
481479

482480
impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> {
483481
fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
484482
let kind = match self.data(interner) {
485-
chalk_ir::LifetimeData::BoundVar(var) => ty::RegionKind::ReLateBound(
483+
chalk_ir::LifetimeData::BoundVar(var) => ty::ReLateBound(
486484
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
487485
ty::BoundRegion {
488486
var: ty::BoundVar::from_usize(var.index),
489487
kind: ty::BrAnon(var.index as u32),
490488
},
491489
),
492490
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
493-
chalk_ir::LifetimeData::Placeholder(p) => {
494-
ty::RegionKind::RePlaceholder(ty::Placeholder {
495-
universe: ty::UniverseIndex::from_usize(p.ui.counter),
496-
name: ty::BoundRegionKind::BrAnon(p.idx as u32),
497-
})
498-
}
491+
chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder {
492+
universe: ty::UniverseIndex::from_usize(p.ui.counter),
493+
name: ty::BoundRegionKind::BrAnon(p.idx as u32),
494+
}),
499495
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
500496
chalk_ir::LifetimeData::Empty(ui) => {
501497
ty::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
@@ -982,7 +978,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
982978
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
983979
Some(idx) => {
984980
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
985-
return self.tcx.mk_region(RegionKind::ReLateBound(index, new_br));
981+
return self.tcx.mk_region(ty::ReLateBound(index, new_br));
986982
}
987983
None => panic!("Missing `BrNamed`."),
988984
},
@@ -1064,14 +1060,14 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
10641060
var: ty::BoundVar::from_u32(*idx),
10651061
kind: ty::BrAnon(*idx),
10661062
};
1067-
self.tcx.mk_region(RegionKind::ReLateBound(self.binder_index, br))
1063+
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
10681064
}
10691065
None => {
10701066
let idx = self.named_regions.len() as u32;
10711067
let br =
10721068
ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(idx) };
10731069
self.named_regions.insert(_re.def_id, idx);
1074-
self.tcx.mk_region(RegionKind::ReLateBound(self.binder_index, br))
1070+
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
10751071
}
10761072
},
10771073

compiler/rustc_typeck/src/check/generator_interior.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
416416
let tcx = self.fcx.tcx;
417417
let ref_ty = tcx.mk_ref(
418418
// Use `ReErased` as `resolve_interior` is going to replace all the regions anyway.
419-
tcx.mk_region(ty::RegionKind::ReErased),
419+
tcx.mk_region(ty::ReErased),
420420
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
421421
);
422422
self.record(

compiler/rustc_typeck/src/check/wfcheck.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,11 @@ fn check_gat_where_clauses(
355355
// Same for the region. In our example, 'a corresponds
356356
// to the 'me parameter.
357357
let region_param = generics.param_at(*region_idx, tcx);
358-
let region_param =
359-
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion {
360-
def_id: region_param.def_id,
361-
index: region_param.index,
362-
name: region_param.name,
363-
}));
358+
let region_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
359+
def_id: region_param.def_id,
360+
index: region_param.index,
361+
name: region_param.name,
362+
}));
364363
// The predicate we expect to see. (In our example,
365364
// `Self: 'me`.)
366365
let clause = ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
@@ -397,20 +396,18 @@ fn check_gat_where_clauses(
397396
debug!("required clause: {} must outlive {}", region_a, region_b);
398397
// Translate into the generic parameters of the GAT.
399398
let region_a_param = generics.param_at(*region_a_idx, tcx);
400-
let region_a_param =
401-
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion {
402-
def_id: region_a_param.def_id,
403-
index: region_a_param.index,
404-
name: region_a_param.name,
405-
}));
399+
let region_a_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
400+
def_id: region_a_param.def_id,
401+
index: region_a_param.index,
402+
name: region_a_param.name,
403+
}));
406404
// Same for the region.
407405
let region_b_param = generics.param_at(*region_b_idx, tcx);
408-
let region_b_param =
409-
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion {
410-
def_id: region_b_param.def_id,
411-
index: region_b_param.index,
412-
name: region_b_param.name,
413-
}));
406+
let region_b_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
407+
def_id: region_b_param.def_id,
408+
index: region_b_param.index,
409+
name: region_b_param.name,
410+
}));
414411
// The predicate we expect to see.
415412
let clause = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
416413
region_a_param,

compiler/rustc_typeck/src/outlives/utils.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
22
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
3-
use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt};
3+
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
44
use rustc_span::Span;
55
use smallvec::smallvec;
66
use std::collections::BTreeMap;
@@ -141,7 +141,7 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
141141
// }
142142
//
143143
// We care about these, so fall through.
144-
RegionKind::ReEarlyBound(_) => true,
144+
ty::ReEarlyBound(_) => true,
145145

146146
// These correspond to `T: 'static` relationships which can be
147147
// rather surprising. We are therefore putting this behind a
@@ -150,7 +150,7 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
150150
// struct Foo<'a, T> {
151151
// field: &'static T, // this would generate a ReStatic
152152
// }
153-
RegionKind::ReStatic => tcx.sess.features_untracked().infer_static_outlives_requirements,
153+
ty::ReStatic => tcx.sess.features_untracked().infer_static_outlives_requirements,
154154

155155
// Late-bound regions can appear in `fn` types:
156156
//
@@ -160,19 +160,16 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
160160
//
161161
// The type above might generate a `T: 'b` bound, but we can
162162
// ignore it. We can't put it on the struct header anyway.
163-
RegionKind::ReLateBound(..) => false,
163+
ty::ReLateBound(..) => false,
164164

165165
// This can appear in `where Self: ` bounds (#64855):
166166
//
167167
// struct Bar<T>(<Self as Foo>::Type) where Self: ;
168168
// struct Baz<'a>(&'a Self) where Self: ;
169-
RegionKind::ReEmpty(_) => false,
169+
ty::ReEmpty(_) => false,
170170

171171
// These regions don't appear in types from type declarations:
172-
RegionKind::ReErased
173-
| RegionKind::ReVar(..)
174-
| RegionKind::RePlaceholder(..)
175-
| RegionKind::ReFree(..) => {
172+
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
176173
bug!("unexpected region in outlives inference: {:?}", region);
177174
}
178175
}

0 commit comments

Comments
 (0)