Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
let (sub_region, cause) = info?;

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(
vid,
region_var_origin(vid),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// this by hooking into the pretty printer and telling it to label the
// lifetimes without names with the value `'0`.
if let ty::Ref(region, ..) = ty.kind() {
match **region {
match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
Expand All @@ -607,7 +607,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);

let region = if let ty::Ref(region, ..) = ty.kind() {
match **region {
match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
where
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),
_ => region,
})
}

/// Returns `true` if a closure is inferred to be an `FnMut` closure.
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(r) = self.to_error_region(fr)
&& let ty::ReLateParam(late_param) = r.kind()
&& let ty::LateParamRegionKind::ClosureEnv = late_param.kind
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
{
Expand Down Expand Up @@ -832,7 +833,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let (Some(f), Some(outlived_f)) =
(self.to_error_region(fr), self.to_error_region(outlived_fr))
{
if *outlived_f != ty::ReStatic {
if outlived_f.kind() != ty::ReStatic {
return;
}
let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f);
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let tcx = self.infcx.tcx;

debug!("give_region_a_name: error_region = {:?}", error_region);
match *error_region {
match error_region.kind() {
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
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);
Expand Down Expand Up @@ -896,7 +896,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
&self,
fr: RegionVid,
) -> 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;
};
if region.has_name() {
Expand All @@ -912,7 +912,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {

let found = tcx
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
*r == ty::ReEarlyParam(region)
r.kind() == ty::ReEarlyParam(region)
});

Some(RegionName {
Expand All @@ -931,7 +931,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
&self,
fr: RegionVid,
) -> 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;
};
if region.has_name() {
Expand Down Expand Up @@ -1007,7 +1007,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
if data.projection_term.self_ty() == ty => {}
_ => 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 {
false
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
fold_regions(tcx, ty, |region, _| match *region {
fold_regions(tcx, ty, |region, _| match region.kind() {
ty::ReVar(vid) => {
let scc = self.constraint_sccs.scc(vid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
/// are dealt with during trait solving.
fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
if value.has_placeholders() {
fold_regions(self.tcx, value, |r, _| match *r {
fold_regions(self.tcx, value, |r, _| match r.kind() {
ty::RePlaceholder(placeholder) => {
self.constraints.placeholder_region(self.infcx, placeholder)
}
Expand All @@ -227,7 +227,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
}

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()
} else {
self.universal_regions.to_region_vid(r)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
}

fn visit_region(&mut self, r: ty::Region<'tcx>) {
match *r {
match r.kind() {
// ignore bound regions, keep visiting
ty::ReBound(_, _) => {}
_ => (self.op)(r),
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,19 +909,19 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
/// if it is a placeholder. Handling placeholders requires access to the
/// `MirTypeckRegionConstraints`.
fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
if let ty::ReVar(..) = *r {
r.as_var()
} else if let ty::ReError(guar) = *r {
self.tainted_by_errors.set(Some(guar));
// 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
// errors are being emitted and 2) it leaves the happy path unaffected.
self.fr_static
} else {
*self
match r.kind() {
ty::ReVar(..) => r.as_var(),
ty::ReError(guar) => {
self.tainted_by_errors.set(Some(guar));
// 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
// errors are being emitted and 2) it leaves the happy path unaffected.
self.fr_static
}
_ => *self
.indices
.get(&r)
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r))
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'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(
self.tcx,
fr.scope,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Ignore `'static` lifetimes for the purpose of this lint: it's
// because we know it outlives everything and so doesn't give meaningful
// 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;
}
// For each region argument (e.g., `'a` in our example), check for a
Expand Down Expand Up @@ -672,7 +672,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Again, skip `'static` because it outlives everything. Also, we trivially
// know that a region outlives itself. Also ignore `ReError`, to avoid
// 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;
}
if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ fn infringing_fields_error<'tcx>(
.entry((ty.clone(), predicate.clone()))
.or_default()
.push(origin.span());
if let ty::RegionKind::ReEarlyParam(ebr) = *b
if let ty::RegionKind::ReEarlyParam(ebr) = b.kind()
&& ebr.has_name()
{
bounds.push((b.to_string(), a.to_string(), None));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ fn recover_infer_ret_ty<'tcx>(
GenericParamKind::Lifetime { .. } => true,
_ => 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 => {
if has_region_params {
ty::Region::new_error_with_message(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
) {
for param in opaque_own_params {
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(
tcx,
ty::EarlyParamRegion { index: param.index, name: param.name },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
}

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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(

fn is_free_region(region: Region<'_>) -> bool {
// First, screen for regions that might appear in a type header.
match *region {
match region.kind() {
// These correspond to `T: 'a` relationships:
//
// struct Foo<'a, T> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
region: ty::Region<'tcx>,
variance: VarianceTermPtr<'a>,
) {
match *region {
match region.kind() {
ty::ReEarlyParam(ref data) => {
self.add_constraint(current, data.index, variance);
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
) -> ty::Region<'tcx> {
let infcx = canonicalizer.infcx.unwrap();

if let ty::ReVar(vid) = *r {
if let ty::ReVar(vid) = r.kind() {
r = infcx
.inner
.borrow_mut()
Expand All @@ -171,7 +171,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
);
};

match *r {
match r.kind() {
ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r,

ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
Expand Down Expand Up @@ -227,7 +227,7 @@ impl CanonicalizeMode for CanonicalizeUserTypeAnnotation {
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
match *r {
match r.kind() {
ty::ReEarlyParam(_)
| ty::ReLateParam(_)
| ty::ReErased
Expand Down Expand Up @@ -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> {
match *r {
match r.kind() {
ty::ReBound(index, ..) => {
if index >= self.binder_index {
bug!("escaping late-bound region during canonicalization");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
GenericArgKind::Lifetime(result_value) => {
// 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)`.

// We only allow a `ty::INNERMOST` index in generic parameters.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
match *r {
match r.kind() {
ty::ReBound(..) => {
// leave bound regions alone
r
Expand Down
Loading
Loading