@@ -11,7 +11,6 @@ use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCod
11
11
use crate :: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
12
12
use crate :: infer:: { self , InferCtxt } ;
13
13
use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
14
- use crate :: traits:: query:: normalize:: QueryNormalizeExt as _;
15
14
use crate :: traits:: specialize:: to_pretty_impl_header;
16
15
use crate :: traits:: NormalizeExt ;
17
16
use on_unimplemented:: { AppendConstMessage , OnUnimplementedNote , TypeErrCtxtExt as _} ;
@@ -31,7 +30,7 @@ use rustc_middle::traits::select::OverflowError;
31
30
use rustc_middle:: traits:: SelectionOutputTypeParameterMismatch ;
32
31
use rustc_middle:: ty:: abstract_const:: NotConstEvaluatable ;
33
32
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
34
- use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
33
+ use rustc_middle:: ty:: fold:: { BottomUpFolder , TypeFolder , TypeSuperFoldable } ;
35
34
use rustc_middle:: ty:: print:: { with_forced_trimmed_paths, FmtPrinter , Print } ;
36
35
use rustc_middle:: ty:: {
37
36
self , SubtypePredicate , ToPolyTraitRef , ToPredicate , TraitRef , Ty , TyCtxt , TypeFoldable ,
@@ -60,7 +59,7 @@ pub enum CandidateSimilarity {
60
59
Fuzzy { ignoring_lifetimes : bool } ,
61
60
}
62
61
63
- #[ derive( Debug , Clone , Copy ) ]
62
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
64
63
pub struct ImplCandidate < ' tcx > {
65
64
pub trait_ref : ty:: TraitRef < ' tcx > ,
66
65
pub similarity : CandidateSimilarity ,
@@ -1992,7 +1991,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1992
1991
// Mentioning implementers of `Copy`, `Debug` and friends is not useful.
1993
1992
return false ;
1994
1993
}
1995
- let normalized_impl_candidates : Vec < _ > = self
1994
+ let impl_candidates : Vec < _ > = self
1996
1995
. tcx
1997
1996
. all_impls ( def_id)
1998
1997
// Ignore automatically derived impls and `!Trait` impls.
@@ -2019,7 +2018,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2019
2018
}
2020
2019
} )
2021
2020
. collect ( ) ;
2022
- return report ( normalized_impl_candidates , err) ;
2021
+ return report ( impl_candidates , err) ;
2023
2022
}
2024
2023
2025
2024
// Sort impl candidates so that ordering is consistent for UI tests.
@@ -2028,27 +2027,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2028
2027
//
2029
2028
// Prefer more similar candidates first, then sort lexicographically
2030
2029
// 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 ( ) ;
2045
2033
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
+ )
2052
2050
}
2053
2051
2054
2052
fn report_similar_impl_candidates_for_root_obligation (
0 commit comments