Skip to content

Commit 1cbf8b5

Browse files
authored
Rollup merge of rust-lang#139509 - xizheyin:issue-139359, r=lcnr
clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()` Closes rust-lang#139359 r? `@lcnr`
2 parents 74c2a9b + c66d35e commit 1cbf8b5

File tree

49 files changed

+117
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+117
-127
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
487487
let (sub_region, cause) = info?;
488488

489489
debug!(?sub_region, "cause = {:#?}", cause);
490-
let error = match (error_region, *sub_region) {
490+
let error = match (error_region, sub_region.kind()) {
491491
(Some(error_region), ty::ReVar(vid)) => RegionResolutionError::SubSupConflict(
492492
vid,
493493
region_var_origin(vid),

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
585585
// this by hooking into the pretty printer and telling it to label the
586586
// lifetimes without names with the value `'0`.
587587
if let ty::Ref(region, ..) = ty.kind() {
588-
match **region {
588+
match region.kind() {
589589
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
590590
| ty::RePlaceholder(ty::PlaceholderRegion {
591591
bound: ty::BoundRegion { kind: br, .. },
@@ -605,7 +605,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
605605
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
606606

607607
let region = if let ty::Ref(region, ..) = ty.kind() {
608-
match **region {
608+
match region.kind() {
609609
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
610610
| ty::RePlaceholder(ty::PlaceholderRegion {
611611
bound: ty::BoundRegion { kind: br, .. },

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
190190
where
191191
T: TypeFoldable<TyCtxt<'tcx>>,
192192
{
193-
fold_regions(tcx, ty, |region, _| match *region {
193+
fold_regions(tcx, ty, |region, _| match region.kind() {
194194
ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region),
195195
_ => region,
196196
})
197197
}
198198

199199
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
200200
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
201-
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
201+
if let Some(r) = self.to_error_region(fr)
202+
&& let ty::ReLateParam(late_param) = r.kind()
202203
&& let ty::LateParamRegionKind::ClosureEnv = late_param.kind
203204
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
204205
{
@@ -832,7 +833,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
832833
if let (Some(f), Some(outlived_f)) =
833834
(self.to_error_region(fr), self.to_error_region(outlived_fr))
834835
{
835-
if *outlived_f != ty::ReStatic {
836+
if outlived_f.kind() != ty::ReStatic {
836837
return;
837838
}
838839
let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f);

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
288288
let tcx = self.infcx.tcx;
289289

290290
debug!("give_region_a_name: error_region = {:?}", error_region);
291-
match *error_region {
291+
match error_region.kind() {
292292
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
293293
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
294294
let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
@@ -896,7 +896,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
896896
&self,
897897
fr: RegionVid,
898898
) -> Option<RegionName> {
899-
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else {
899+
let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
900900
return None;
901901
};
902902
if region.has_name() {
@@ -912,7 +912,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
912912

913913
let found = tcx
914914
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
915-
*r == ty::ReEarlyParam(region)
915+
r.kind() == ty::ReEarlyParam(region)
916916
});
917917

918918
Some(RegionName {
@@ -931,7 +931,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
931931
&self,
932932
fr: RegionVid,
933933
) -> Option<RegionName> {
934-
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else {
934+
let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
935935
return None;
936936
};
937937
if region.has_name() {
@@ -1007,7 +1007,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
10071007
if data.projection_term.self_ty() == ty => {}
10081008
_ => return false,
10091009
}
1010-
tcx.any_free_region_meets(pred, |r| *r == ty::ReEarlyParam(region))
1010+
tcx.any_free_region_meets(pred, |r| r.kind() == ty::ReEarlyParam(region))
10111011
})
10121012
} else {
10131013
false

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
186186
where
187187
T: TypeFoldable<TyCtxt<'tcx>>,
188188
{
189-
fold_regions(tcx, ty, |region, _| match *region {
189+
fold_regions(tcx, ty, |region, _| match region.kind() {
190190
ty::ReVar(vid) => {
191191
let scc = self.constraint_sccs.scc(vid);
192192

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
205205
/// are dealt with during trait solving.
206206
fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
207207
if value.has_placeholders() {
208-
fold_regions(self.tcx, value, |r, _| match *r {
208+
fold_regions(self.tcx, value, |r, _| match r.kind() {
209209
ty::RePlaceholder(placeholder) => {
210210
self.constraints.placeholder_region(self.infcx, placeholder)
211211
}
@@ -227,7 +227,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
227227
}
228228

229229
fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
230-
if let ty::RePlaceholder(placeholder) = *r {
230+
if let ty::RePlaceholder(placeholder) = r.kind() {
231231
self.constraints.placeholder_region(self.infcx, placeholder).as_var()
232232
} else {
233233
self.universal_regions.to_region_vid(r)

compiler/rustc_borrowck/src/type_check/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ where
271271
}
272272

273273
fn visit_region(&mut self, r: ty::Region<'tcx>) {
274-
match *r {
274+
match r.kind() {
275275
// ignore bound regions, keep visiting
276276
ty::ReBound(_, _) => {}
277277
_ => (self.op)(r),

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -909,19 +909,19 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
909909
/// if it is a placeholder. Handling placeholders requires access to the
910910
/// `MirTypeckRegionConstraints`.
911911
fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
912-
if let ty::ReVar(..) = *r {
913-
r.as_var()
914-
} else if let ty::ReError(guar) = *r {
915-
self.tainted_by_errors.set(Some(guar));
916-
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
917-
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
918-
// errors are being emitted and 2) it leaves the happy path unaffected.
919-
self.fr_static
920-
} else {
921-
*self
912+
match r.kind() {
913+
ty::ReVar(..) => r.as_var(),
914+
ty::ReError(guar) => {
915+
self.tainted_by_errors.set(Some(guar));
916+
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
917+
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
918+
// errors are being emitted and 2) it leaves the happy path unaffected.
919+
self.fr_static
920+
}
921+
_ => *self
922922
.indices
923923
.get(&r)
924-
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r))
924+
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r)),
925925
}
926926
}
927927

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
442442
}
443443

444444
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
445-
if let ty::ReLateParam(fr) = *r {
445+
if let ty::ReLateParam(fr) = r.kind() {
446446
ty::Region::new_late_param(
447447
self.tcx,
448448
fr.scope,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
631631
// Ignore `'static` lifetimes for the purpose of this lint: it's
632632
// because we know it outlives everything and so doesn't give meaningful
633633
// clues. Also ignore `ReError`, to avoid knock-down errors.
634-
if let ty::ReStatic | ty::ReError(_) = **region_a {
634+
if let ty::ReStatic | ty::ReError(_) = region_a.kind() {
635635
continue;
636636
}
637637
// 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>>>(
672672
// Again, skip `'static` because it outlives everything. Also, we trivially
673673
// know that a region outlives itself. Also ignore `ReError`, to avoid
674674
// knock-down errors.
675-
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b {
675+
if matches!(region_b.kind(), ty::ReStatic | ty::ReError(_)) || region_a == region_b {
676676
continue;
677677
}
678678
if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) {

0 commit comments

Comments
 (0)