@@ -21,6 +21,7 @@ use crate::traits::{
2121} ;
2222use core:: ops:: ControlFlow ;
2323use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
24+ use rustc_data_structures:: unord:: UnordSet ;
2425use rustc_errors:: codes:: * ;
2526use rustc_errors:: { pluralize, struct_span_code_err, Applicability , MultiSpan , StringPart } ;
2627use rustc_errors:: { Diag , EmissionGuarantee , ErrorGuaranteed , FatalError , StashKey } ;
@@ -2243,14 +2244,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22432244 } ;
22442245
22452246 let required_trait_path = self . tcx . def_path_str ( trait_ref. def_id ( ) ) ;
2246- let traits_with_same_path: std :: collections :: BTreeSet < _ > = self
2247+ let traits_with_same_path: UnordSet < _ > = self
22472248 . tcx
22482249 . all_traits ( )
22492250 . filter ( |trait_def_id| * trait_def_id != trait_ref. def_id ( ) )
2250- . filter ( |trait_def_id| self . tcx . def_path_str ( * trait_def_id) == required_trait_path)
2251+ . map ( |trait_def_id| ( self . tcx . def_path_str ( trait_def_id) , trait_def_id) )
2252+ . filter ( |( p, _) | * p == required_trait_path)
22512253 . collect ( ) ;
2254+
2255+ let traits_with_same_path =
2256+ traits_with_same_path. into_items ( ) . into_sorted_stable_ord_by_key ( |( p, _) | p) ;
22522257 let mut suggested = false ;
2253- for trait_with_same_path in traits_with_same_path {
2258+ for ( _ , trait_with_same_path) in traits_with_same_path {
22542259 let trait_impls = get_trait_impls ( trait_with_same_path) ;
22552260 if trait_impls. is_empty ( ) {
22562261 continue ;
0 commit comments