@@ -21,6 +21,7 @@ use crate::traits::{
21
21
} ;
22
22
use core:: ops:: ControlFlow ;
23
23
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
24
+ use rustc_data_structures:: unord:: UnordSet ;
24
25
use rustc_errors:: codes:: * ;
25
26
use rustc_errors:: { pluralize, struct_span_code_err, Applicability , MultiSpan , StringPart } ;
26
27
use rustc_errors:: { Diag , EmissionGuarantee , ErrorGuaranteed , FatalError , StashKey } ;
@@ -2245,14 +2246,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2245
2246
} ;
2246
2247
2247
2248
let required_trait_path = self . tcx . def_path_str ( trait_ref. def_id ( ) ) ;
2248
- let traits_with_same_path: std :: collections :: BTreeSet < _ > = self
2249
+ let traits_with_same_path: UnordSet < _ > = self
2249
2250
. tcx
2250
2251
. all_traits ( )
2251
2252
. filter ( |trait_def_id| * trait_def_id != trait_ref. def_id ( ) )
2252
- . filter ( |trait_def_id| self . tcx . def_path_str ( * trait_def_id) == required_trait_path)
2253
+ . map ( |trait_def_id| ( self . tcx . def_path_str ( trait_def_id) , trait_def_id) )
2254
+ . filter ( |( p, _) | * p == required_trait_path)
2253
2255
. collect ( ) ;
2256
+
2257
+ let traits_with_same_path =
2258
+ traits_with_same_path. into_items ( ) . into_sorted_stable_ord_by_key ( |( p, _) | p) ;
2254
2259
let mut suggested = false ;
2255
- for trait_with_same_path in traits_with_same_path {
2260
+ for ( _ , trait_with_same_path) in traits_with_same_path {
2256
2261
let trait_impls = get_trait_impls ( trait_with_same_path) ;
2257
2262
if trait_impls. is_empty ( ) {
2258
2263
continue ;
0 commit comments