about summary refs log tree commit diff
diff options
context:
space:
mode:
authorb-naber <b_naber@gmx.de>2023-02-21 21:54:53 +0000
committerb-naber <b_naber@gmx.de>2023-02-21 21:54:53 +0000
commit8252a6eddfc59328fe6ac36ef09feb2844f28fa2 (patch)
tree784b84ea334cbabc7b71dbaf993ee17c6b0f20f3
parentc9843d61440edb19642920f2f8f33652e9c83971 (diff)
downloadrust-8252a6eddfc59328fe6ac36ef09feb2844f28fa2.tar.gz
rust-8252a6eddfc59328fe6ac36ef09feb2844f28fa2.zip
address review
-rw-r--r--compiler/rustc_borrowck/src/lib.rs4
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs8
-rw-r--r--compiler/rustc_borrowck/src/type_check/relate_tys.rs10
-rw-r--r--compiler/rustc_data_structures/src/graph/scc/mod.rs24
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs2
5 files changed, 31 insertions, 17 deletions
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index aedc030ea0a..622b57c7b7f 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -505,7 +505,7 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
     {
         let next_region = self.infcx.next_region_var(origin);
         let vid = next_region
-            .try_get_var()
+            .as_var()
             .unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
 
         if cfg!(debug_assertions) {
@@ -534,7 +534,7 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
     {
         let next_region = self.infcx.next_nll_region_var(origin.clone());
         let vid = next_region
-            .try_get_var()
+            .as_var()
             .unwrap_or_else(|| bug!("expected RegionKind::RegionVar on {:?}", next_region));
 
         if cfg!(debug_assertions) {
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs
index b2548b61cc5..8c374c2164c 100644
--- a/compiler/rustc_borrowck/src/region_infer/mod.rs
+++ b/compiler/rustc_borrowck/src/region_infer/mod.rs
@@ -261,10 +261,10 @@ fn sccs_info<'cx, 'tcx>(
     }
     debug!(debug_str);
 
-    let num_components = sccs.scc_data.ranges.len();
+    let num_components = sccs.scc_data().ranges().len();
     let mut components = vec![FxHashSet::default(); num_components];
 
-    for (reg_var_idx, scc_idx) in sccs.scc_indices.iter().enumerate() {
+    for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() {
         let reg_var = ty::RegionVid::from_usize(reg_var_idx);
         let origin = var_to_origin.get(&reg_var).unwrap_or_else(|| &RegionCtxt::Unknown);
         components[scc_idx.as_usize()].insert((reg_var, *origin));
@@ -298,8 +298,8 @@ fn sccs_info<'cx, 'tcx>(
 
     let mut scc_node_to_edges = FxHashMap::default();
     for (scc_idx, repr) in components_representatives.iter() {
-        let edges_range = sccs.scc_data.ranges[*scc_idx].clone();
-        let edges = &sccs.scc_data.all_successors[edges_range];
+        let edges_range = sccs.scc_data().ranges()[*scc_idx].clone();
+        let edges = &sccs.scc_data().all_successors()[edges_range];
         let edge_representatives =
             edges.iter().map(|scc_idx| components_representatives[scc_idx]).collect::<Vec<_>>();
         scc_node_to_edges.insert((scc_idx, repr), edge_representatives);
diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs
index 1ea3dccc910..d96372fb99b 100644
--- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs
+++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs
@@ -130,9 +130,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
             ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),
         };
 
-        let reg_var = reg
-            .try_get_var()
-            .unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
+        let reg_var =
+            reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
         let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
         let prev = var_to_origin.insert(reg_var, RegionCtxt::Placeholder(reg_info));
         assert!(matches!(prev, None));
@@ -147,9 +146,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
             universe,
         );
 
-        let reg_var = reg
-            .try_get_var()
-            .unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
+        let reg_var =
+            reg.as_var().unwrap_or_else(|| bug!("expected region {:?} to be of kind ReVar", reg));
 
         if cfg!(debug_assertions) {
             let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
diff --git a/compiler/rustc_data_structures/src/graph/scc/mod.rs b/compiler/rustc_data_structures/src/graph/scc/mod.rs
index e2fe5285aad..c4b11951ab7 100644
--- a/compiler/rustc_data_structures/src/graph/scc/mod.rs
+++ b/compiler/rustc_data_structures/src/graph/scc/mod.rs
@@ -21,21 +21,21 @@ mod tests;
 pub struct Sccs<N: Idx, S: Idx> {
     /// For each node, what is the SCC index of the SCC to which it
     /// belongs.
-    pub scc_indices: IndexVec<N, S>,
+    scc_indices: IndexVec<N, S>,
 
     /// Data about each SCC.
-    pub scc_data: SccData<S>,
+    scc_data: SccData<S>,
 }
 
 pub struct SccData<S: Idx> {
     /// For each SCC, the range of `all_successors` where its
     /// successors can be found.
-    pub ranges: IndexVec<S, Range<usize>>,
+    ranges: IndexVec<S, Range<usize>>,
 
     /// Contains the successors for all the Sccs, concatenated. The
     /// range of indices corresponding to a given SCC is found in its
     /// SccData.
-    pub all_successors: Vec<S>,
+    all_successors: Vec<S>,
 }
 
 impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
@@ -43,6 +43,14 @@ impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
         SccsConstruction::construct(graph)
     }
 
+    pub fn scc_indices(&self) -> &IndexVec<N, S> {
+        &self.scc_indices
+    }
+
+    pub fn scc_data(&self) -> &SccData<S> {
+        &self.scc_data
+    }
+
     /// Returns the number of SCCs in the graph.
     pub fn num_sccs(&self) -> usize {
         self.scc_data.len()
@@ -115,6 +123,14 @@ impl<S: Idx> SccData<S> {
         self.ranges.len()
     }
 
+    pub fn ranges(&self) -> &IndexVec<S, Range<usize>> {
+        &self.ranges
+    }
+
+    pub fn all_successors(&self) -> &Vec<S> {
+        &self.all_successors
+    }
+
     /// Returns the successors of the given SCC.
     fn successors(&self, scc: S) -> &[S] {
         // Annoyingly, `range` does not implement `Copy`, so we have
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index c5d6df5b1ad..35ff71d8885 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -1752,7 +1752,7 @@ impl<'tcx> Region<'tcx> {
         matches!(self.kind(), ty::ReVar(_))
     }
 
-    pub fn try_get_var(self) -> Option<RegionVid> {
+    pub fn as_var(self) -> Option<RegionVid> {
         match self.kind() {
             ty::ReVar(vid) => Some(vid),
             _ => None,