@@ -24,7 +24,7 @@ use crate::traits::error_reporting::InferCtxtExt;
24
24
use crate :: traits:: project:: ProjectAndUnifyResult ;
25
25
use crate :: traits:: project:: ProjectionCacheKeyExt ;
26
26
use crate :: traits:: ProjectionCacheKey ;
27
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
27
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
28
28
use rustc_data_structures:: stack:: ensure_sufficient_stack;
29
29
use rustc_errors:: { Diagnostic , ErrorGuaranteed } ;
30
30
use rustc_hir as hir;
@@ -52,7 +52,7 @@ pub use rustc_middle::traits::select::*;
52
52
mod candidate_assembly;
53
53
mod confirmation;
54
54
55
- #[ derive( Clone , Debug ) ]
55
+ #[ derive( Clone , Debug , Eq , PartialEq , Hash ) ]
56
56
pub enum IntercrateAmbiguityCause {
57
57
DownstreamCrate { trait_desc : String , self_desc : Option < String > } ,
58
58
UpstreamCrateUpdate { trait_desc : String , self_desc : Option < String > } ,
@@ -128,7 +128,7 @@ pub struct SelectionContext<'cx, 'tcx> {
128
128
/// We don't do his until we detect a coherence error because it can
129
129
/// lead to false overflow results (#47139) and because always
130
130
/// computing it may negatively impact performance.
131
- intercrate_ambiguity_causes : Option < Vec < IntercrateAmbiguityCause > > ,
131
+ intercrate_ambiguity_causes : Option < FxIndexSet < IntercrateAmbiguityCause > > ,
132
132
133
133
/// The mode that trait queries run in, which informs our error handling
134
134
/// policy. In essence, canonicalized queries need their errors propagated
@@ -254,14 +254,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
254
254
pub fn enable_tracking_intercrate_ambiguity_causes ( & mut self ) {
255
255
assert ! ( self . intercrate) ;
256
256
assert ! ( self . intercrate_ambiguity_causes. is_none( ) ) ;
257
- self . intercrate_ambiguity_causes = Some ( vec ! [ ] ) ;
257
+ self . intercrate_ambiguity_causes = Some ( FxIndexSet :: default ( ) ) ;
258
258
debug ! ( "selcx: enable_tracking_intercrate_ambiguity_causes" ) ;
259
259
}
260
260
261
261
/// Gets the intercrate ambiguity causes collected since tracking
262
262
/// was enabled and disables tracking at the same time. If
263
263
/// tracking is not enabled, just returns an empty vector.
264
- pub fn take_intercrate_ambiguity_causes ( & mut self ) -> Vec < IntercrateAmbiguityCause > {
264
+ pub fn take_intercrate_ambiguity_causes ( & mut self ) -> FxIndexSet < IntercrateAmbiguityCause > {
265
265
assert ! ( self . intercrate) ;
266
266
self . intercrate_ambiguity_causes . take ( ) . unwrap_or_default ( )
267
267
}
@@ -960,7 +960,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
960
960
} ) ;
961
961
962
962
debug ! ( ?cause, "evaluate_stack: pushing cause" ) ;
963
- self . intercrate_ambiguity_causes . as_mut ( ) . unwrap ( ) . push ( cause) ;
963
+ self . intercrate_ambiguity_causes . as_mut ( ) . unwrap ( ) . insert ( cause) ;
964
964
}
965
965
}
966
966
}
@@ -1252,7 +1252,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1252
1252
reservation impl ambiguity on {:?}",
1253
1253
def_id
1254
1254
) ;
1255
- intercrate_ambiguity_clauses. push (
1255
+ intercrate_ambiguity_clauses. insert (
1256
1256
IntercrateAmbiguityCause :: ReservationImpl {
1257
1257
message : value. to_string ( ) ,
1258
1258
} ,
0 commit comments