@@ -739,7 +739,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
739
739
{
740
740
let mut eraser = TypeParamEraser ( self . tcx ) ;
741
741
let candidate_len = impl_candidates. len ( ) ;
742
- let mut suggestions: Vec < _ > = impl_candidates. iter ( ) . map ( |candidate| {
742
+ let mut suggestions: Vec < _ > = impl_candidates. iter ( ) . filter_map ( |candidate| {
743
743
let trait_item = self . tcx
744
744
. associated_items ( candidate. def_id )
745
745
. find_by_name_and_kind (
@@ -748,6 +748,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
748
748
ty:: AssocKind :: Fn ,
749
749
candidate. def_id
750
750
) ;
751
+ if trait_item. is_none ( ) {
752
+ return None ;
753
+ }
751
754
let prefix = if let Some ( trait_item) = trait_item
752
755
&& let Some ( trait_m) = trait_item. def_id . as_local ( )
753
756
&& let hir:: TraitItemKind :: Fn ( fn_, _) = & self . tcx . hir ( ) . trait_item ( hir:: TraitItemId { def_id : trait_m } ) . kind
@@ -761,24 +764,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
761
764
""
762
765
} ;
763
766
let candidate = candidate. super_fold_with ( & mut eraser) ;
764
- vec ! [
767
+ Some ( vec ! [
765
768
( expr. span. shrink_to_lo( ) , format!( "{}::{}({}" , candidate, segment. ident, prefix) ) ,
766
769
if exprs. len( ) == 1 {
767
770
( expr. span. shrink_to_hi( ) . with_hi( e. span. hi( ) ) , ")" . to_string( ) )
768
771
} else {
769
772
( expr. span. shrink_to_hi( ) . with_hi( exprs[ 1 ] . span. lo( ) ) , ", " . to_string( ) )
770
773
} ,
771
- ]
774
+ ] )
772
775
} ) . collect ( ) ;
773
776
suggestions. sort_by ( |a, b| a[ 0 ] . 1 . cmp ( & b[ 0 ] . 1 ) ) ;
774
- err. multipart_suggestions (
775
- & format ! (
776
- "use the fully qualified path for the potential candidate{}" ,
777
- pluralize!( candidate_len) ,
778
- ) ,
779
- suggestions. into_iter ( ) ,
780
- Applicability :: MaybeIncorrect ,
781
- ) ;
777
+ if !suggestions. is_empty ( ) {
778
+ err. multipart_suggestions (
779
+ & format ! (
780
+ "use the fully qualified path for the potential candidate{}" ,
781
+ pluralize!( candidate_len) ,
782
+ ) ,
783
+ suggestions. into_iter ( ) ,
784
+ Applicability :: MaybeIncorrect ,
785
+ ) ;
786
+ }
782
787
}
783
788
// Suggest specifying type params or point out the return type of the call:
784
789
//
0 commit comments