@@ -110,16 +110,47 @@ where
110110
111111 let node_impls: Vec < ImplId < _ > > = forest. raw_nodes ( ) . iter ( ) . map ( |x| x. weight ) . collect ( ) ;
112112
113- // Find all specializations (implemented in coherence/solve)
114- // Record them in the forest by adding an edge from the less special
115- // to the more special.
113+ // Find all specializations. Record them in the forest
114+ // by adding an edge from the less special to the more special.
116115 self . visit_specializations_of_trait ( |less_special, more_special| {
117- // Check so that we never add multiple nodes with the same ImplId.
118- if !node_impls. contains ( & less_special) && !node_impls. contains ( & more_special) {
119- let l = forest. add_node ( less_special) ;
120- let m = forest. add_node ( more_special) ;
121-
122- forest. add_edge ( l, m, ( ) ) ;
116+ match (
117+ node_impls. contains ( & less_special) ,
118+ node_impls. contains ( & more_special) ,
119+ ) {
120+ ( true , true ) => {
121+ // but how do we get indices for l and m?
122+ let l = forest
123+ . node_indices ( )
124+ . find ( |i| forest[ * i] == less_special)
125+ . unwrap ( ) ;
126+ let m = forest
127+ . node_indices ( )
128+ . find ( |i| forest[ * i] == more_special)
129+ . unwrap ( ) ;
130+ forest. add_edge ( l, m, ( ) ) ;
131+ }
132+ ( true , false ) => {
133+ let m = forest. add_node ( more_special) ;
134+ let l = forest
135+ . node_indices ( )
136+ . find ( |i| forest[ * i] == less_special)
137+ . unwrap ( ) ;
138+ forest. add_edge ( l, m, ( ) ) ;
139+ }
140+ ( false , true ) => {
141+ let l = forest. add_node ( less_special) ;
142+ let m = forest
143+ . node_indices ( )
144+ . find ( |i| forest[ * i] == more_special)
145+ . unwrap ( ) ;
146+ forest. add_edge ( l, m, ( ) ) ;
147+ }
148+ ( false , false ) => {
149+ // add L and M
150+ let l = forest. add_node ( less_special) ;
151+ let m = forest. add_node ( more_special) ;
152+ forest. add_edge ( l, m, ( ) ) ;
153+ }
123154 }
124155 } ) ?;
125156
0 commit comments