]> git.lizzy.rs Git - rust.git/commitdiff
region_inference: tighten up `pub`, stop re-exporting enum variants
authorNiko Matsakis <niko@alum.mit.edu>
Sun, 5 Nov 2017 10:23:30 +0000 (05:23 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 16 Nov 2017 10:57:41 +0000 (05:57 -0500)
src/librustc/infer/error_reporting/mod.rs
src/librustc/infer/lexical_region_resolve/graphviz.rs
src/librustc/infer/lexical_region_resolve/mod.rs
src/librustc/infer/region_inference/mod.rs

index c262e966576bd29aa4ec22d14ec60102143b4cff..072f76eb6aa8da973c6314f1c9f1b30a120306fc 100644 (file)
@@ -57,8 +57,7 @@
 
 use infer;
 use super::{InferCtxt, TypeTrace, SubregionOrigin, RegionVariableOrigin, ValuePairs};
-use super::region_inference::{RegionResolutionError, ConcreteFailure, SubSupConflict,
-                              GenericBoundFailure, GenericKind};
+use super::region_inference::{RegionResolutionError, GenericKind};
 
 use std::fmt;
 use hir;
@@ -293,33 +292,37 @@ pub fn report_region_errors(&self,
             debug!("report_region_errors: error = {:?}", error);
 
             if !self.try_report_named_anon_conflict(&error) &&
-               !self.try_report_anon_anon_conflict(&error) {
-
-               match error.clone() {
-                  // These errors could indicate all manner of different
-                  // problems with many different solutions. Rather
-                  // than generate a "one size fits all" error, what we
-                  // attempt to do is go through a number of specific
-                  // scenarios and try to find the best way to present
-                  // the error. If all of these fails, we fall back to a rather
-                  // general bit of code that displays the error information
-                  ConcreteFailure(origin, sub, sup) => {
-                      self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
-                  }
-
-                  GenericBoundFailure(kind, param_ty, sub) => {
-                      self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
-                  }
-
-                  SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
+                !self.try_report_anon_anon_conflict(&error)
+            {
+                match error.clone() {
+                    // These errors could indicate all manner of different
+                    // problems with many different solutions. Rather
+                    // than generate a "one size fits all" error, what we
+                    // attempt to do is go through a number of specific
+                    // scenarios and try to find the best way to present
+                    // the error. If all of these fails, we fall back to a rather
+                    // general bit of code that displays the error information
+                    RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
+                        self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
+                    }
+
+                    RegionResolutionError::GenericBoundFailure(kind, param_ty, sub) => {
+                        self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
+                    }
+
+                    RegionResolutionError::SubSupConflict(var_origin,
+                                                          sub_origin,
+                                                          sub_r,
+                                                          sup_origin,
+                                                          sup_r) => {
                         self.report_sub_sup_conflict(region_scope_tree,
                                                      var_origin,
                                                      sub_origin,
                                                      sub_r,
                                                      sup_origin,
                                                      sup_r);
-                  }
-               }
+                    }
+                }
             }
         }
     }
@@ -351,9 +354,9 @@ fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
         // the only thing in the list.
 
         let is_bound_failure = |e: &RegionResolutionError<'tcx>| match *e {
-            ConcreteFailure(..) => false,
-            SubSupConflict(..) => false,
-            GenericBoundFailure(..) => true,
+            RegionResolutionError::GenericBoundFailure(..) => true,
+            RegionResolutionError::ConcreteFailure(..) |
+            RegionResolutionError::SubSupConflict(..) => false,
         };
 
 
@@ -365,9 +368,9 @@ fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
 
         // sort the errors by span, for better error message stability.
         errors.sort_by_key(|u| match *u {
-            ConcreteFailure(ref sro, _, _) => sro.span(),
-            GenericBoundFailure(ref sro, _, _) => sro.span(),
-            SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
+            RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
+            RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
+            RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),
         });
         errors
     }
