@@ -96,34 +96,43 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9696 /// method calls and overloaded operators.
9797 pub ( in super :: super ) fn check_argument_types (
9898 & self ,
99- sp : Span ,
100- expr : & ' tcx hir:: Expr < ' tcx > ,
101- fn_inputs : & [ Ty < ' tcx > ] ,
102- expected_arg_tys : & [ Ty < ' tcx > ] ,
103- args : & ' tcx [ hir:: Expr < ' tcx > ] ,
99+ // Span enclosing the call site
100+ call_span : Span ,
101+ // Expression of the call site
102+ call_expr : & ' tcx hir:: Expr < ' tcx > ,
103+ // Types (as defined in the *signature* of the target function)
104+ formal_input_tys : & [ Ty < ' tcx > ] ,
105+ // More specific expected types, after unifying with caller output types
106+ expected_input_tys : & [ Ty < ' tcx > ] ,
107+ // The expressions for each provided argument
108+ provided_args : & ' tcx [ hir:: Expr < ' tcx > ] ,
109+ // Whether the function is variadic, for example when imported from C
104110 c_variadic : bool ,
111+ // Whether the arguments have been bundled in a tuple (ex: closures)
105112 tuple_arguments : TupleArgumentsFlag ,
106- def_id : Option < DefId > ,
113+ // The DefId for the function being called, for better error messages
114+ fn_def_id : Option < DefId > ,
107115 ) {
108116 let tcx = self . tcx ;
109117 // Grab the argument types, supplying fresh type variables
110118 // if the wrong number of arguments were supplied
111- let supplied_arg_count = if tuple_arguments == DontTupleArguments { args. len ( ) } else { 1 } ;
119+ let supplied_arg_count =
120+ if tuple_arguments == DontTupleArguments { provided_args. len ( ) } else { 1 } ;
112121
113122 // All the input types from the fn signature must outlive the call
114123 // so as to validate implied bounds.
115- for ( & fn_input_ty, arg_expr) in iter:: zip ( fn_inputs , args ) {
124+ for ( & fn_input_ty, arg_expr) in iter:: zip ( formal_input_tys , provided_args ) {
116125 self . register_wf_obligation ( fn_input_ty. into ( ) , arg_expr. span , traits:: MiscObligation ) ;
117126 }
118127
119- let expected_arg_count = fn_inputs . len ( ) ;
128+ let expected_arg_count = formal_input_tys . len ( ) ;
120129
121130 let param_count_error = |expected_count : usize ,
122131 arg_count : usize ,
123132 error_code : & str ,
124133 c_variadic : bool ,
125134 sugg_unit : bool | {
126- let ( span, start_span, args, ctor_of) = match & expr . kind {
135+ let ( span, start_span, args, ctor_of) = match & call_expr . kind {
127136 hir:: ExprKind :: Call (
128137 hir:: Expr {
129138 span,
@@ -156,14 +165,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156165 & args[ 1 ..] , // Skip the receiver.
157166 None , // methods are never ctors
158167 ) ,
159- k => span_bug ! ( sp , "checking argument types on a non-call: `{:?}`" , k) ,
168+ k => span_bug ! ( call_span , "checking argument types on a non-call: `{:?}`" , k) ,
160169 } ;
161- let arg_spans = if args . is_empty ( ) {
170+ let arg_spans = if provided_args . is_empty ( ) {
162171 // foo()
163172 // ^^^-- supplied 0 arguments
164173 // |
165174 // expected 2 arguments
166- vec ! [ tcx. sess. source_map( ) . next_point( start_span) . with_hi( sp . hi( ) ) ]
175+ vec ! [ tcx. sess. source_map( ) . next_point( start_span) . with_hi( call_span . hi( ) ) ]
167176 } else {
168177 // foo(1, 2, 3)
169178 // ^^^ - - - supplied 3 arguments
@@ -196,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
196205 ) ;
197206 }
198207
199- if let Some ( def_id) = def_id {
208+ if let Some ( def_id) = fn_def_id {
200209 if let Some ( def_span) = tcx. def_ident_span ( def_id) {
201210 let mut spans: MultiSpan = def_span. into ( ) ;
202211
@@ -218,7 +227,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
218227 }
219228
220229 if sugg_unit {
221- let sugg_span = tcx. sess . source_map ( ) . end_point ( expr . span ) ;
230+ let sugg_span = tcx. sess . source_map ( ) . end_point ( call_expr . span ) ;
222231 // remove closing `)` from the span
223232 let sugg_span = sugg_span. shrink_to_lo ( ) ;
224233 err. span_suggestion (
@@ -240,15 +249,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
240249 err. emit ( ) ;
241250 } ;
242251
243- let mut expected_arg_tys = expected_arg_tys . to_vec ( ) ;
252+ let mut expected_arg_tys = expected_input_tys . to_vec ( ) ;
244253
245254 let formal_tys = if tuple_arguments == TupleArguments {
246- let tuple_type = self . structurally_resolved_type ( sp , fn_inputs [ 0 ] ) ;
255+ let tuple_type = self . structurally_resolved_type ( call_span , formal_input_tys [ 0 ] ) ;
247256 match tuple_type. kind ( ) {
248- ty:: Tuple ( arg_types) if arg_types. len ( ) != args . len ( ) => {
249- param_count_error ( arg_types. len ( ) , args . len ( ) , "E0057" , false , false ) ;
257+ ty:: Tuple ( arg_types) if arg_types. len ( ) != provided_args . len ( ) => {
258+ param_count_error ( arg_types. len ( ) , provided_args . len ( ) , "E0057" , false , false ) ;
250259 expected_arg_tys = vec ! [ ] ;
251- self . err_args ( args . len ( ) )
260+ self . err_args ( provided_args . len ( ) )
252261 }
253262 ty:: Tuple ( arg_types) => {
254263 expected_arg_tys = match expected_arg_tys. get ( 0 ) {
@@ -263,21 +272,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
263272 _ => {
264273 struct_span_err ! (
265274 tcx. sess,
266- sp ,
275+ call_span ,
267276 E0059 ,
268277 "cannot use call notation; the first type parameter \
269278 for the function trait is neither a tuple nor unit"
270279 )
271280 . emit ( ) ;
272281 expected_arg_tys = vec ! [ ] ;
273- self . err_args ( args . len ( ) )
282+ self . err_args ( provided_args . len ( ) )
274283 }
275284 }
276285 } else if expected_arg_count == supplied_arg_count {
277- fn_inputs . to_vec ( )
286+ formal_input_tys . to_vec ( )
278287 } else if c_variadic {
279288 if supplied_arg_count >= expected_arg_count {
280- fn_inputs . to_vec ( )
289+ formal_input_tys . to_vec ( )
281290 } else {
282291 param_count_error ( expected_arg_count, supplied_arg_count, "E0060" , true , false ) ;
283292 expected_arg_tys = vec ! [ ] ;
@@ -287,8 +296,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
287296 // is the missing argument of type `()`?
288297 let sugg_unit = if expected_arg_tys. len ( ) == 1 && supplied_arg_count == 0 {
289298 self . resolve_vars_if_possible ( expected_arg_tys[ 0 ] ) . is_unit ( )
290- } else if fn_inputs . len ( ) == 1 && supplied_arg_count == 0 {
291- self . resolve_vars_if_possible ( fn_inputs [ 0 ] ) . is_unit ( )
299+ } else if formal_input_tys . len ( ) == 1 && supplied_arg_count == 0 {
300+ self . resolve_vars_if_possible ( formal_input_tys [ 0 ] ) . is_unit ( )
292301 } else {
293302 false
294303 } ;
@@ -322,13 +331,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
322331 // the call. This helps coercions.
323332 if check_closures {
324333 self . select_obligations_where_possible ( false , |errors| {
325- self . point_at_type_arg_instead_of_call_if_possible ( errors, expr ) ;
334+ self . point_at_type_arg_instead_of_call_if_possible ( errors, call_expr ) ;
326335 self . point_at_arg_instead_of_call_if_possible (
327336 errors,
328337 & final_arg_types,
329- expr ,
330- sp ,
331- & args ,
338+ call_expr ,
339+ call_span ,
340+ & provided_args ,
332341 ) ;
333342 } )
334343 }
@@ -339,11 +348,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339348 let t = if c_variadic {
340349 expected_arg_count
341350 } else if tuple_arguments == TupleArguments {
342- args . len ( )
351+ provided_args . len ( )
343352 } else {
344353 supplied_arg_count
345354 } ;
346- for ( i, arg) in args . iter ( ) . take ( t) . enumerate ( ) {
355+ for ( i, arg) in provided_args . iter ( ) . take ( t) . enumerate ( ) {
347356 // Warn only for the first loop (the "no closures" one).
348357 // Closure arguments themselves can't be diverging, but
349358 // a previous argument can, e.g., `foo(panic!(), || {})`.
@@ -380,13 +389,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
380389 let _ = self . resolve_vars_with_obligations_and_mutate_fulfillment (
381390 coerce_ty,
382391 |errors| {
383- self . point_at_type_arg_instead_of_call_if_possible ( errors, expr ) ;
392+ self . point_at_type_arg_instead_of_call_if_possible ( errors, call_expr ) ;
384393 self . point_at_arg_instead_of_call_if_possible (
385394 errors,
386395 & final_arg_types,
387- expr ,
388- sp ,
389- args ,
396+ call_expr ,
397+ call_span ,
398+ provided_args ,
390399 ) ;
391400 } ,
392401 ) ;
@@ -410,7 +419,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
410419 MissingCastForVariadicArg { sess, span, ty, cast_ty } . diagnostic ( ) . emit ( )
411420 }
412421
413- for arg in args . iter ( ) . skip ( expected_arg_count) {
422+ for arg in provided_args . iter ( ) . skip ( expected_arg_count) {
414423 let arg_ty = self . check_expr ( & arg) ;
415424
416425 // There are a few types which get autopromoted when passed via varargs
0 commit comments