From 727807293bc21c072162e9420096cb5a10cc63da Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 21 Mar 2024 16:35:45 +0000 Subject: [PATCH] Don't sort `DefId`s in suggestions --- .../src/traits/error_reporting/type_err_ctxt_ext.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 9186241d607..7a62030353d 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -21,6 +21,7 @@ }; use core::ops::ControlFlow; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; +use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; use rustc_errors::{pluralize, struct_span_code_err, Applicability, MultiSpan, StringPart}; use rustc_errors::{Diag, EmissionGuarantee, ErrorGuaranteed, FatalError, StashKey}; @@ -2243,14 +2244,18 @@ fn note_version_mismatch( }; let required_trait_path = self.tcx.def_path_str(trait_ref.def_id()); - let traits_with_same_path: std::collections::BTreeSet<_> = self + let traits_with_same_path: UnordSet<_> = self .tcx .all_traits() .filter(|trait_def_id| *trait_def_id != trait_ref.def_id()) - .filter(|trait_def_id| self.tcx.def_path_str(*trait_def_id) == required_trait_path) + .map(|trait_def_id| (self.tcx.def_path_str(trait_def_id), trait_def_id)) + .filter(|(p, _)| *p == required_trait_path) .collect(); + + let traits_with_same_path = + traits_with_same_path.into_items().into_sorted_stable_ord_by_key(|(p, _)| p); let mut suggested = false; - for trait_with_same_path in traits_with_same_path { + for (_, trait_with_same_path) in traits_with_same_path { let trait_impls = get_trait_impls(trait_with_same_path); if trait_impls.is_empty() { continue;