Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 35c4ea5

Browse files
authoredApr 13, 2023
Rollup merge of #110218 - nnethercote:rm-ToRegionVid, r=compiler-errors
Remove `ToRegionVid` r? ```@compiler-errors```
2 parents 958413c + 72605cd commit 35c4ea5

File tree

18 files changed

+55
-241
lines changed

18 files changed

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

Lines changed: 2 additions & 4 deletions
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

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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 1 addition & 22 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,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

Lines changed: 10 additions & 13 deletions
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

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

Lines changed: 2 additions & 9 deletions
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

‎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

‎compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use rustc_middle::hir::nested_filter;
88
use rustc_middle::ty::print::with_forced_trimmed_paths;
99
use rustc_middle::ty::subst::InternalSubsts;
1010
use rustc_middle::ty::util::IntTypeExt;
11-
use rustc_middle::ty::{
12-
self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable,
13-
TypeVisitableExt,
14-
};
11+
use rustc_middle::ty::{self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
1512
use rustc_span::symbol::Ident;
1613
use rustc_span::{Span, DUMMY_SP};
1714

@@ -874,28 +871,6 @@ fn infer_placeholder_type<'a>(
874871
item_ident: Ident,
875872
kind: &'static str,
876873
) -> Ty<'a> {
877-
// Attempts to make the type nameable by turning FnDefs into FnPtrs.
878-
struct MakeNameable<'tcx> {
879-
tcx: TyCtxt<'tcx>,
880-
}
881-
882-
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MakeNameable<'tcx> {
883-
fn interner(&self) -> TyCtxt<'tcx> {
884-
self.tcx
885-
}
886-
887-
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
888-
let ty = match *ty.kind() {
889-
ty::FnDef(def_id, substs) => {
890-
self.tcx.mk_fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs))
891-
}
892-
_ => ty,
893-
};
894-
895-
ty.super_fold_with(self)
896-
}
897-
}
898-
899874
let ty = tcx.diagnostic_only_typeck(def_id).node_type(body_id.hir_id);
900875

901876
// If this came from a free `const` or `static mut?` item,

‎compiler/rustc_hir_typeck/src/op.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_middle::ty::adjustment::{
1212
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
1313
};
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
15-
use rustc_middle::ty::{
16-
self, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
17-
};
15+
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
1816
use rustc_session::errors::ExprParenthesesNeeded;
1917
use rustc_span::source_map::Spanned;
2018
use rustc_span::symbol::{sym, Ident};
@@ -965,21 +963,3 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool
965963
}
966964
}
967965
}
968-
969-
struct TypeParamEraser<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, Span);
970-
971-
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TypeParamEraser<'_, 'tcx> {
972-
fn interner(&self) -> TyCtxt<'tcx> {
973-
self.0.tcx
974-
}
975-
976-
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
977-
match ty.kind() {
978-
ty::Param(_) => self.0.next_ty_var(TypeVariableOrigin {
979-
kind: TypeVariableOriginKind::MiscVariable,
980-
span: self.1,
981-
}),
982-
_ => ty.super_fold_with(self),
983-
}
984-
}
985-
}

‎compiler/rustc_middle/src/ty/sty.rs

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
77
use crate::ty::visit::ValidateBoundVars;
88
use crate::ty::InferTy::*;
99
use crate::ty::{
10-
self, AdtDef, Discr, FallibleTypeFolder, Term, Ty, TyCtxt, TypeFlags, TypeFoldable,
11-
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
10+
self, AdtDef, Discr, Term, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable,
11+
TypeVisitableExt, TypeVisitor,
1212
};
1313
use crate::ty::{List, ParamEnv};
1414
use hir::def::DefKind;
@@ -1156,81 +1156,6 @@ where
11561156
}
11571157
}
11581158

