about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-06-20 21:11:27 +0100
committerDavid Wood <david@davidtw.co>2018-07-01 15:34:47 +0100
commit58a723209d170634ecc4f9be02e9bc3659541125 (patch)
tree6b706ac27920fc65555501cdd448efe30fb76c2d
parentfd0806618c259a31da2c7824610d3224e71dad34 (diff)
downloadrust-58a723209d170634ecc4f9be02e9bc3659541125.tar.gz
rust-58a723209d170634ecc4f9be02e9bc3659541125.zip
Switched to while let in DFS and deriving Ord on ConstraintCategory.
-rw-r--r--src/librustc_mir/borrow_check/nll/constraint_set.rs28
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/mod.rs9
2 files changed, 4 insertions, 33 deletions
diff --git a/src/librustc_mir/borrow_check/nll/constraint_set.rs b/src/librustc_mir/borrow_check/nll/constraint_set.rs
index 232242b552f..d8c26960a72 100644
--- a/src/librustc_mir/borrow_check/nll/constraint_set.rs
+++ b/src/librustc_mir/borrow_check/nll/constraint_set.rs
@@ -13,7 +13,6 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use borrow_check::nll::type_check::Locations;
 
 use std::fmt;
-use std::cmp::Ordering;
 use std::ops::Deref;
 
 #[derive(Clone, Default)]
@@ -112,7 +111,7 @@ impl fmt::Debug for OutlivesConstraint {
 
 /// Constraints that are considered interesting can be categorized to
 /// determine why they are interesting.
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
 crate enum ConstraintCategory {
     Assignment,
     CallArgument,
@@ -120,29 +119,4 @@ crate enum ConstraintCategory {
     Other,
 }
 
-impl Ord for ConstraintCategory {
-    fn cmp(&self, other: &Self) -> Ordering {
-        if self == other {
-            return Ordering::Equal;
-        }
-
-        match (self, other) {
-            (ConstraintCategory::Assignment, _) => Ordering::Greater,
-            (_, ConstraintCategory::Assignment) => Ordering::Less,
-            (ConstraintCategory::CallArgument, _) => Ordering::Greater,
-            (_, ConstraintCategory::CallArgument) => Ordering::Less,
-            (ConstraintCategory::Cast, _) => Ordering::Greater,
-            (_, ConstraintCategory::Cast) => Ordering::Less,
-            (ConstraintCategory::Other, _) => Ordering::Greater,
-        }
-    }
-}
-
-impl PartialOrd for ConstraintCategory {
-    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-        Some(self.cmp(other))
-    }
-}
-
-
 newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" });
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
index 713ff7002b3..d7e818c5043 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs
@@ -978,20 +978,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
 
         // Mapping of regions to the previous region and constraint index that led to it.
         let mut previous = FxHashMap();
-        // Current region in traversal.
-        let mut current = r0;
         // Regions yet to be visited.
-        let mut next = vec! [ current ];
+        let mut next = vec! [ r0 ];
         // Regions that have been visited.
         let mut visited = FxHashSet();
         // Ends of paths.
         let mut end_regions: Vec<RegionVid> = Vec::new();
 
         // When we've still got points to visit...
-        while !next.is_empty() {
+        while let Some(current) = next.pop() {
             // ...take the next point...
-            debug!("find_constraint_paths_from_region: next={:?}", next);
-            current = next.pop().unwrap(); // Can unwrap here as we know the vector is not empty.
+            debug!("find_constraint_paths_from_region: current={:?} next={:?}", current, next);
 
             // ...find the edges containing it...
             let mut upcoming = Vec::new();