Skip to content

Commit 14dffd5

Browse files
committed
do not add nodes that already exist
1 parent e1d9f37 commit 14dffd5

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

chalk-solve/src/coherence.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,19 @@ where
107107

108108
// Build the forest of specialization relationships.
109109
fn build_specialization_forest(&self) -> Result<Graph<ImplId<I>, ()>, CoherenceError<I>> {
110-
// FIXME(pierwill): Previously, the forest was built as a GraphMap
111-
// so that we never add multiple nodes with the same ItemId.
112-
// Will need to add a check for this.
113110
let mut forest = DiGraph::new();
114111

115112
// Find all specializations (implemented in coherence/solve)
116113
// Record them in the forest by adding an edge from the less special
117114
// to the more special.
118115
self.visit_specializations_of_trait(|less_special, more_special| {
119-
let nodes = forest.raw_nodes();
120-
let mut goodnodes: Vec<ImplId<_>> = vec![];
116+
let node_impls: Vec<ImplId<_>> = forest.raw_nodes().iter().map(|x| x.weight).collect();
121117

122-
for node in nodes {
123-
goodnodes.push(node.weight);
124-
}
125-
126-
if !goodnodes.contains(&less_special) && !goodnodes.contains(&more_special) {
118+
// Check so that we never add multiple nodes with the same ImplId.
119+
if !node_impls.contains(&less_special) && !node_impls.contains(&more_special) {
127120
let l = forest.add_node(less_special);
128121
let m = forest.add_node(more_special);
129122

130-
#[rustfmt::skip]
131-
println!( "adding an edge from {:?} to {:?}", less_special, more_special );
132123
forest.add_edge(l, m, ());
133124
}
134125
})?;

0 commit comments

Comments
 (0)