1159-
struct SkipBindersAt<'tcx> {
1160-
tcx: TyCtxt<'tcx>,
1161-
index: ty::DebruijnIndex,
1162-
}
1163-
1164-
impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for SkipBindersAt<'tcx> {
1165-
type Error = ();
1166-
1167-
fn interner(&self) -> TyCtxt<'tcx> {
1168-
self.tcx
1169-
}
1170-
1171-
fn try_fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Result<Binder<'tcx, T>, Self::Error>
1172-
where
1173-
T: ty::TypeFoldable<TyCtxt<'tcx>>,
1174-
{
1175-
self.index.shift_in(1);
1176-
let value = t.try_map_bound(|t| t.try_fold_with(self));
1177-
self.index.shift_out(1);
1178-
value
1179-
}
1180-
1181-
fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
1182-
if !ty.has_escaping_bound_vars() {
1183-
Ok(ty)
1184-
} else if let ty::Bound(index, bv) = *ty.kind() {
1185-
if index == self.index {
1186-
Err(())
1187-
} else {
1188-
Ok(self.interner().mk_bound(index.shifted_out(1), bv))
1189-
}
1190-
} else {
1191-
ty.try_super_fold_with(self)
1192-
}
1193-
}
1194-
1195-
fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
1196-
if !r.has_escaping_bound_vars() {
1197-
Ok(r)
1198-
} else if let ty::ReLateBound(index, bv) = r.kind() {
1199-
if index == self.index {
1200-
Err(())
1201-
} else {
1202-
Ok(self.interner().mk_re_late_bound(index.shifted_out(1), bv))
1203-
}
1204-
} else {
1205-
r.try_super_fold_with(self)
1206-
}
1207-
}
1208-
1209-
fn try_fold_const(&mut self, ct: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self::Error> {
1210-
if !ct.has_escaping_bound_vars() {
1211-
Ok(ct)
1212-
} else if let ty::ConstKind::Bound(index, bv) = ct.kind() {
1213-
if index == self.index {
1214-
Err(())
1215-
} else {
1216-
Ok(self.interner().mk_const(
1217-
ty::ConstKind::Bound(index.shifted_out(1), bv),
1218-
ct.ty().try_fold_with(self)?,
1219-
))
1220-
}
1221-
} else {
1222-
ct.try_super_fold_with(self)
1223-
}
1224-
}
1225-
1226-
fn try_fold_predicate(
1227-
&mut self,
1228-
p: ty::Predicate<'tcx>,
1229-
) -> Result<ty::Predicate<'tcx>, Self::Error> {
1230-
if !p.has_escaping_bound_vars() { Ok(p) } else { p.try_super_fold_with(self) }
1231-
}
1232-
}
1233-
12341159
/// Represents the projection of an associated type.
12351160
///
12361161
/// For a projection, this would be `<Ty as Trait<...>>::N`.
@@ -1772,10 +1697,10 @@ impl<'tcx> Region<'tcx> {
17721697
matches!(self.kind(), ty::ReVar(_))
17731698
}
17741699

1775-
pub fn as_var(self) -> Option<RegionVid> {
1700+
pub fn as_var(self) -> RegionVid {
17761701
match self.kind() {
1777-
ty::ReVar(vid) => Some(vid),
1778-
_ => None,
1702+
ty::ReVar(vid) => vid,
1703+
_ => bug!("expected region {:?} to be of kind ReVar", self),
17791704
}
17801705
}
17811706
}

‎compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::infer::InferCtxt;
99
use crate::traits::project::ProjectAndUnifyResult;
1010
use rustc_infer::infer::DefineOpaqueTypes;
1111
use rustc_middle::mir::interpret::ErrorHandled;
12-
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
1312
use rustc_middle::ty::visit::TypeVisitableExt;
1413
use rustc_middle::ty::{ImplPolarity, Region, RegionVid};
1514

@@ -851,23 +850,3 @@ impl<'tcx> AutoTraitFinder<'tcx> {
851850
infcx.freshen(p)
852851
}
853852
}
854-
855-
/// Replaces all ReVars in a type with ty::Region's, using the provided map
856-
pub struct RegionReplacer<'a, 'tcx> {
857-
vid_to_region: &'a FxHashMap<ty::RegionVid, ty::Region<'tcx>>,
858-
tcx: TyCtxt<'tcx>,
859-
}
860-
861-
impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for RegionReplacer<'a, 'tcx> {
862-
fn interner(&self) -> TyCtxt<'tcx> {
863-
self.tcx
864-
}
865-
866-
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
867-
(match *r {
868-
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
869-
_ => None,
870-
})
871-
.unwrap_or_else(|| r.super_fold_with(self))
872-
}
873-
}

0 commit comments

Comments
 (0)
Please sign in to comment.