diff --git a/src/librustc_data_structures/control_flow_graph/dominators/mod.rs b/src/librustc_data_structures/control_flow_graph/dominators/mod.rs index 250b89d12ed05..ab675db21503e 100644 --- a/src/librustc_data_structures/control_flow_graph/dominators/mod.rs +++ b/src/librustc_data_structures/control_flow_graph/dominators/mod.rs @@ -57,9 +57,9 @@ pub fn dominators_given_rpo(graph: &G, // (*) // (*) dominators for `pred` have been calculated new_idom = intersect_opt(&post_order_rank, - &immediate_dominators, - new_idom, - Some(pred)); + &immediate_dominators, + new_idom, + Some(pred)); } } @@ -77,10 +77,10 @@ pub fn dominators_given_rpo(graph: &G, } fn intersect_opt(post_order_rank: &IndexVec, - immediate_dominators: &IndexVec>, - node1: Option, - node2: Option) - -> Option { + immediate_dominators: &IndexVec>, + node1: Option, + node2: Option) + -> Option { match (node1, node2) { (None, None) => None, (Some(n), None) | (None, Some(n)) => Some(n), @@ -89,10 +89,10 @@ fn intersect_opt(post_order_rank: &IndexVec, } fn intersect(post_order_rank: &IndexVec, - immediate_dominators: &IndexVec>, - mut node1: Node, - mut node2: Node) - -> Node { + immediate_dominators: &IndexVec>, + mut node1: Node, + mut node2: Node) + -> Node { while node1 != node2 { while post_order_rank[node1] < post_order_rank[node2] { node1 = immediate_dominators[node1].unwrap(); @@ -142,9 +142,9 @@ impl Dominators { "node {:?} is not reachable", node2); intersect::(&self.post_order_rank, - &self.immediate_dominators, - node1, - node2) + &self.immediate_dominators, + node1, + node2) } pub fn mutual_dominator(&self, iter: I) -> Option diff --git a/src/librustc_data_structures/control_flow_graph/dominators/test.rs b/src/librustc_data_structures/control_flow_graph/dominators/test.rs index a6db5f2fe3ea1..0af878cac2df1 100644 --- a/src/librustc_data_structures/control_flow_graph/dominators/test.rs +++ b/src/librustc_data_structures/control_flow_graph/dominators/test.rs @@ -14,12 +14,7 @@ use super::*; #[test] fn diamond() { - let graph = TestGraph::new(0, &[ - (0, 1), - (0, 2), - (1, 3), - (2, 3), - ]); + let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); let dominators = dominators(&graph); let immediate_dominators = dominators.all_immediate_dominators(); @@ -32,17 +27,9 @@ fn diamond() { #[test] fn paper() { // example from the paper: - let graph = TestGraph::new(6, &[ - (6, 5), - (6, 4), - (5, 1), - (4, 2), - (4, 3), - (1, 2), - (2, 3), - (3, 2), - (2, 1), - ]); + let graph = TestGraph::new(6, + &[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2), + (2, 1)]); let dominators = dominators(&graph); let immediate_dominators = dominators.all_immediate_dominators(); @@ -54,4 +41,3 @@ fn paper() { assert_eq!(immediate_dominators[5], Some(6)); assert_eq!(immediate_dominators[6], Some(6)); } - diff --git a/src/librustc_data_structures/control_flow_graph/iterate/test.rs b/src/librustc_data_structures/control_flow_graph/iterate/test.rs index 28297d55bdf32..dca45602f17c4 100644 --- a/src/librustc_data_structures/control_flow_graph/iterate/test.rs +++ b/src/librustc_data_structures/control_flow_graph/iterate/test.rs @@ -15,12 +15,7 @@ use super::*; #[test] fn diamond_post_order() { - let graph = TestGraph::new(0, &[ - (0, 1), - (0, 2), - (1, 3), - (2, 3), - ]); + let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); let result = post_order_from(&graph, 0); assert_eq!(result, vec![3, 1, 2, 0]); @@ -33,16 +28,8 @@ fn rev_post_order_inner_loop() { // ^ ^ v | // | 6 <- 4 | // +-----------------+ - let graph = TestGraph::new(0, &[ - (0, 1), - (1, 2), - (2, 3), - (3, 5), - (3, 1), - (2, 4), - (4, 6), - (6, 2), - ]); + let graph = TestGraph::new(0, + &[(0, 1), (1, 2), (2, 3), (3, 5), (3, 1), (2, 4), (4, 6), (6, 2)]); let rev_graph = TransposedGraph::new(&graph); @@ -52,4 +39,3 @@ fn rev_post_order_inner_loop() { let result = post_order_from_to(&rev_graph, 3, Some(1)); assert_eq!(result, vec![4, 6, 2, 3]); } - diff --git a/src/librustc_data_structures/control_flow_graph/mod.rs b/src/librustc_data_structures/control_flow_graph/mod.rs index f9e75b12e0358..eb6839df6274f 100644 --- a/src/librustc_data_structures/control_flow_graph/mod.rs +++ b/src/librustc_data_structures/control_flow_graph/mod.rs @@ -36,10 +36,10 @@ pub trait ControlFlowGraph pub trait GraphPredecessors<'graph> { type Item; - type Iter: Iterator; + type Iter: Iterator; } pub trait GraphSuccessors<'graph> { type Item; - type Iter: Iterator; -} \ No newline at end of file + type Iter: Iterator; +} diff --git a/src/librustc_data_structures/control_flow_graph/reachable/mod.rs b/src/librustc_data_structures/control_flow_graph/reachable/mod.rs index e520e23f3afb8..24210ebb95d3d 100644 --- a/src/librustc_data_structures/control_flow_graph/reachable/mod.rs +++ b/src/librustc_data_structures/control_flow_graph/reachable/mod.rs @@ -19,8 +19,7 @@ use super::super::indexed_vec::{IndexVec, Idx}; #[cfg(test)] mod test; -pub fn reachable(graph: &G) - -> Reachability { +pub fn reachable(graph: &G) -> Reachability { let reverse_post_order = reverse_post_order(graph, graph.start_node()); reachable_given_rpo(graph, &reverse_post_order) } @@ -53,12 +52,10 @@ pub struct Reachability { impl Reachability { fn new(graph: &G) -> Self { let num_nodes = graph.num_nodes(); - Reachability { - bits: IndexVec::from_elem_n(BitVector::new(num_nodes), num_nodes), - } + Reachability { bits: IndexVec::from_elem_n(BitVector::new(num_nodes), num_nodes) } } - pub fn can_reach(&self, source: Node, target: Node)-> bool { + pub fn can_reach(&self, source: Node, target: Node) -> bool { let bit: usize = target.index(); self.bits[source].contains(bit) } diff --git a/src/librustc_data_structures/control_flow_graph/reachable/test.rs b/src/librustc_data_structures/control_flow_graph/reachable/test.rs index 6aa906a0804e2..ef45deeaafc78 100644 --- a/src/librustc_data_structures/control_flow_graph/reachable/test.rs +++ b/src/librustc_data_structures/control_flow_graph/reachable/test.rs @@ -17,15 +17,7 @@ fn test1() { // 0 -> 1 -> 2 -> 3 // ^ v // 6 <- 4 -> 5 - let graph = TestGraph::new(0, &[ - (0, 1), - (1, 2), - (2, 3), - (2, 4), - (4, 5), - (4, 6), - (6, 1), - ]); + let graph = TestGraph::new(0, &[(0, 1), (1, 2), (2, 3), (2, 4), (4, 5), (4, 6), (6, 1)]); let reachable = reachable(&graph); assert!((0..6).all(|i| reachable.can_reach(0, i))); assert!((1..6).all(|i| reachable.can_reach(1, i))); @@ -43,15 +35,9 @@ fn test2() { // 30 -> 31 -> 32 -> 33 // ^ v // 36 <- 34 -> 35 - let graph = TestGraph::new(30, &[ - (30, 31), - (31, 32), - (32, 33), - (32, 34), - (34, 35), - (34, 36), - (36, 31), - ]); + let graph = TestGraph::new(30, + &[(30, 31), (31, 32), (32, 33), (32, 34), (34, 35), (34, 36), + (36, 31)]); let reachable = reachable(&graph); assert!((30..36).all(|i| reachable.can_reach(30, i))); assert!((31..36).all(|i| reachable.can_reach(31, i))); diff --git a/src/librustc_data_structures/control_flow_graph/reference.rs b/src/librustc_data_structures/control_flow_graph/reference.rs index d735be1ed2f54..3b8b01f2ff43b 100644 --- a/src/librustc_data_structures/control_flow_graph/reference.rs +++ b/src/librustc_data_structures/control_flow_graph/reference.rs @@ -21,13 +21,13 @@ impl<'graph, G: ControlFlowGraph> ControlFlowGraph for &'graph G { (**self).start_node() } - fn predecessors<'iter>(&'iter self, node: Self::Node) - -> >::Iter { + fn predecessors<'iter>(&'iter self, + node: Self::Node) + -> >::Iter { (**self).predecessors(node) } - fn successors<'iter>(&'iter self, node: Self::Node) - -> >::Iter { + fn successors<'iter>(&'iter self, node: Self::Node) -> >::Iter { (**self).successors(node) } } diff --git a/src/librustc_data_structures/control_flow_graph/test.rs b/src/librustc_data_structures/control_flow_graph/test.rs index 57b2a858de568..d48a6e684ad8e 100644 --- a/src/librustc_data_structures/control_flow_graph/test.rs +++ b/src/librustc_data_structures/control_flow_graph/test.rs @@ -28,7 +28,7 @@ impl TestGraph { num_nodes: start_node + 1, start_node: start_node, successors: HashMap::new(), - predecessors: HashMap::new() + predecessors: HashMap::new(), }; for &(source, target) in edges { graph.num_nodes = max(graph.num_nodes, source + 1); @@ -55,13 +55,13 @@ impl ControlFlowGraph for TestGraph { self.num_nodes } - fn predecessors<'graph>(&'graph self, node: usize) + fn predecessors<'graph>(&'graph self, + node: usize) -> >::Iter { - self.predecessors[&node].iter().cloned() + self.predecessors[&node].iter().cloned() } - fn successors<'graph>(&'graph self, node: usize) - -> >::Iter { + fn successors<'graph>(&'graph self, node: usize) -> >::Iter { self.successors[&node].iter().cloned() } } @@ -75,4 +75,3 @@ impl<'graph> GraphSuccessors<'graph> for TestGraph { type Item = usize; type Iter = iter::Cloned>; } - diff --git a/src/librustc_data_structures/control_flow_graph/transpose.rs b/src/librustc_data_structures/control_flow_graph/transpose.rs index 792e079c28c85..a1a117edb94fc 100644 --- a/src/librustc_data_structures/control_flow_graph/transpose.rs +++ b/src/librustc_data_structures/control_flow_graph/transpose.rs @@ -22,7 +22,10 @@ impl TransposedGraph { } pub fn with_start(base_graph: G, start_node: G::Node) -> Self { - TransposedGraph { base_graph: base_graph, start_node: start_node } + TransposedGraph { + base_graph: base_graph, + start_node: start_node, + } } } @@ -37,12 +40,14 @@ impl ControlFlowGraph for TransposedGraph { self.start_node } - fn predecessors<'graph>(&'graph self, node: Self::Node) + fn predecessors<'graph>(&'graph self, + node: Self::Node) -> >::Iter { self.base_graph.successors(node) } - fn successors<'graph>(&'graph self, node: Self::Node) + fn successors<'graph>(&'graph self, + node: Self::Node) -> >::Iter { self.base_graph.predecessors(node) }