Skip to content

Commit 9d478e3

Browse files
authored
Rollup merge of rust-lang#110218 - nnethercote:rm-ToRegionVid, r=compiler-errors
Remove `ToRegionVid` r? `@compiler-errors`
2 parents ff41c72 + 72605cd commit 9d478e3

File tree

18 files changed

+55
-241
lines changed

18 files changed

+55
-241
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+2-3
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

+3-3
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/dataflow.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use rustc_mir_dataflow::{self, fmt::DebugWithContext, CallReturnPlaces, GenKill}
1111
use rustc_mir_dataflow::{Analysis, Direction, Results};
1212
use std::fmt;
1313

14-
use crate::{
15-
places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid,
16-
};
14+
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
1715

1816
/// A tuple with named fields that can hold either the results or the transient state of the
1917
/// dataflow analyses used by the borrow checker.
@@ -242,7 +240,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
242240
) -> Self {
243241
let mut prec = OutOfScopePrecomputer::new(body, nonlexical_regioncx);
244242
for (borrow_index, borrow_data) in borrow_set.iter_enumerated() {
245-
let borrow_region = borrow_data.region.to_region_vid();
243+
let borrow_region = borrow_data.region;
246244
let location = borrow_data.reserve_location;
247245

248246
prec.precompute_borrows_out_of_scope(borrow_index, borrow_region, location);

compiler/rustc_borrowck/src/diagnostics/find_use.rs

+1-2
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

+5-5
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

+3-3
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/lib.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub mod consumers;
9494

9595
use borrow_set::{BorrowData, BorrowSet};
9696
use dataflow::{BorrowIndex, BorrowckFlowState as Flows, BorrowckResults, Borrows};
97-
use nll::{PoloniusOutput, ToRegionVid};
97+
use nll::PoloniusOutput;
9898
use place_ext::PlaceExt;
9999
use places_conflict::{places_conflict, PlaceConflictBias};
100100
use region_infer::RegionInferenceContext;
@@ -507,9 +507,7 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
507507
F: Fn() -> RegionCtxt,
508508
{
509509
let next_region = self.infcx.next_region_var(origin);
510-
let vid = next_region
511-
.as_var()
512-
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
510+
let vid = next_region.as_var();
513511

514512
if cfg!(debug_assertions) && !self.inside_canonicalization_ctxt() {
515513
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
@@ -531,9 +529,7 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
531529
F: Fn() -> RegionCtxt,
532530
{
533531
let next_region = self.infcx.next_nll_region_var(origin.clone());
534-
let vid = next_region
535-
.as_var()
536-
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
532+
let vid = next_region.as_var();
537533

538534
if cfg!(debug_assertions) && !self.inside_canonicalization_ctxt() {
539535
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);

compiler/rustc_borrowck/src/nll.rs

+1-22
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,27 +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-
462-
impl ToRegionVid for RegionVid {
463-
fn to_region_vid(self) -> RegionVid {
464-
self
465-
}
466-
}
467-
468447
pub(crate) trait ConstraintDescription {
469448
fn description(&self) -> &'static str;
470449
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727
},
2828
diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo},
2929
member_constraints::{MemberConstraintSet, NllMemberConstraintIndex},
30-
nll::{PoloniusOutput, ToRegionVid},
30+
nll::PoloniusOutput,
3131
region_infer::reverse_sccs::ReverseSccGraph,
3232
region_infer::values::{
3333
LivenessValues, PlaceholderIndices, RegionElement, RegionValueElements, RegionValues,
@@ -593,39 +593,36 @@ impl<'tcx> RegionInferenceContext<'tcx> {
593593
/// Returns `true` if the region `r` contains the point `p`.
594594
///
595595
/// Panics if called before `solve()` executes,
596-
pub(crate) fn region_contains(&self, r: impl ToRegionVid, p: impl ToElementIndex) -> bool {
597-
let scc = self.constraint_sccs.scc(r.to_region_vid());
596+
pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex) -> bool {
597+
let scc = self.constraint_sccs.scc(r);
598598
self.scc_values.contains(scc, p)
599599
}
600600

601601
/// Returns access to the value of `r` for debugging purposes.
602602
pub(crate) fn region_value_str(&self, r: RegionVid) -> String {
603-
let scc = self.constraint_sccs.scc(r.to_region_vid());
603+
let scc = self.constraint_sccs.scc(r);
604604
self.scc_values.region_value_str(scc)
605605
}
606606

607607
pub(crate) fn placeholders_contained_in<'a>(
608608
&'a self,
609609
r: RegionVid,
610610
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
611-
let scc = self.constraint_sccs.scc(r.to_region_vid());
611+
let scc = self.constraint_sccs.scc(r);
612612
self.scc_values.placeholders_contained_in(scc)
613613
}
614614

615615
/// Returns access to the value of `r` for debugging purposes.
616616
pub(crate) fn region_universe(&self, r: RegionVid) -> ty::UniverseIndex {
617-
let scc = self.constraint_sccs.scc(r.to_region_vid());
617+
let scc = self.constraint_sccs.scc(r);
618618
self.scc_universes[scc]
619619
}
620620

621621
/// Once region solving has completed, this function will return
622622
/// the member constraints that were applied to the value of a given
623623
/// region `r`. See `AppliedMemberConstraint`.
624-
pub(crate) fn applied_member_constraints(
625-
&self,
626-
r: impl ToRegionVid,
627-
) -> &[AppliedMemberConstraint] {
628-
let scc = self.constraint_sccs.scc(r.to_region_vid());
624+
pub(crate) fn applied_member_constraints(&self, r: RegionVid) -> &[AppliedMemberConstraint] {
625+
let scc = self.constraint_sccs.scc(r);
629626
binary_search_util::binary_search_slice(
630627
&self.member_constraints_applied,
631628
|applied| applied.member_region_scc,
@@ -1133,7 +1130,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11331130
let r_vid = self.to_region_vid(r);
11341131
let r_scc = self.constraint_sccs.scc(r_vid);
11351132

1136-
// The challenge if this. We have some region variable `r`
1133+
// The challenge is this. We have some region variable `r`
11371134
// whose value is a set of CFG points and universal
11381135
// regions. We want to find if that set is *equivalent* to
11391136
// any of the named regions found in the closure.
@@ -2234,7 +2231,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22342231
r: RegionVid,
22352232
body: &Body<'_>,
22362233
) -> Option<Location> {
2237-
let scc = self.constraint_sccs.scc(r.to_region_vid());
2234+
let scc = self.constraint_sccs.scc(r);
22382235
let locations = self.scc_values.locations_outlived_by(scc);
22392236
for location in locations {
22402237
let bb = &body[location.block];

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+1-2
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

+1-4
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

+3-4
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/type_check/relate_tys.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
131131
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
132132
};
133133

134-
let reg_var =
135-
reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
136-
137134
if cfg!(debug_assertions) && !self.type_checker.infcx.inside_canonicalization_ctxt() {
138135
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
139-
debug!(?reg_var);
140-
var_to_origin.insert(reg_var, RegionCtxt::Placeholder(reg_info));
136+
var_to_origin.insert(reg.as_var(), RegionCtxt::Placeholder(reg_info));
141137
}
142138

143139
reg
@@ -150,12 +146,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
150146
universe,
151147
);
152148

153-
let reg_var =
154-
reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
155-
156149
if cfg!(debug_assertions) && !self.type_checker.infcx.inside_canonicalization_ctxt() {
157150
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
158-
var_to_origin.insert(reg_var, RegionCtxt::Existential(None));
151+
var_to_origin.insert(reg.as_var(), RegionCtxt::Existential(None));
159152
}
160153

161154
reg

0 commit comments

Comments
 (0)