Skip to content

Commit 8252a6e

Browse files
committed
address review
1 parent c9843d6 commit 8252a6e

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

compiler/rustc_borrowck/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
505505
{
506506
let next_region = self.infcx.next_region_var(origin);
507507
let vid = next_region
508-
.try_get_var()
508+
.as_var()
509509
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
510510

511511
if cfg!(debug_assertions) {
@@ -534,7 +534,7 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
534534
{
535535
let next_region = self.infcx.next_nll_region_var(origin.clone());
536536
let vid = next_region
537-
.try_get_var()
537+
.as_var()
538538
.unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
539539

540540
if cfg!(debug_assertions) {

compiler/rustc_borrowck/src/region_infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ fn sccs_info<'cx, 'tcx>(
261261
}
262262
debug!(debug_str);
263263

264-
let num_components = sccs.scc_data.ranges.len();
264+
let num_components = sccs.scc_data().ranges().len();
265265
let mut components = vec![FxHashSet::default(); num_components];
266266

267-
for (reg_var_idx, scc_idx) in sccs.scc_indices.iter().enumerate() {
267+
for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() {
268268
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
269269
let origin = var_to_origin.get(&reg_var).unwrap_or_else(|| &RegionCtxt::Unknown);
270270
components[scc_idx.as_usize()].insert((reg_var, *origin));
@@ -298,8 +298,8 @@ fn sccs_info<'cx, 'tcx>(
298298

299299
let mut scc_node_to_edges = FxHashMap::default();
300300
for (scc_idx, repr) in components_representatives.iter() {
301-
let edges_range = sccs.scc_data.ranges[*scc_idx].clone();
302-
let edges = &sccs.scc_data.all_successors[edges_range];
301+
let edges_range = sccs.scc_data().ranges()[*scc_idx].clone();
302+
let edges = &sccs.scc_data().all_successors()[edges_range];
303303
let edge_representatives =
304304
edges.iter().map(|scc_idx| components_representatives[scc_idx]).collect::<Vec<_>>();
305305
scc_node_to_edges.insert((scc_idx, repr), edge_representatives);

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
130130
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),
131131
};
132132

133-
let reg_var = reg
134-
.try_get_var()
135-
.unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
133+
let reg_var =
134+
reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
136135
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
137136
let prev = var_to_origin.insert(reg_var, RegionCtxt::Placeholder(reg_info));
138137
assert!(matches!(prev, None));
@@ -147,9 +146,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
147146
universe,
148147
);
149148

150-
let reg_var = reg
151-
.try_get_var()
152-
.unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
149+
let reg_var =
150+
reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
153151

154152
if cfg!(debug_assertions) {
155153
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();

compiler/rustc_data_structures/src/graph/scc/mod.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,36 @@ mod tests;
2121
pub struct Sccs<N: Idx, S: Idx> {
2222
/// For each node, what is the SCC index of the SCC to which it
2323
/// belongs.
24-
pub scc_indices: IndexVec<N, S>,
24+
scc_indices: IndexVec<N, S>,
2525

2626
/// Data about each SCC.
27-
pub scc_data: SccData<S>,
27+
scc_data: SccData<S>,
2828
}
2929

3030
pub struct SccData<S: Idx> {
3131
/// For each SCC, the range of `all_successors` where its
3232
/// successors can be found.
33-
pub ranges: IndexVec<S, Range<usize>>,
33+
ranges: IndexVec<S, Range<usize>>,
3434

3535
/// Contains the successors for all the Sccs, concatenated. The
3636
/// range of indices corresponding to a given SCC is found in its
3737
/// SccData.
38-
pub all_successors: Vec<S>,
38+
all_successors: Vec<S>,
3939
}
4040

4141
impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
4242
pub fn new(graph: &(impl DirectedGraph<Node = N> + WithNumNodes + WithSuccessors)) -> Self {
4343
SccsConstruction::construct(graph)
4444
}
4545

46+
pub fn scc_indices(&self) -> &IndexVec<N, S> {
47+
&self.scc_indices
48+
}
49+
50+
pub fn scc_data(&self) -> &SccData<S> {
51+
&self.scc_data
52+
}
53+
4654
/// Returns the number of SCCs in the graph.
4755
pub fn num_sccs(&self) -> usize {
4856
self.scc_data.len()
@@ -115,6 +123,14 @@ impl<S: Idx> SccData<S> {
115123
self.ranges.len()
116124
}
117125

126+
pub fn ranges(&self) -> &IndexVec<S, Range<usize>> {
127+
&self.ranges
128+
}
129+
130+
pub fn all_successors(&self) -> &Vec<S> {
131+
&self.all_successors
132+
}
133+
118134
/// Returns the successors of the given SCC.
119135
fn successors(&self, scc: S) -> &[S] {
120136
// Annoyingly, `range` does not implement `Copy`, so we have

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ impl<'tcx> Region<'tcx> {
17521752
matches!(self.kind(), ty::ReVar(_))
17531753
}
17541754

1755-
pub fn try_get_var(self) -> Option<RegionVid> {
1755+
pub fn as_var(self) -> Option<RegionVid> {
17561756
match self.kind() {
17571757
ty::ReVar(vid) => Some(vid),
17581758
_ => None,

0 commit comments

Comments
 (0)