@@ -473,38 +473,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473
473
call_expr : & hir:: Expr < ' tcx > ,
474
474
) {
475
475
// Next, let's construct the error
476
- let ( error_span, full_call_span, ctor_of , is_method) = match & call_expr. kind {
476
+ let ( error_span, full_call_span, call_name , is_method) = match & call_expr. kind {
477
477
hir:: ExprKind :: Call (
478
478
hir:: Expr { hir_id, span, kind : hir:: ExprKind :: Path ( qpath) , .. } ,
479
479
_,
480
480
) => {
481
481
if let Res :: Def ( DefKind :: Ctor ( of, _) , _) =
482
482
self . typeck_results . borrow ( ) . qpath_res ( qpath, * hir_id)
483
483
{
484
- ( call_span, * span, Some ( of) , false )
484
+ let name = match of {
485
+ CtorOf :: Struct => "struct" ,
486
+ CtorOf :: Variant => "enum variant" ,
487
+ } ;
488
+ ( call_span, * span, name, false )
485
489
} else {
486
- ( call_span, * span, None , false )
490
+ ( call_span, * span, "function" , false )
487
491
}
488
492
}
489
- hir:: ExprKind :: Call ( hir:: Expr { span, .. } , _) => ( call_span, * span, None , false ) ,
493
+ hir:: ExprKind :: Call ( hir:: Expr { span, .. } , _) => ( call_span, * span, "function" , false ) ,
490
494
hir:: ExprKind :: MethodCall ( path_segment, _, _, span) => {
491
495
let ident_span = path_segment. ident . span ;
492
496
let ident_span = if let Some ( args) = path_segment. args {
493
497
ident_span. with_hi ( args. span_ext . hi ( ) )
494
498
} else {
495
499
ident_span
496
500
} ;
497
- // methods are never ctors
498
- ( * span, ident_span, None , true )
501
+ ( * span, ident_span, "method" , true )
499
502
}
500
503
k => span_bug ! ( call_span, "checking argument types on a non-call: `{:?}`" , k) ,
501
504
} ;
502
505
let args_span = error_span. trim_start ( full_call_span) . unwrap_or ( error_span) ;
503
- let call_name = match ctor_of {
504
- Some ( CtorOf :: Struct ) => "struct" ,
505
- Some ( CtorOf :: Variant ) => "enum variant" ,
506
- None => "function" ,
507
- } ;
508
506
509
507
// Don't print if it has error types or is just plain `_`
510
508
fn has_error_or_infer < ' tcx > ( tys : impl IntoIterator < Item = Ty < ' tcx > > ) -> bool {
@@ -690,8 +688,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
690
688
err = tcx. sess . struct_span_err_with_code (
691
689
full_call_span,
692
690
& format ! (
693
- "this {} takes {}{} but {} {} supplied" ,
694
- call_name,
691
+ "{call_name} takes {}{} but {} {} supplied" ,
695
692
if c_variadic { "at least " } else { "" } ,
696
693
potentially_plural_count(
697
694
formal_and_expected_inputs. len( ) ,
0 commit comments