index efe364166e4be6c14f7fcf08f5645a492cec8614..403ff3c4dfa218671987eac7edc69e9267bd4ff5 100644 (file)
@@ -212,13 +212,13 @@ fn edge_label(&self, e: &Edge) -> dot::LabelText {
 
 fn constraint_to_nodes(c: &Constraint) -> (Node, Node) {
     match *c {
-        Constraint::ConstrainVarSubVar(rv_1, rv_2) =>
+        Constraint::VarSubVar(rv_1, rv_2) =>
             (Node::RegionVid(rv_1), Node::RegionVid(rv_2)),
-        Constraint::ConstrainRegSubVar(r_1, rv_2) =>
+        Constraint::RegSubVar(r_1, rv_2) =>
             (Node::Region(*r_1), Node::RegionVid(rv_2)),
-        Constraint::ConstrainVarSubReg(rv_1, r_2) =>
+        Constraint::VarSubReg(rv_1, r_2) =>
             (Node::RegionVid(rv_1), Node::Region(*r_2)),
-        Constraint::ConstrainRegSubReg(r_1, r_2) =>
+        Constraint::RegSubReg(r_1, r_2) =>
             (Node::Region(*r_1), Node::Region(*r_2)),
     }
 }
index 8c5d7a7fc9b02420f3e94c90cb12398af8c722a0..682f5743e4bff8e7768f6b0a1fd3b589ca53c8a3 100644 (file)
@@ -12,7 +12,6 @@
 
 use infer::SubregionOrigin;
 use infer::region_inference::Constraint;
-use infer::region_inference::Constraint::*;
 use infer::region_inference::RegionVarBindings;
 use infer::region_inference::RegionResolutionError;
 use infer::region_inference::VarValue;
@@ -230,18 +229,18 @@ fn expansion(
         self.iterate_until_fixed_point("Expansion", |constraint, origin| {
             debug!("expansion: constraint={:?} origin={:?}", constraint, origin);
             match *constraint {
-                ConstrainRegSubVar(a_region, b_vid) => {
+                Constraint::RegSubVar(a_region, b_vid) => {
                     let b_data = &mut var_values[b_vid.index as usize];
                     self.expand_node(region_rels, a_region, b_vid, b_data)
                 }
-                ConstrainVarSubVar(a_vid, b_vid) => match var_values[a_vid.index as usize] {
+                Constraint::VarSubVar(a_vid, b_vid) => match var_values[a_vid.index as usize] {
                     VarValue::ErrorValue => false,
                     VarValue::Value(a_region) => {
                         let b_node = &mut var_values[b_vid.index as usize];
                         self.expand_node(region_rels, a_region, b_vid, b_node)
                     }
                 },
-                ConstrainRegSubReg(..) | ConstrainVarSubReg(..) => {
+                Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
                     // These constraints are checked after expansion
                     // is done, in `collect_errors`.
                     false
@@ -311,11 +310,11 @@ fn collect_errors(
                 origin
             );
             match *constraint {
-                ConstrainRegSubVar(..) | ConstrainVarSubVar(..) => {
+                Constraint::RegSubVar(..) | Constraint::VarSubVar(..) => {
                     // Expansion will ensure that these constraints hold. Ignore.
                 }
 
-                ConstrainRegSubReg(sub, sup) => {
+                Constraint::RegSubReg(sub, sup) => {
                     if region_rels.is_subregion_of(sub, sup) {
                         continue;
                     }
@@ -331,7 +330,7 @@ fn collect_errors(
                     errors.push(RegionResolutionError::ConcreteFailure((*origin).clone(), sub, sup));
                 }
 
-                ConstrainVarSubReg(a_vid, b_region) => {
+                Constraint::VarSubReg(a_vid, b_region) => {
                     let a_data = &mut var_data[a_vid.index as usize];
                     debug!("contraction: {:?} == {:?}, {:?}", a_vid, a_data, b_region);
 
@@ -473,20 +472,20 @@ fn construct_graph(&self) -> RegionGraph<'tcx> {
 
         for (constraint, _) in constraints.iter() {
             match *constraint {
-                ConstrainVarSubVar(a_id, b_id) => {
+                Constraint::VarSubVar(a_id, b_id) => {
                     graph.add_edge(
                         NodeIndex(a_id.index as usize),
                         NodeIndex(b_id.index as usize),
                         *constraint,
                     );
                 }
-                ConstrainRegSubVar(_, b_id) => {
+                Constraint::RegSubVar(_, b_id) => {
                     graph.add_edge(dummy_source, NodeIndex(b_id.index as usize), *constraint);
                 }
-                ConstrainVarSubReg(a_id, _) => {
+                Constraint::VarSubReg(a_id, _) => {
                     graph.add_edge(NodeIndex(a_id.index as usize), dummy_sink, *constraint);
                 }
-                ConstrainRegSubReg(..) => {
+                Constraint::RegSubReg(..) => {
                     // this would be an edge from `dummy_source` to
                     // `dummy_sink`; just ignore it.
                 }
@@ -624,7 +623,7 @@ fn process_edges<'a, 'gcx, 'tcx>(
             let source_node_index = NodeIndex(source_vid.index as usize);
             for (_, edge) in graph.adjacent_edges(source_node_index, dir) {
                 match edge.data {
-                    ConstrainVarSubVar(from_vid, to_vid) => {
+                    Constraint::VarSubVar(from_vid, to_vid) => {
                         let opp_vid = if from_vid == source_vid {
                             to_vid
                         } else {
@@ -635,14 +634,14 @@ fn process_edges<'a, 'gcx, 'tcx>(
                         }
                     }
 
-                    ConstrainRegSubVar(region, _) | ConstrainVarSubReg(_, region) => {
+                    Constraint::RegSubVar(region, _) | Constraint::VarSubReg(_, region) => {
                         state.result.push(RegionAndOrigin {
                             region,
                             origin: this.constraints.borrow().get(&edge.data).unwrap().clone(),
                         });
                     }
 
-                    ConstrainRegSubReg(..) => panic!(
+                    Constraint::RegSubReg(..) => panic!(
                         "cannot reach reg-sub-reg edge in region inference \
                          post-processing"
                     ),
index e197f4f27ef16b56fe567f6535794065c9d2b01c..ef888ea4b9f0106dab115c0a04a65ae03ab3a479 100644 (file)
 
 //! See README.md
 
-pub use self::Constraint::*;
-pub use self::UndoLogEntry::*;
-pub use self::CombineMapType::*;
-pub use self::RegionResolutionError::*;
-pub use self::VarValue::*;
+use self::UndoLogEntry::*;
+use self::CombineMapType::*;
 
 use super::{RegionVariableOrigin, SubregionOrigin, MiscVariable};
 use super::unify_key;
 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
 pub enum Constraint<'tcx> {
     /// One region variable is subregion of another
-    ConstrainVarSubVar(RegionVid, RegionVid),
+    VarSubVar(RegionVid, RegionVid),
 
     /// Concrete region is subregion of region variable
-    ConstrainRegSubVar(Region<'tcx>, RegionVid),
+    RegSubVar(Region<'tcx>, RegionVid),
 
     /// Region variable is subregion of concrete region. This does not
     /// directly affect inference, but instead is checked after
     /// inference is complete.
-    ConstrainVarSubReg(RegionVid, Region<'tcx>),
+    VarSubReg(RegionVid, Region<'tcx>),
 
     /// A constraint where neither side is a variable. This does not
     /// directly affect inference, but instead is checked after
     /// inference is complete.
-    ConstrainRegSubReg(Region<'tcx>, Region<'tcx>),
+    RegSubReg(Region<'tcx>, Region<'tcx>),
 }
 
 /// VerifyGenericBound(T, _, R, RS): The parameter type `T` (or
@@ -98,13 +95,13 @@ pub enum VerifyBound<'tcx> {
 }
 
 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
-pub struct TwoRegions<'tcx> {
+struct TwoRegions<'tcx> {
     a: Region<'tcx>,
     b: Region<'tcx>,
 }
 
 #[derive(Copy, Clone, PartialEq)]
-pub enum UndoLogEntry<'tcx> {
+enum UndoLogEntry<'tcx> {
     /// Pushed when we start a snapshot.
     OpenSnapshot,
 
@@ -138,7 +135,7 @@ pub enum UndoLogEntry<'tcx> {
 }
 
 #[derive(Copy, Clone, PartialEq)]
-pub enum CombineMapType {
+enum CombineMapType {
     Lub,
     Glb,
 }
@@ -168,19 +165,13 @@ pub enum RegionResolutionError<'tcx> {
                    Region<'tcx>),
 }
 
-#[derive(Clone, Debug)]
-pub enum ProcessedErrorOrigin<'tcx> {
-    ConcreteFailure(SubregionOrigin<'tcx>, Region<'tcx>, Region<'tcx>),
-    VariableFailure(RegionVariableOrigin),
-}
-
 #[derive(Copy, Clone, Debug)]
 pub enum VarValue<'tcx> {
     Value(Region<'tcx>),
     ErrorValue,
 }
 
-pub type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
+type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
 
 pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
     pub(in infer) tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -426,7 +417,7 @@ pub fn rollback_to(&self, snapshot: RegionSnapshot) {
             .rollback_to(snapshot.region_snapshot);
     }
 
-    pub fn rollback_undo_entry(&self, undo_entry: UndoLogEntry<'tcx>) {
+    fn rollback_undo_entry(&self, undo_entry: UndoLogEntry<'tcx>) {
         match undo_entry {
             OpenSnapshot => {
                 panic!("Failure to observe stack discipline");
@@ -578,13 +569,13 @@ fn kill_constraint<'tcx>(skols: &FxHashSet<ty::Region<'tcx>>,
                                  undo_entry: &UndoLogEntry<'tcx>)
                                  -> bool {
             match undo_entry {
-                &AddConstraint(ConstrainVarSubVar(..)) =>
+                &AddConstraint(Constraint::VarSubVar(..)) =>
                     false,
-                &AddConstraint(ConstrainRegSubVar(a, _)) =>
+                &AddConstraint(Constraint::RegSubVar(a, _)) =>
                     skols.contains(&a),
-                &AddConstraint(ConstrainVarSubReg(_, b)) =>
+                &AddConstraint(Constraint::VarSubReg(_, b)) =>
                     skols.contains(&b),
-                &AddConstraint(ConstrainRegSubReg(a, b)) =>
+                &AddConstraint(Constraint::RegSubReg(a, b)) =>
                     skols.contains(&a) || skols.contains(&b),
                 &AddGiven(..) =>
                     false,
@@ -725,16 +716,16 @@ pub fn make_subregion(&self,
                 // all regions are subregions of static, so we can ignore this
             }
             (&ReVar(sub_id), &ReVar(sup_id)) => {
-                self.add_constraint(ConstrainVarSubVar(sub_id, sup_id), origin);
+                self.add_constraint(Constraint::VarSubVar(sub_id, sup_id), origin);
             }
             (_, &ReVar(sup_id)) => {
-                self.add_constraint(ConstrainRegSubVar(sub, sup_id), origin);
+                self.add_constraint(Constraint::RegSubVar(sub, sup_id), origin);
             }
             (&ReVar(sub_id), _) => {
-                self.add_constraint(ConstrainVarSubReg(sub_id, sup), origin);
+                self.add_constraint(Constraint::VarSubReg(sub_id, sup), origin);
             }
             _ => {
-                self.add_constraint(ConstrainRegSubReg(sub, sup), origin);
+                self.add_constraint(Constraint::RegSubReg(sub, sup), origin);
             }
         }
     }
@@ -817,13 +808,13 @@ fn combine_map(&self, t: CombineMapType) -> &RefCell<CombineMap<'tcx>> {
         }
     }
 
-    pub fn combine_vars<F>(&self,
-                           t: CombineMapType,
-                           a: Region<'tcx>,
-                           b: Region<'tcx>,
-                           origin: SubregionOrigin<'tcx>,
-                           mut relate: F)
-                           -> Region<'tcx>
+    fn combine_vars<F>(&self,
+                       t: CombineMapType,
+                       a: Region<'tcx>,
+                       b: Region<'tcx>,
+                       origin: SubregionOrigin<'tcx>,
+                       mut relate: F)
+                       -> Region<'tcx>
         where F: FnMut(&RegionVarBindings<'a, 'gcx, 'tcx>, Region<'tcx>, Region<'tcx>)
     {
         let vars = TwoRegions { a: a, b: b };