@@ -16,8 +16,8 @@ use std::collections::hash_map::Entry;
16
16
use std:: collections:: { BTreeMap , btree_map} ;
17
17
use std:: fmt:: Debug ;
18
18
use std:: hash:: Hash ;
19
+ use std:: iter;
19
20
use std:: marker:: PhantomData ;
20
- use std:: { iter, mem} ;
21
21
22
22
use derive_where:: derive_where;
23
23
#[ cfg( feature = "nightly" ) ]
@@ -229,16 +229,19 @@ impl Usages {
229
229
230
230
#[ derive( Debug , Default ) ]
231
231
pub struct CandidateUsages {
232
- usages : HashMap < StackDepth , Usages > ,
232
+ usages : Option < Box < HashMap < StackDepth , Usages > > > ,
233
233
}
234
234
impl CandidateUsages {
235
- pub fn add_usages ( & mut self , mut other : CandidateUsages ) {
236
- if self . usages . is_empty ( ) {
237
- mem:: swap ( self , & mut other) ;
238
- }
239
- #[ allow( rustc:: potential_query_instability) ]
240
- for ( head_index, head) in other. usages {
241
- self . usages . entry ( head_index) . or_default ( ) . add_usages ( head) ;
235
+ pub fn add_usages ( & mut self , other : CandidateUsages ) {
236
+ if let Some ( other_usages) = other. usages {
237
+ if let Some ( ref mut self_usages) = self . usages {
238
+ #[ allow( rustc:: potential_query_instability) ]
239
+ for ( head_index, head) in other_usages. into_iter ( ) {
240
+ self_usages. entry ( head_index) . or_default ( ) . add_usages ( head) ;
241
+ }
242
+ } else {
243
+ self . usages = Some ( other_usages) ;
244
+ }
242
245
}
243
246
}
244
247
}
@@ -604,6 +607,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
604
607
if let Some ( candidate_usages) = & mut parent. candidate_usages {
605
608
candidate_usages
606
609
. usages
610
+ . get_or_insert_default ( )
607
611
. entry ( head_index)
608
612
. or_default ( )
609
613
. add_usages ( head. usages . compressed ( ) ) ;
@@ -682,13 +686,15 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
682
686
}
683
687
684
688
pub fn ignore_candidate_usages ( & mut self , usages : CandidateUsages ) {
685
- let ( entry_index, entry) = self . stack . last_mut_with_index ( ) . unwrap ( ) ;
686
- #[ allow( rustc:: potential_query_instability) ]
687
- for ( head_index, usages) in usages. usages {
688
- if head_index == entry_index {
689
- entry. usages . unwrap ( ) . ignore_usages ( usages) ;
690
- } else {
691
- entry. heads . ignore_usages ( head_index, usages) ;
689
+ if let Some ( usages) = usages. usages {
690
+ let ( entry_index, entry) = self . stack . last_mut_with_index ( ) . unwrap ( ) ;
691
+ #[ allow( rustc:: potential_query_instability) ]
692
+ for ( head_index, usages) in usages. into_iter ( ) {
693
+ if head_index == entry_index {
694
+ entry. usages . unwrap ( ) . ignore_usages ( usages) ;
695
+ } else {
696
+ entry. heads . ignore_usages ( head_index, usages) ;
697
+ }
692
698
}
693
699
}
694
700
}
0 commit comments