Skip to content

Commit bbc4009

Browse files
committed
Remove ToRegionVid.
It is only implemented for `Region`, where it is equivalent to the inherent `as_var` method.
1 parent 411422f commit bbc4009

File tree

11 files changed

+32
-55
lines changed

11 files changed

+32
-55
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
3-
use crate::nll::ToRegionVid;
43
use crate::path_utils::allow_two_phase_borrow;
54
use crate::place_ext::PlaceExt;
65
use crate::BorrowIndex;
@@ -204,7 +203,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
204203
return;
205204
}
206205

207-
let region = region.to_region_vid();
206+
let region = region.as_var();
208207

209208
let borrow = BorrowData {
210209
kind,
@@ -279,7 +278,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
279278
let borrow_data = &self.location_map[&location];
280279
assert_eq!(borrow_data.reserve_location, location);
281280
assert_eq!(borrow_data.kind, kind);
282-
assert_eq!(borrow_data.region, region.to_region_vid());
281+
assert_eq!(borrow_data.region, region.as_var());
283282
assert_eq!(borrow_data.borrowed_place, place);
284283
}
285284

compiler/rustc_borrowck/src/constraint_generation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustc_middle::ty::visit::TypeVisitable;
1212
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
1313

1414
use crate::{
15-
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, nll::ToRegionVid,
16-
places_conflict, region_infer::values::LivenessValues,
15+
borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict,
16+
region_infer::values::LivenessValues,
1717
};
1818

1919
pub(super) fn generate_constraints<'tcx>(
@@ -170,7 +170,7 @@ impl<'cx, 'tcx> ConstraintGeneration<'cx, 'tcx> {
170170
debug!("add_regular_live_constraint(live_ty={:?}, location={:?})", live_ty, location);
171171

172172
self.infcx.tcx.for_each_free_region(&live_ty, |live_region| {
173-
let vid = live_region.to_region_vid();
173+
let vid = live_region.as_var();
174174
self.liveness_constraints.add_element(vid, location);
175175
});
176176
}

compiler/rustc_borrowck/src/diagnostics/find_use.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::rc::Rc;
66

