@@ -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 } ;
@@ -2243,14 +2244,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2243
2244
} ;
2244
2245
2245
2246
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
2247
2248
. tcx
2248
2249
. all_traits ( )
2249
2250
. 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)
2251
2253
. collect ( ) ;
2254
+
2255
+ let traits_with_same_path =
2256
+ traits_with_same_path. into_items ( ) . into_sorted_stable_ord_by_key ( |( p, _) | p) ;
2252
2257
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 {
2254
2259
let trait_impls = get_trait_impls ( trait_with_same_path) ;
2255
2260
if trait_impls. is_empty ( ) {
2256
2261
continue ;
0 commit comments