@@ -11,7 +11,6 @@ use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCod
1111use crate :: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
1212use crate :: infer:: { self , InferCtxt } ;
1313use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
14- use crate :: traits:: query:: normalize:: QueryNormalizeExt as _;
1514use crate :: traits:: specialize:: to_pretty_impl_header;
1615use crate :: traits:: NormalizeExt ;
1716use on_unimplemented:: { AppendConstMessage , OnUnimplementedNote , TypeErrCtxtExt as _} ;
@@ -31,7 +30,7 @@ use rustc_middle::traits::select::OverflowError;
3130use rustc_middle:: traits:: SelectionOutputTypeParameterMismatch ;
3231use rustc_middle:: ty:: abstract_const:: NotConstEvaluatable ;
3332use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
34- use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
33+ use rustc_middle:: ty:: fold:: { BottomUpFolder , TypeFolder , TypeSuperFoldable } ;
3534use rustc_middle:: ty:: print:: { with_forced_trimmed_paths, FmtPrinter , Print } ;
3635use rustc_middle:: ty:: {
3736 self , SubtypePredicate , ToPolyTraitRef , ToPredicate , TraitRef , Ty , TyCtxt , TypeFoldable ,
@@ -60,7 +59,7 @@ pub enum CandidateSimilarity {
6059 Fuzzy { ignoring_lifetimes : bool } ,
6160}
6261
63- #[ derive( Debug , Clone , Copy ) ]
62+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
6463pub struct ImplCandidate < ' tcx > {
6564 pub trait_ref : ty:: TraitRef < ' tcx > ,
6665 pub similarity : CandidateSimilarity ,
@@ -1992,7 +1991,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19921991 // Mentioning implementers of `Copy`, `Debug` and friends is not useful.
19931992 return false ;
19941993 }
1995- let normalized_impl_candidates : Vec < _ > = self
1994+ let impl_candidates : Vec < _ > = self
19961995 . tcx
19971996 . all_impls ( def_id)
19981997 // Ignore automatically derived impls and `!Trait` impls.
@@ -2019,7 +2018,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20192018 }
20202019 } )
20212020 . collect ( ) ;
2022- return report ( normalized_impl_candidates , err) ;
2021+ return report ( impl_candidates , err) ;
20232022 }
20242023
20252024 // Sort impl candidates so that ordering is consistent for UI tests.
@@ -2028,27 +2027,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20282027 //
20292028 // Prefer more similar candidates first, then sort lexicographically
20302029 // by their normalized string representation.
2031- let mut normalized_impl_candidates_and_similarities = impl_candidates
2032- . iter ( )
2033- . copied ( )
2034- . map ( |ImplCandidate { trait_ref, similarity } | {
2035- // FIXME(compiler-errors): This should be using `NormalizeExt::normalize`
2036- let normalized = self
2037- . at ( & ObligationCause :: dummy ( ) , ty:: ParamEnv :: empty ( ) )
2038- . query_normalize ( trait_ref)
2039- . map_or ( trait_ref, |normalized| normalized. value ) ;
2040- ( similarity, normalized)
2041- } )
2042- . collect :: < Vec < _ > > ( ) ;
2043- normalized_impl_candidates_and_similarities. sort ( ) ;
2044- normalized_impl_candidates_and_similarities. dedup ( ) ;
2030+ let mut impl_candidates = impl_candidates. to_vec ( ) ;
2031+ impl_candidates. sort_by_key ( |cand| ( cand. similarity , cand. trait_ref ) ) ;
2032+ impl_candidates. dedup ( ) ;
20452033
2046- let normalized_impl_candidates = normalized_impl_candidates_and_similarities
2047- . into_iter ( )
2048- . map ( |( _, normalized) | normalized)
2049- . collect :: < Vec < _ > > ( ) ;
2050-
2051- report ( normalized_impl_candidates, err)
2034+ report (
2035+ impl_candidates
2036+ . into_iter ( )
2037+ . map ( |cand| {
2038+ // Fold the const so that it shows up as, e.g., `10`
2039+ // instead of `core::::array::{impl#30}::{constant#0}`.
2040+ cand. trait_ref . fold_with ( & mut BottomUpFolder {
2041+ tcx : self . tcx ,
2042+ ty_op : |ty| ty,
2043+ lt_op : |lt| lt,
2044+ ct_op : |ct| ct. eval ( self . tcx , ty:: ParamEnv :: empty ( ) ) ,
2045+ } )
2046+ } )
2047+ . collect ( ) ,
2048+ err,
2049+ )
20522050 }
20532051
20542052 fn report_similar_impl_candidates_for_root_obligation (
0 commit comments