@@ -24,7 +24,7 @@ use crate::traits::error_reporting::InferCtxtExt;
2424use crate :: traits:: project:: ProjectAndUnifyResult ;
2525use crate :: traits:: project:: ProjectionCacheKeyExt ;
2626use crate :: traits:: ProjectionCacheKey ;
27- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
27+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
2828use rustc_data_structures:: stack:: ensure_sufficient_stack;
2929use rustc_errors:: { Diagnostic , ErrorGuaranteed } ;
3030use rustc_hir as hir;
@@ -52,7 +52,7 @@ pub use rustc_middle::traits::select::*;
5252mod candidate_assembly;
5353mod confirmation;
5454
55- #[ derive( Clone , Debug ) ]
55+ #[ derive( Clone , Debug , Eq , PartialEq , Hash ) ]
5656pub enum IntercrateAmbiguityCause {
5757 DownstreamCrate { trait_desc : String , self_desc : Option < String > } ,
5858 UpstreamCrateUpdate { trait_desc : String , self_desc : Option < String > } ,
@@ -128,7 +128,7 @@ pub struct SelectionContext<'cx, 'tcx> {
128128 /// We don't do his until we detect a coherence error because it can
129129 /// lead to false overflow results (#47139) and because always
130130 /// computing it may negatively impact performance.
131- intercrate_ambiguity_causes : Option < Vec < IntercrateAmbiguityCause > > ,
131+ intercrate_ambiguity_causes : Option < FxIndexSet < IntercrateAmbiguityCause > > ,
132132
133133 /// The mode that trait queries run in, which informs our error handling
134134 /// policy. In essence, canonicalized queries need their errors propagated
@@ -254,14 +254,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
254254 pub fn enable_tracking_intercrate_ambiguity_causes ( & mut self ) {
255255 assert ! ( self . intercrate) ;
256256 assert ! ( self . intercrate_ambiguity_causes. is_none( ) ) ;
257- self . intercrate_ambiguity_causes = Some ( vec ! [ ] ) ;
257+ self . intercrate_ambiguity_causes = Some ( FxIndexSet :: default ( ) ) ;
258258 debug ! ( "selcx: enable_tracking_intercrate_ambiguity_causes" ) ;
259259 }
260260
261261 /// Gets the intercrate ambiguity causes collected since tracking
262262 /// was enabled and disables tracking at the same time. If
263263 /// 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 > {
265265 assert ! ( self . intercrate) ;
266266 self . intercrate_ambiguity_causes . take ( ) . unwrap_or_default ( )
267267 }
@@ -960,7 +960,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
960960 } ) ;
961961
962962 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) ;
964964 }
965965 }
966966 }
@@ -1252,7 +1252,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12521252 reservation impl ambiguity on {:?}",
12531253 def_id
12541254 ) ;
1255- intercrate_ambiguity_clauses. push (
1255+ intercrate_ambiguity_clauses. insert (
12561256 IntercrateAmbiguityCause :: ReservationImpl {
12571257 message : value. to_string ( ) ,
12581258 } ,
0 commit comments