@@ -886,6 +886,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
886886 ) )
887887 }
888888
889+ fn suggest_surround_method_call (
890+ & self ,
891+ err : & mut Diag < ' _ > ,
892+ span : Span ,
893+ rcvr_ty : Ty < ' tcx > ,
894+ item_ident : Ident ,
895+ source : SelfSource < ' tcx > ,
896+ similar_candidate : & Option < ty:: AssocItem > ,
897+ ) -> bool {
898+ match source {
899+ // If the method name is the name of a field with a function or closure type,
900+ // give a helping note that it has to be called as `(x.f)(...)`.
901+ SelfSource :: MethodCall ( expr) => {
902+ !self . suggest_calling_field_as_fn ( span, rcvr_ty, expr, item_ident, err)
903+ && similar_candidate. is_none ( )
904+ }
905+ _ => true ,
906+ }
907+ }
908+
889909 fn report_no_match_method_error (
890910 & self ,
891911 mut span : Span ,
@@ -1018,15 +1038,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10181038 } ;
10191039
10201040 let mut find_candidate_for_method = false ;
1021- let should_label_not_found = match source {
1022- // If the method name is the name of a field with a function or closure type,
1023- // give a helping note that it has to be called as `(x.f)(...)`.
1024- SelfSource :: MethodCall ( expr) => {
1025- !self . suggest_calling_field_as_fn ( span, rcvr_ty, expr, item_ident, & mut err)
1026- && similar_candidate. is_none ( )
1027- }
1028- _ => true ,
1029- } ;
1041+ let should_label_not_found = self . suggest_surround_method_call (
1042+ & mut err,
1043+ span,
1044+ rcvr_ty,
1045+ item_ident,
1046+ source,
1047+ & similar_candidate,
1048+ ) ;
10301049
10311050 if should_label_not_found && !custom_span_label {
10321051 self . set_not_found_span_label (
0 commit comments