@@ -106,7 +106,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
106
106
107
107
let report_candidates = |span : Span ,
108
108
err : & mut Diagnostic ,
109
- mut sources : Vec < CandidateSource > ,
109
+ sources : & mut Vec < CandidateSource > ,
110
110
sugg_span : Span | {
111
111
sources. sort ( ) ;
112
112
sources. dedup ( ) ;
@@ -248,7 +248,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
248
248
249
249
match error {
250
250
MethodError :: NoMatch ( NoMatchData {
251
- static_candidates : static_sources,
251
+ static_candidates : mut static_sources,
252
252
unsatisfied_predicates,
253
253
out_of_scope_traits,
254
254
lev_candidate,
@@ -422,9 +422,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
422
422
err. help ( & format ! ( "try with `{}::{}`" , ty_str, item_name, ) ) ;
423
423
}
424
424
425
- report_candidates ( span, & mut err, static_sources, sugg_span) ;
425
+ report_candidates ( span, & mut err, & mut static_sources, sugg_span) ;
426
426
} else if static_sources. len ( ) > 1 {
427
- report_candidates ( span, & mut err, static_sources, sugg_span) ;
427
+ report_candidates ( span, & mut err, & mut static_sources, sugg_span) ;
428
428
}
429
429
430
430
let mut bound_spans = vec ! [ ] ;
@@ -1007,6 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1007
1007
source,
1008
1008
out_of_scope_traits,
1009
1009
& unsatisfied_predicates,
1010
+ & static_sources,
1010
1011
unsatisfied_bounds,
1011
1012
) ;
1012
1013
}
@@ -1079,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1079
1080
return Some ( err) ;
1080
1081
}
1081
1082
1082
- MethodError :: Ambiguity ( sources) => {
1083
+ MethodError :: Ambiguity ( mut sources) => {
1083
1084
let mut err = struct_span_err ! (
1084
1085
self . sess( ) ,
1085
1086
item_name. span,
@@ -1088,7 +1089,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1088
1089
) ;
1089
1090
err. span_label ( item_name. span , format ! ( "multiple `{}` found" , item_name) ) ;
1090
1091
1091
- report_candidates ( span, & mut err, sources, sugg_span) ;
1092
+ report_candidates ( span, & mut err, & mut sources, sugg_span) ;
1092
1093
err. emit ( ) ;
1093
1094
}
1094
1095
@@ -2015,6 +2016,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2015
2016
Option < ty:: Predicate < ' tcx > > ,
2016
2017
Option < ObligationCause < ' tcx > > ,
2017
2018
) ] ,
2019
+ static_candidates : & [ CandidateSource ] ,
2018
2020
unsatisfied_bounds : bool ,
2019
2021
) {
2020
2022
let mut alt_rcvr_sugg = false ;
@@ -2128,6 +2130,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2128
2130
Some ( attr) => attr. level . is_stable ( ) ,
2129
2131
None => true ,
2130
2132
} )
2133
+ . filter ( |info| {
2134
+ // Static candidates are already implemented, and known not to work
2135
+ // Do not suggest them again
2136
+ static_candidates. iter ( ) . all ( |sc| match * sc {
2137
+ CandidateSource :: Trait ( def_id) => def_id != info. def_id ,
2138
+ CandidateSource :: Impl ( def_id) => {
2139
+ self . tcx . trait_id_of_impl ( def_id) != Some ( info. def_id )
2140
+ }
2141
+ } )
2142
+ } )
2131
2143
. filter ( |info| {
2132
2144
// We approximate the coherence rules to only suggest
2133
2145
// traits that are legal to implement by requiring that
0 commit comments