@@ -415,14 +415,17 @@ declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE
415
415
416
416
impl LateLintPass < ' _ > for Diagnostics {
417
417
fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
418
+ let collect_args_tys_and_spans = |args : & [ Expr < ' _ > ] , reserve_one_extra : bool | {
419
+ let mut result = Vec :: with_capacity ( args. len ( ) + usize:: from ( reserve_one_extra) ) ;
420
+ result. extend ( args. iter ( ) . map ( |arg| ( cx. typeck_results ( ) . expr_ty ( arg) , arg. span ) ) ) ;
421
+ result
422
+ } ;
418
423
// Only check function calls and method calls.
419
- let ( span, def_id, fn_gen_args, call_tys ) = match expr. kind {
424
+ let ( span, def_id, fn_gen_args, arg_tys_and_spans ) = match expr. kind {
420
425
ExprKind :: Call ( callee, args) => {
421
426
match cx. typeck_results ( ) . node_type ( callee. hir_id ) . kind ( ) {
422
427
& ty:: FnDef ( def_id, fn_gen_args) => {
423
- let call_tys: Vec < _ > =
424
- args. iter ( ) . map ( |arg| cx. typeck_results ( ) . expr_ty ( arg) ) . collect ( ) ;
425
- ( callee. span , def_id, fn_gen_args, call_tys)
428
+ ( callee. span , def_id, fn_gen_args, collect_args_tys_and_spans ( args, false ) )
426
429
}
427
430
_ => return , // occurs for fns passed as args
428
431
}
@@ -432,10 +435,9 @@ impl LateLintPass<'_> for Diagnostics {
432
435
else {
433
436
return ;
434
437
} ;
435
- let mut call_tys: Vec < _ > =
436
- args. iter ( ) . map ( |arg| cx. typeck_results ( ) . expr_ty ( arg) ) . collect ( ) ;
437
- call_tys. insert ( 0 , cx. tcx . types . self_param ) ; // dummy inserted for `self`
438
- ( span, def_id, fn_gen_args, call_tys)
438
+ let mut args = collect_args_tys_and_spans ( args, true ) ;
439
+ args. insert ( 0 , ( cx. tcx . types . self_param , _recv. span ) ) ; // dummy inserted for `self`
440
+ ( span, def_id, fn_gen_args, args)
439
441
}
440
442
_ => return ,
441
443
} ;
@@ -525,11 +527,11 @@ impl LateLintPass<'_> for Diagnostics {
525
527
// `UNTRANSLATABLE_DIAGNOSTIC` lint.
526
528
for ( param_i, param_i_p_name) in impl_into_diagnostic_message_params {
527
529
// Is the arg type `{Sub,D}iagMessage`or `impl Into<{Sub,D}iagMessage>`?
528
- let arg_ty = call_tys [ param_i] ;
530
+ let ( arg_ty, arg_span ) = arg_tys_and_spans [ param_i] ;
529
531
let is_translatable = is_diag_message ( arg_ty)
530
532
|| matches ! ( arg_ty. kind( ) , ty:: Param ( p) if p. name == param_i_p_name) ;
531
533
if !is_translatable {
532
- cx. emit_span_lint ( UNTRANSLATABLE_DIAGNOSTIC , span , UntranslatableDiag ) ;
534
+ cx. emit_span_lint ( UNTRANSLATABLE_DIAGNOSTIC , arg_span , UntranslatableDiag ) ;
533
535
}
534
536
}
535
537
}
0 commit comments