@@ -106,7 +106,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
106106
107107 let report_candidates = |span : Span ,
108108 err : & mut Diagnostic ,
109- mut sources : Vec < CandidateSource > ,
109+ sources : & mut Vec < CandidateSource > ,
110110 sugg_span : Span | {
111111 sources. sort ( ) ;
112112 sources. dedup ( ) ;
@@ -248,7 +248,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
248248
249249 match error {
250250 MethodError :: NoMatch ( NoMatchData {
251- static_candidates : static_sources,
251+ static_candidates : mut static_sources,
252252 unsatisfied_predicates,
253253 out_of_scope_traits,
254254 lev_candidate,
@@ -422,9 +422,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
422422 err. help ( & format ! ( "try with `{}::{}`" , ty_str, item_name, ) ) ;
423423 }
424424
425- report_candidates ( span, & mut err, static_sources, sugg_span) ;
425+ report_candidates ( span, & mut err, & mut static_sources, sugg_span) ;
426426 } 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) ;
428428 }
429429
430430 let mut bound_spans = vec ! [ ] ;
@@ -1007,6 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10071007 source,
10081008 out_of_scope_traits,
10091009 & unsatisfied_predicates,
1010+ & static_sources,
10101011 unsatisfied_bounds,
10111012 ) ;
10121013 }
@@ -1079,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10791080 return Some ( err) ;
10801081 }
10811082
1082- MethodError :: Ambiguity ( sources) => {
1083+ MethodError :: Ambiguity ( mut sources) => {
10831084 let mut err = struct_span_err ! (
10841085 self . sess( ) ,
10851086 item_name. span,
@@ -1088,7 +1089,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10881089 ) ;
10891090 err. span_label ( item_name. span , format ! ( "multiple `{}` found" , item_name) ) ;
10901091
1091- report_candidates ( span, & mut err, sources, sugg_span) ;
1092+ report_candidates ( span, & mut err, & mut sources, sugg_span) ;
10921093 err. emit ( ) ;
10931094 }
10941095
@@ -2015,6 +2016,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20152016 Option < ty:: Predicate < ' tcx > > ,
20162017 Option < ObligationCause < ' tcx > > ,
20172018 ) ] ,
2019+ static_candidates : & [ CandidateSource ] ,
20182020 unsatisfied_bounds : bool ,
20192021 ) {
20202022 let mut alt_rcvr_sugg = false ;
@@ -2128,6 +2130,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21282130 Some ( attr) => attr. level . is_stable ( ) ,
21292131 None => true ,
21302132 } )
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+ } )
21312143 . filter ( |info| {
21322144 // We approximate the coherence rules to only suggest
21332145 // traits that are legal to implement by requiring that
0 commit comments