@@ -119,11 +119,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
119
119
120
120
// returns if `cond` not occurring implies that `error` does not occur - i.e., that
121
121
// `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 {
127
127
if cond == error {
128
128
return true
129
129
}
@@ -155,13 +155,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
155
155
false
156
156
}
157
157
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
+ ) {
161
164
debug ! ( "report_fulfillment_errors({:?})" , error) ;
162
165
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
+ ) ;
165
173
}
166
174
FulfillmentErrorCode :: CodeProjectionError ( ref e) => {
167
175
self . report_projection_error ( & error. obligation , e) ;
@@ -170,19 +178,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
170
178
self . maybe_report_ambiguity ( & error. obligation , body_id) ;
171
179
}
172
180
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 ( ) ;
178
187
}
179
188
}
180
189
}
181
190
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
+ ) {
186
196
let predicate =
187
197
self . resolve_vars_if_possible ( & obligation. predicate ) ;
188
198
@@ -603,6 +613,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
603
613
obligation : & PredicateObligation < ' tcx > ,
604
614
error : & SelectionError < ' tcx > ,
605
615
fallback_has_occurred : bool ,
616
+ points_at_arg : bool ,
606
617
) {
607
618
let span = obligation. cause . span ;
608
619
@@ -690,7 +701,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
690
701
}
691
702
692
703
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 ) ;
694
705
self . suggest_remove_reference ( & obligation, & mut err, & trait_ref) ;
695
706
self . suggest_semicolon_removal ( & obligation, & mut err, span, & trait_ref) ;
696
707
@@ -963,6 +974,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
963
974
obligation : & PredicateObligation < ' tcx > ,
964
975
err : & mut DiagnosticBuilder < ' tcx > ,
965
976
trait_ref : & ty:: Binder < ty:: TraitRef < ' tcx > > ,
977
+ points_at_arg : bool ,
966
978
) {
967
979
let self_ty = trait_ref. self_ty ( ) ;
968
980
match self_ty. sty {
@@ -991,15 +1003,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
991
1003
..
992
1004
} ) ) = self . tcx . hir ( ) . get_if_local ( def_id) {
993
1005
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
+ "{}({})" ,
996
1009
ident,
997
1010
body. params. iter( )
998
1011
. map( |arg| match & arg. pat. node {
999
1012
hir:: PatKind :: Binding ( _, _, ident, None )
1000
1013
if ident. name != kw:: SelfLower => ident. to_string( ) ,
1001
1014
_ => "_" . 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
+ }
1003
1027
}
1004
1028
}
1005
1029
_ => { }
0 commit comments