Skip to content

Commit 58a7232

Browse files
committed
Switched to while let in DFS and deriving Ord on ConstraintCategory.
1 parent fd08066 commit 58a7232

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

src/librustc_mir/borrow_check/nll/constraint_set.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1313
use borrow_check::nll::type_check::Locations;
1414

1515
use std::fmt;
16-
use std::cmp::Ordering;
1716
use std::ops::Deref;
1817

1918
#[derive(Clone, Default)]
@@ -112,37 +111,12 @@ impl fmt::Debug for OutlivesConstraint {
112111

113112
/// Constraints that are considered interesting can be categorized to
114113
/// determine why they are interesting.
115-
#[derive(Debug, Eq, PartialEq)]
114+
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
116115
crate enum ConstraintCategory {
117116
Assignment,
118117
CallArgument,
119118
Cast,
120119
Other,
121120
}
122121

123-
impl Ord for ConstraintCategory {
124-
fn cmp(&self, other: &Self) -> Ordering {
125-
if self == other {
126-
return Ordering::Equal;
127-
}
128-
129-
match (self, other) {
130-
(ConstraintCategory::Assignment, _) => Ordering::Greater,
131-
(_, ConstraintCategory::Assignment) => Ordering::Less,
132-
(ConstraintCategory::CallArgument, _) => Ordering::Greater,
133-
(_, ConstraintCategory::CallArgument) => Ordering::Less,
134-
(ConstraintCategory::Cast, _) => Ordering::Greater,
135-
(_, ConstraintCategory::Cast) => Ordering::Less,
136-
(ConstraintCategory::Other, _) => Ordering::Greater,
137-
}
138-
}
139-
}
140-
141-
impl PartialOrd for ConstraintCategory {
142-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
143-
Some(self.cmp(other))
144-
}
145-
}
146-
147-
148122
newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" });

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,20 +978,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
978978

979979
// Mapping of regions to the previous region and constraint index that led to it.
980980
let mut previous = FxHashMap();
981-
// Current region in traversal.
982-
let mut current = r0;
983981
// Regions yet to be visited.
984-
let mut next = vec! [ current ];
982+
let mut next = vec! [ r0 ];
985983
// Regions that have been visited.
986984
let mut visited = FxHashSet();
987985
// Ends of paths.
988986
let mut end_regions: Vec<RegionVid> = Vec::new();
989987

990988
// When we've still got points to visit...
991-
while !next.is_empty() {
989+
while let Some(current) = next.pop() {
992990
// ...take the next point...
993-
debug!("find_constraint_paths_from_region: next={:?}", next);
994-
current = next.pop().unwrap(); // Can unwrap here as we know the vector is not empty.
991+
debug!("find_constraint_paths_from_region: current={:?} next={:?}", current, next);
995992

996993
// ...find the edges containing it...
997994
let mut upcoming = Vec::new();

0 commit comments

Comments
 (0)