77
use crate::{
88
def_use::{self, DefUse},
9-
nll::ToRegionVid,
109
region_infer::{Cause, RegionInferenceContext},
1110
};
1211
use rustc_data_structures::fx::FxIndexSet;
@@ -117,7 +116,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> {
117116

118117
let mut found_it = false;
119118
self.tcx.for_each_free_region(&local_ty, |r| {
120-
if r.to_region_vid() == self.region_vid {
119+
if r.as_var() == self.region_vid {
121120
found_it = true;
122121
}
123122
});

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::{self, RegionVid, Ty};
1010
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1111
use rustc_span::{Span, DUMMY_SP};
1212

13-
use crate::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt};
13+
use crate::{universal_regions::DefiningTy, MirBorrowckCtxt};
1414

1515
/// A name for a particular region used in emitting diagnostics. This name could be a generated
1616
/// name like `'1`, a name used by the user like `'a`, or a name like `'static`.
@@ -497,7 +497,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
497497
// &
498498
// - let's call the lifetime of this reference `'1`
499499
(ty::Ref(region, referent_ty, _), hir::TyKind::Ref(_lifetime, referent_hir_ty)) => {
500-
if region.to_region_vid() == needle_fr {
500+
if region.as_var() == needle_fr {
501501
// Just grab the first character, the `&`.
502502
let source_map = self.infcx.tcx.sess.source_map();
503503
let ampersand_span = source_map.start_point(hir_ty.span);
@@ -598,7 +598,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
598598
for (kind, hir_arg) in iter::zip(substs, args.args) {
599599
match (kind.unpack(), hir_arg) {
600600
(GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => {
601-
if r.to_region_vid() == needle_fr {
601+
if r.as_var() == needle_fr {
602602
return Some(lt);
603603
}
604604
}
@@ -666,7 +666,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
666666

667667
let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
668668
debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty);
669-
if !tcx.any_free_region_meets(&return_ty, |r| r.to_region_vid() == fr) {
669+
if !tcx.any_free_region_meets(&return_ty, |r| r.as_var() == fr) {
670670
return None;
671671
}
672672

@@ -803,7 +803,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
803803

804804
let tcx = self.infcx.tcx;
805805

806-
if !tcx.any_free_region_meets(&yield_ty, |r| r.to_region_vid() == fr) {
806+
if !tcx.any_free_region_meets(&yield_ty, |r| r.as_var() == fr) {
807807
return None;
808808
}
809809

compiler/rustc_borrowck/src/diagnostics/var_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
33

4+
use crate::region_infer::RegionInferenceContext;
45
use crate::Upvar;
5-
use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext};
66
use rustc_index::vec::{Idx, IndexSlice};
77
use rustc_middle::mir::{Body, Local};
88
use rustc_middle::ty::{RegionVid, TyCtxt};
@@ -46,7 +46,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4646
self.universal_regions().defining_ty.upvar_tys().position(|upvar_ty| {
4747
debug!("get_upvar_index_for_region: upvar_ty={upvar_ty:?}");
4848
tcx.any_free_region_meets(&upvar_ty, |r| {
49-
let r = r.to_region_vid();
49+
let r = r.as_var();
5050
debug!("get_upvar_index_for_region: r={r:?} fr={fr:?}");
5151
r == fr
5252
})
@@ -96,7 +96,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9696
self.universal_regions().unnormalized_input_tys.iter().skip(implicit_inputs).position(
9797
|arg_ty| {
9898
debug!("get_argument_index_for_region: arg_ty = {arg_ty:?}");
99-
tcx.any_free_region_meets(arg_ty, |r| r.to_region_vid() == fr)
99+
tcx.any_free_region_meets(arg_ty, |r| r.as_var() == fr)
100100
},
101101
)?;
102102

compiler/rustc_borrowck/src/nll.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::{
1010
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
1111
Promoted,
1212
};
13-
use rustc_middle::ty::{self, OpaqueHiddenType, Region, RegionVid, TyCtxt};
13+
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
1414
use rustc_span::symbol::sym;
1515
use std::env;
1616
use std::io;
@@ -444,21 +444,6 @@ fn for_each_region_constraint<'tcx>(
444444
Ok(())
445445
}
446446

447-
/// Right now, we piggy back on the `ReVar` to store our NLL inference
448-
/// regions. These are indexed with `RegionVid`. This method will
449-
/// assert that the region is a `ReVar` and extract its internal index.
450-
/// This is reasonable because in our MIR we replace all universal regions
451-
/// with inference variables.
452-
pub trait ToRegionVid {
453-
fn to_region_vid(self) -> RegionVid;
454-
}
455-
456-
impl<'tcx> ToRegionVid for Region<'tcx> {
457-
fn to_region_vid(self) -> RegionVid {
458-
if let ty::ReVar(vid) = *self { vid } else { bug!("region is not an ReVar: {:?}", self) }
459-
}
460-
}
461-
462447
pub(crate) trait ConstraintDescription {
463448
fn description(&self) -> &'static str;
464449
}

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11301130
let r_vid = self.to_region_vid(r);
11311131
let r_scc = self.constraint_sccs.scc(r_vid);
11321132

1133-
// The challenge if this. We have some region variable `r`
1133+
// The challenge is this. We have some region variable `r`
11341134
// whose value is a set of CFG points and universal
11351135
// regions. We want to find if that set is *equivalent* to
11361136
// any of the named regions found in the closure.

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_span::{Span, DUMMY_SP};
1212

1313
use crate::{
1414
constraints::OutlivesConstraint,
15-
nll::ToRegionVid,
1615
region_infer::TypeTest,
1716
type_check::{Locations, MirTypeckRegionConstraints},
1817
universal_regions::UniversalRegions,
@@ -198,7 +197,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
198197

199198
fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
200199
if let ty::RePlaceholder(placeholder) = *r {
201-
self.constraints.placeholder_region(self.infcx, placeholder).to_region_vid()
200+
self.constraints.placeholder_region(self.infcx, placeholder).as_var()
202201
} else {
203202
self.universal_regions.to_region_vid(r)
204203
}

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111
constraints::OutlivesConstraintSet,
1212
facts::{AllFacts, AllFactsExt},
1313
location::LocationTable,
14-
nll::ToRegionVid,
1514
region_infer::values::RegionValueElements,
1615
universal_regions::UniversalRegions,
1716
};
@@ -80,9 +79,7 @@ fn compute_relevant_live_locals<'tcx>(
8079
) -> (Vec<Local>, Vec<Local>) {
8180
let (boring_locals, relevant_live_locals): (Vec<_>, Vec<_>) =
8281
body.local_decls.iter_enumerated().partition_map(|(local, local_decl)| {
83-
if tcx.all_free_regions_meet(&local_decl.ty, |r| {
84-
free_regions.contains(&r.to_region_vid())
85-
}) {
82+
if tcx.all_free_regions_meet(&local_decl.ty, |r| free_regions.contains(&r.as_var())) {
8683
Either::Left(local)
8784
} else {
8885
Either::Right(local)

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use crate::{
5656
facts::AllFacts,
5757
location::LocationTable,
5858
member_constraints::MemberConstraintSet,
59-
nll::ToRegionVid,
6059
path_utils,
6160
region_infer::values::{
6261
LivenessValues, PlaceholderIndex, PlaceholderIndices, RegionValueElements,
@@ -2419,7 +2418,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24192418
if let Some(all_facts) = all_facts {
24202419
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
24212420
if let Some(borrow_index) = borrow_set.get_index_of(&location) {
2422-
let region_vid = borrow_region.to_region_vid();
2421+
let region_vid = borrow_region.as_var();
24232422
all_facts.loan_issued_at.push((
24242423
region_vid,
24252424
borrow_index,
@@ -2465,8 +2464,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24652464
match base_ty.kind() {
24662465
ty::Ref(ref_region, _, mutbl) => {
24672466
constraints.outlives_constraints.push(OutlivesConstraint {
2468-
sup: ref_region.to_region_vid(),
2469-
sub: borrow_region.to_region_vid(),
2467+
sup: ref_region.as_var(),
2468+
sub: borrow_region.as_var(),
24702469
locations: location.to_locations(),
24712470
span: location.to_locations().span(body),
24722471
category,

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rustc_span::symbol::{kw, sym};
2828
use rustc_span::Symbol;
2929
use std::iter;
3030

31-
use crate::nll::ToRegionVid;
3231
use crate::renumber::{BoundRegionInfo, RegionCtxt};
3332
use crate::BorrowckInferCtxt;
3433

@@ -406,7 +405,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
406405

407406
// Create the "global" region that is always free in all contexts: 'static.
408407
let fr_static =
409-
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(kw::Static)).to_region_vid();
408+
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(kw::Static)).as_var();
410409

411410
// We've now added all the global regions. The next ones we
412411
// add will be external.
@@ -446,7 +445,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
446445
};
447446

448447
debug!(?region_vid);
449-
indices.insert_late_bound_region(r, region_vid.to_region_vid());
448+
indices.insert_late_bound_region(r, region_vid.as_var());
450449
}
451450
},
452451
);
@@ -480,7 +479,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
480479
};
481480

482481
debug!(?region_vid);
483-
indices.insert_late_bound_region(r, region_vid.to_region_vid());
482+
indices.insert_late_bound_region(r, region_vid.as_var());
484483
}
485484
});
486485

@@ -499,7 +498,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
499498
let reg_vid = self
500499
.infcx
501500
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
502-
.to_region_vid();
501+
.as_var();
503502

504503
let region = self.infcx.tcx.mk_re_var(reg_vid);
505504
let va_list_ty =
@@ -514,7 +513,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
514513
let fr_fn_body = self
515514
.infcx
516515
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("fn_body")))
517-
.to_region_vid();
516+
.as_var();
518517

519518
let num_universals = self.infcx.num_region_vars();
520519

@@ -635,7 +634,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
635634

636635
let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
637636
let subst_mapping =
638-
iter::zip(identity_substs.regions(), fr_substs.regions().map(|r| r.to_region_vid()));
637+
iter::zip(identity_substs.regions(), fr_substs.regions().map(|r| r.as_var()));
639638

640639
UniversalRegionIndices { indices: global_mapping.chain(subst_mapping).collect(), fr_static }
641640
}
@@ -789,7 +788,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
789788
self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name)))
790789
};
791790

792-
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
791+
indices.insert_late_bound_region(liberated_region, region_vid.as_var());
793792
debug!(?liberated_region, ?region_vid);
794793
region_vid
795794
});
@@ -822,7 +821,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
822821
};
823822

824823
debug!(?region_vid);
825-
indices.insert_late_bound_region(r, region_vid.to_region_vid());
824+
indices.insert_late_bound_region(r, region_vid.as_var());
826825
}
827826
});
828827
}
@@ -843,7 +842,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
843842
})
844843
};
845844

846-
indices.insert_late_bound_region(r, region_vid.to_region_vid());
845+
indices.insert_late_bound_region(r, region_vid.as_var());
847846
}
848847
});
849848
}
@@ -861,7 +860,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
861860
}
862861

863862
/// Converts `r` into a local inference variable: `r` can either
864-
/// by a `ReVar` (i.e., already a reference to an inference
863+
/// be a `ReVar` (i.e., already a reference to an inference
865864
/// variable) or it can be `'static` or some early-bound
866865
/// region. This is useful when taking the results from
867866
/// type-checking and trait-matching, which may sometimes
@@ -870,7 +869,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
870869
/// fully initialized.
871870
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
872871
if let ty::ReVar(..) = *r {
873-
r.to_region_vid()
872+
r.as_var()
874873
} else if r.is_error() {
875874
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
876875
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if

0 commit comments

Comments
 (0)