@@ -415,14 +415,17 @@ declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE
415415
416416impl LateLintPass < ' _ > for Diagnostics {
417417 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+ } ;
418423 // 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 {
420425 ExprKind :: Call ( callee, args) => {
421426 match cx. typeck_results ( ) . node_type ( callee. hir_id ) . kind ( ) {
422427 & 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 ) )
426429 }
427430 _ => return , // occurs for fns passed as args
428431 }
@@ -432,10 +435,9 @@ impl LateLintPass<'_> for Diagnostics {
432435 else {
433436 return ;
434437 } ;
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)
439441 }
440442 _ => return ,
441443 } ;
@@ -525,11 +527,11 @@ impl LateLintPass<'_> for Diagnostics {
525527 // `UNTRANSLATABLE_DIAGNOSTIC` lint.
526528 for ( param_i, param_i_p_name) in impl_into_diagnostic_message_params {
527529 // 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] ;
529531 let is_translatable = is_diag_message ( arg_ty)
530532 || matches ! ( arg_ty. kind( ) , ty:: Param ( p) if p. name == param_i_p_name) ;
531533 if !is_translatable {
532- cx. emit_span_lint ( UNTRANSLATABLE_DIAGNOSTIC , span , UntranslatableDiag ) ;
534+ cx. emit_span_lint ( UNTRANSLATABLE_DIAGNOSTIC , arg_span , UntranslatableDiag ) ;
533535 }
534536 }
535537 }
0 commit comments