@@ -16,8 +16,8 @@ use std::collections::hash_map::Entry;
1616use std:: collections:: { BTreeMap , btree_map} ;
1717use std:: fmt:: Debug ;
1818use std:: hash:: Hash ;
19+ use std:: iter;
1920use std:: marker:: PhantomData ;
20- use std:: { iter, mem} ;
2121
2222use derive_where:: derive_where;
2323#[ cfg( feature = "nightly" ) ]
@@ -229,16 +229,19 @@ impl Usages {
229229
230230#[ derive( Debug , Default ) ]
231231pub struct CandidateUsages {
232- usages : HashMap < StackDepth , Usages > ,
232+ usages : Option < Box < HashMap < StackDepth , Usages > > > ,
233233}
234234impl 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+ }
242245 }
243246 }
244247}
@@ -604,6 +607,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
604607 if let Some ( candidate_usages) = & mut parent. candidate_usages {
605608 candidate_usages
606609 . usages
610+ . get_or_insert_default ( )
607611 . entry ( head_index)
608612 . or_default ( )
609613 . add_usages ( head. usages . compressed ( ) ) ;
@@ -682,13 +686,15 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
682686 }
683687
684688 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+ }
692698 }
693699 }
694700 }
0 commit comments