@@ -119,11 +119,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
119119
120120 // returns if `cond` not occurring implies that `error` does not occur - i.e., that
121121 // `error` occurring implies that `cond` occurs.
122- fn error_implies ( & self ,
123- cond : & ty :: Predicate < ' tcx > ,
124- error : & ty:: Predicate < ' tcx > )
125- -> bool
126- {
122+ fn error_implies (
123+ & self ,
124+ cond : & ty:: Predicate < ' tcx > ,
125+ error : & ty :: Predicate < ' tcx > ,
126+ ) -> bool {
127127 if cond == error {
128128 return true
129129 }
@@ -155,13 +155,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
155155 false
156156 }
157157
158- fn report_fulfillment_error ( & self , error : & FulfillmentError < ' tcx > ,
159- body_id : Option < hir:: BodyId > ,
160- fallback_has_occurred : bool ) {
158+ fn report_fulfillment_error (
159+ & self ,
160+ error : & FulfillmentError < ' tcx > ,
161+ body_id : Option < hir:: BodyId > ,
162+ fallback_has_occurred : bool ,
163+ ) {
161164 debug ! ( "report_fulfillment_errors({:?})" , error) ;
162165 match error. code {
163- FulfillmentErrorCode :: CodeSelectionError ( ref e) => {
164- self . report_selection_error ( & error. obligation , e, fallback_has_occurred) ;
166+ FulfillmentErrorCode :: CodeSelectionError ( ref selection_error) => {
167+ self . report_selection_error (
168+ & error. obligation ,
169+ selection_error,
170+ fallback_has_occurred,
171+ error. points_at_arg_span ,
172+ ) ;
165173 }
166174 FulfillmentErrorCode :: CodeProjectionError ( ref e) => {
167175 self . report_projection_error ( & error. obligation , e) ;
@@ -170,19 +178,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
170178 self . maybe_report_ambiguity ( & error. obligation , body_id) ;
171179 }
172180 FulfillmentErrorCode :: CodeSubtypeError ( ref expected_found, ref err) => {
173- self . report_mismatched_types ( & error. obligation . cause ,
174- expected_found. expected ,
175- expected_found. found ,
176- err. clone ( ) )
177- . emit ( ) ;
181+ self . report_mismatched_types (
182+ & error. obligation . cause ,
183+ expected_found. expected ,
184+ expected_found. found ,
185+ err. clone ( ) ,
186+ ) . emit ( ) ;
178187 }
179188 }
180189 }
181190
182- fn report_projection_error ( & self ,
183- obligation : & PredicateObligation < ' tcx > ,
184- error : & MismatchedProjectionTypes < ' tcx > )
185- {
191+ fn report_projection_error (
192+ & self ,
193+ obligation : & PredicateObligation < ' tcx > ,
194+ error : & MismatchedProjectionTypes < ' tcx > ,
195+ ) {
186196 let predicate =
187197 self . resolve_vars_if_possible ( & obligation. predicate ) ;
188198
@@ -603,6 +613,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
603613 obligation : & PredicateObligation < ' tcx > ,
604614 error : & SelectionError < ' tcx > ,
605615 fallback_has_occurred : bool ,
616+ points_at_arg : bool ,
606617 ) {
607618 let span = obligation. cause . span ;
608619
@@ -690,7 +701,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
690701 }
691702
692703 self . suggest_borrow_on_unsized_slice ( & obligation. cause . code , & mut err) ;
693- self . suggest_fn_call ( & obligation, & mut err, & trait_ref) ;
704+ self . suggest_fn_call ( & obligation, & mut err, & trait_ref, points_at_arg ) ;
694705 self . suggest_remove_reference ( & obligation, & mut err, & trait_ref) ;
695706 self . suggest_semicolon_removal ( & obligation, & mut err, span, & trait_ref) ;
696707
@@ -963,6 +974,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
963974 obligation : & PredicateObligation < ' tcx > ,
964975 err : & mut DiagnosticBuilder < ' tcx > ,
965976 trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ,
977+ points_at_arg : bool ,
966978 ) {
967979 let self_ty = trait_ref. self_ty ( ) ;
968980 match self_ty. sty {
@@ -991,15 +1003,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
9911003 ..
9921004 } ) ) = self . tcx . hir ( ) . get_if_local ( def_id) {
9931005 let body = self . tcx . hir ( ) . body ( * body_id) ;
994- err. help ( & format ! (
995- "use parentheses to call the function: `{}({})`" ,
1006+ let msg = "use parentheses to call the function" ;
1007+ let snippet = format ! (
1008+ "{}({})" ,
9961009 ident,
9971010 body. params. iter( )
9981011 . map( |arg| match & arg. pat. node {
9991012 hir:: PatKind :: Binding ( _, _, ident, None )
10001013 if ident. name != kw:: SelfLower => ident. to_string( ) ,
10011014 _ => "_" . to_string( ) ,
1002- } ) . collect:: <Vec <_>>( ) . join( ", " ) ) ) ;
1015+ } ) . collect:: <Vec <_>>( ) . join( ", " ) ,
1016+ ) ;
1017+ if points_at_arg {
1018+ err. span_suggestion (
1019+ obligation. cause . span ,
1020+ msg,
1021+ snippet,
1022+ Applicability :: HasPlaceholders ,
1023+ ) ;
1024+ } else {
1025+ err. help ( & format ! ( "{}: `{}`" , msg, snippet) ) ;
1026+ }
10031027 }
10041028 }
10051029 _ => { }
0 commit comments