@@ -666,6 +666,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
666666 }
667667 }
668668
669+ fn suggest_method_call_annotation (
670+ & self ,
671+ err : & mut Diag < ' _ > ,
672+ span : Span ,
673+ rcvr_ty : Ty < ' tcx > ,
674+ item_ident : Ident ,
675+ mode : Mode ,
676+ source : SelfSource < ' tcx > ,
677+ expected : Expectation < ' tcx > ,
678+ ) {
679+ if let Mode :: MethodCall = mode
680+ && let SelfSource :: MethodCall ( cal) = source
681+ {
682+ self . suggest_await_before_method (
683+ err,
684+ item_ident,
685+ rcvr_ty,
686+ cal,
687+ span,
688+ expected. only_has_type ( self ) ,
689+ ) ;
690+ }
691+
692+ self . suggest_on_pointer_type ( err, source, rcvr_ty, item_ident) ;
693+
694+ if let SelfSource :: MethodCall ( rcvr_expr) = source {
695+ self . suggest_fn_call ( err, rcvr_expr, rcvr_ty, |output_ty| {
696+ let call_expr = self . tcx . hir_expect_expr ( self . tcx . parent_hir_id ( rcvr_expr. hir_id ) ) ;
697+ let probe = self . lookup_probe_for_diagnostic (
698+ item_ident,
699+ output_ty,
700+ call_expr,
701+ ProbeScope :: AllTraits ,
702+ expected. only_has_type ( self ) ,
703+ ) ;
704+ probe. is_ok ( )
705+ } ) ;
706+ self . note_internal_mutation_in_method (
707+ err,
708+ rcvr_expr,
709+ expected. to_option ( self ) ,
710+ rcvr_ty,
711+ ) ;
712+ }
713+ }
714+
669715 fn report_no_match_method_error (
670716 & self ,
671717 mut span : Span ,
@@ -754,40 +800,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
754800 args,
755801 ) ;
756802
757- if let Mode :: MethodCall = mode
758- && let SelfSource :: MethodCall ( cal) = source
759- {
760- self . suggest_await_before_method (
761- & mut err,
762- item_ident,
763- rcvr_ty,
764- cal,
765- span,
766- expected. only_has_type ( self ) ,
767- ) ;
768- }
769-
770- self . suggest_on_pointer_type ( & mut err, source, rcvr_ty, item_ident) ;
771-
772- if let SelfSource :: MethodCall ( rcvr_expr) = source {
773- self . suggest_fn_call ( & mut err, rcvr_expr, rcvr_ty, |output_ty| {
774- let call_expr = self . tcx . hir_expect_expr ( self . tcx . parent_hir_id ( rcvr_expr. hir_id ) ) ;
775- let probe = self . lookup_probe_for_diagnostic (
776- item_ident,
777- output_ty,
778- call_expr,
779- ProbeScope :: AllTraits ,
780- expected. only_has_type ( self ) ,
781- ) ;
782- probe. is_ok ( )
783- } ) ;
784- self . note_internal_mutation_in_method (
785- & mut err,
786- rcvr_expr,
787- expected. to_option ( self ) ,
788- rcvr_ty,
789- ) ;
790- }
803+ self . suggest_method_call_annotation (
804+ & mut err, span, rcvr_ty, item_ident, mode, source, expected,
805+ ) ;
791806
792807 let mut custom_span_label = false ;
793808 let mut static_candidates = no_match_data. static_candidates . clone ( ) ;
0 commit comments