From 7eb15509ce758849108e80d8807cde1d6806d74b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 1 Feb 2022 12:57:04 +1100 Subject: [PATCH] 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. --- .../src/type_check/constraint_conversion.rs | 2 +- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 6 +-- compiler/rustc_middle/src/ty/sty.rs | 16 ++++---- .../src/traits/auto_trait.rs | 11 ++---- compiler/rustc_traits/src/chalk/db.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 38 +++++++++---------- .../src/check/generator_interior.rs | 2 +- compiler/rustc_typeck/src/check/wfcheck.rs | 33 ++++++++-------- compiler/rustc_typeck/src/outlives/utils.rs | 15 +++----- 10 files changed, 56 insertions(+), 71 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index 68357556f86..5022cb98b82 100644 --- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> { // verifying these bounds. if t1.has_placeholders() { t1 = tcx.fold_regions(t1, &mut false, |r, _| match *r { - ty::RegionKind::RePlaceholder(placeholder) => { + ty::RePlaceholder(placeholder) => { self.constraints.placeholder_region(self.infcx, placeholder) } _ => r, diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 392a1780797..145ac6f4dab 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -428,7 +428,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { } GenericArgKind::Lifetime(result_value) => { // 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)`. // We only allow a `ty::INNERMOST` index in substitutions. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index c44c65eaf8e..c9a540f45bf 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -937,9 +937,9 @@ impl<'tcx> CommonLifetimes<'tcx> { }; CommonLifetimes { - re_root_empty: mk(RegionKind::ReEmpty(ty::UniverseIndex::ROOT)), - re_static: mk(RegionKind::ReStatic), - re_erased: mk(RegionKind::ReErased), + re_root_empty: mk(ty::ReEmpty(ty::UniverseIndex::ROOT)), + re_static: mk(ty::ReStatic), + re_erased: mk(ty::ReErased), } } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index cb921271de0..bb44cf74833 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1685,14 +1685,14 @@ impl<'tcx> Region<'tcx> { /// Is this region named by the user? pub fn has_name(self) -> bool { match *self { - RegionKind::ReEarlyBound(ebr) => ebr.has_name(), - RegionKind::ReLateBound(_, br) => br.kind.is_named(), - RegionKind::ReFree(fr) => fr.bound_region.is_named(), - RegionKind::ReStatic => true, - RegionKind::ReVar(..) => false, - RegionKind::RePlaceholder(placeholder) => placeholder.name.is_named(), - RegionKind::ReEmpty(_) => false, - RegionKind::ReErased => false, + ty::ReEarlyBound(ebr) => ebr.has_name(), + ty::ReLateBound(_, br) => br.kind.is_named(), + ty::ReFree(fr) => fr.bound_region.is_named(), + ty::ReStatic => true, + ty::ReVar(..) => false, + ty::RePlaceholder(placeholder) => placeholder.name.is_named(), + ty::ReEmpty(_) => false, + ty::ReErased => false, } } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 332d5223872..db179da7e90 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -440,13 +440,9 @@ impl<'tcx> AutoTraitFinder<'tcx> { match (*new_region, *old_region) { // If both predicates have an `ReLateBound` (a HRTB) in the // same spot, we do nothing. - ( - ty::RegionKind::ReLateBound(_, _), - ty::RegionKind::ReLateBound(_, _), - ) => {} + (ty::ReLateBound(_, _), ty::ReLateBound(_, _)) => {} - (ty::RegionKind::ReLateBound(_, _), _) - | (_, ty::RegionKind::ReVar(_)) => { + (ty::ReLateBound(_, _), _) | (_, ty::ReVar(_)) => { // One of these is true: // The new predicate has a HRTB in a spot where the old // predicate does not (if they both had a HRTB, the previous @@ -472,8 +468,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { // `user_computed_preds`. return false; } - (_, ty::RegionKind::ReLateBound(_, _)) - | (ty::RegionKind::ReVar(_), _) => { + (_, ty::ReLateBound(_, _)) | (ty::ReVar(_), _) => { // This is the opposite situation as the previous arm. // One of these is true: // diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 0170ab223b0..b806cb4a6b4 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -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()), 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 diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index d6743fce588..05ad0fe3264 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -35,7 +35,7 @@ use rustc_ast::ast; use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner}; use rustc_middle::ty::fold::TypeFolder; 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 chalk_ir::{FnSig, ForeignDefId}; @@ -449,32 +449,30 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime>> for Region<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime> { - use rustc_middle::ty::RegionKind::*; - match *self { - ReEarlyBound(_) => { + ty::ReEarlyBound(_) => { 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()), br.var.as_usize(), )) .intern(interner), - ReFree(_) => unimplemented!(), - ReStatic => chalk_ir::LifetimeData::Static.intern(interner), - ReVar(_) => unimplemented!(), - RePlaceholder(placeholder_region) => { + ty::ReFree(_) => unimplemented!(), + ty::ReStatic => chalk_ir::LifetimeData::Static.intern(interner), + ty::ReVar(_) => unimplemented!(), + ty::RePlaceholder(placeholder_region) => { chalk_ir::LifetimeData::Placeholder(chalk_ir::PlaceholderIndex { ui: chalk_ir::UniverseIndex { counter: placeholder_region.universe.index() }, idx: 0, }) .intern(interner) } - ReEmpty(ui) => { + ty::ReEmpty(ui) => { chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() }) .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>> for Region<'t impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime> { fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> { 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::BoundRegion { var: ty::BoundVar::from_usize(var.index), @@ -490,12 +488,10 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime unimplemented!(), - chalk_ir::LifetimeData::Placeholder(p) => { - ty::RegionKind::RePlaceholder(ty::Placeholder { - universe: ty::UniverseIndex::from_usize(p.ui.counter), - name: ty::BoundRegionKind::BrAnon(p.idx as u32), - }) - } + chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder { + universe: ty::UniverseIndex::from_usize(p.ui.counter), + name: ty::BoundRegionKind::BrAnon(p.idx as u32), + }), chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static, chalk_ir::LifetimeData::Empty(ui) => { 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) { Some(idx) => { let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) }; - return self.tcx.mk_region(RegionKind::ReLateBound(index, new_br)); + return self.tcx.mk_region(ty::ReLateBound(index, new_br)); } None => panic!("Missing `BrNamed`."), }, @@ -1064,14 +1060,14 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> { var: ty::BoundVar::from_u32(*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 => { let idx = self.named_regions.len() as u32; let br = ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(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)) } }, diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 21c8ea54621..d360f34ae70 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -416,7 +416,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { let tcx = self.fcx.tcx; let ref_ty = tcx.mk_ref( // 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 }, ); self.record( diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 31392719671..ad9bb4470b6 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -355,12 +355,11 @@ fn check_gat_where_clauses( // Same for the region. In our example, 'a corresponds // to the 'me parameter. let region_param = generics.param_at(*region_idx, tcx); - let region_param = - tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { - def_id: region_param.def_id, - index: region_param.index, - name: region_param.name, - })); + let region_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { + def_id: region_param.def_id, + index: region_param.index, + name: region_param.name, + })); // The predicate we expect to see. (In our example, // `Self: 'me`.) 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); // Translate into the generic parameters of the GAT. let region_a_param = generics.param_at(*region_a_idx, tcx); - let region_a_param = - tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { - def_id: region_a_param.def_id, - index: region_a_param.index, - name: region_a_param.name, - })); + let region_a_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { + def_id: region_a_param.def_id, + index: region_a_param.index, + name: region_a_param.name, + })); // Same for the region. let region_b_param = generics.param_at(*region_b_idx, tcx); - let region_b_param = - tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { - def_id: region_b_param.def_id, - index: region_b_param.index, - name: region_b_param.name, - })); + let region_b_param = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { + def_id: region_b_param.def_id, + index: region_b_param.index, + name: region_b_param.name, + })); // The predicate we expect to see. let clause = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate( region_a_param, diff --git a/compiler/rustc_typeck/src/outlives/utils.rs b/compiler/rustc_typeck/src/outlives/utils.rs index 1a32003da8d..54a5037b575 100644 --- a/compiler/rustc_typeck/src/outlives/utils.rs +++ b/compiler/rustc_typeck/src/outlives/utils.rs @@ -1,6 +1,6 @@ use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; 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 smallvec::smallvec; use std::collections::BTreeMap; @@ -141,7 +141,7 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool { // } // // We care about these, so fall through. - RegionKind::ReEarlyBound(_) => true, + ty::ReEarlyBound(_) => true, // These correspond to `T: 'static` relationships which can be // 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> { // 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: // @@ -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 // 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): // // struct Bar(::Type) 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: - RegionKind::ReErased - | RegionKind::ReVar(..) - | RegionKind::RePlaceholder(..) - | RegionKind::ReFree(..) => { + ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => { bug!("unexpected region in outlives inference: {:?}", region); } }