@@ -524,20 +524,21 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
524
524
body : & hir:: Expr < ' _ > ,
525
525
span : Option < Span > ,
526
526
move_span : Span ,
527
- err : & mut Diag < ' tcx > ,
527
+ err : & mut Diag < ' infcx > ,
528
528
) {
529
- let sm = self . infcx . tcx . sess . source_map ( ) ;
530
- let arg_code = if let Some ( span) = span
531
- && let Ok ( code) = sm. span_to_snippet ( span)
532
- {
533
- code
529
+ let Some ( span) = span else {
530
+ return ;
531
+ } ;
532
+ let var_info = self . body . var_debug_info . iter ( ) . find ( |info| info. source_info . span == span) ;
533
+ let arg_name = if let Some ( var_info) = var_info {
534
+ var_info. name . to_string ( )
534
535
} else {
535
536
return ;
536
537
} ;
537
538
struct MatchArgFinder {
538
539
expr_span : Span ,
539
540
match_arg_span : Option < Span > ,
540
- arg_code : String ,
541
+ arg_name : String ,
541
542
}
542
543
impl Visitor < ' _ > for MatchArgFinder {
543
544
fn visit_expr ( & mut self , e : & hir:: Expr < ' _ > ) {
@@ -547,7 +548,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
547
548
_,
548
549
path @ Path { segments : [ seg] , .. } ,
549
550
) ) = & expr. kind
550
- && seg. ident . name . as_str ( ) == & self . arg_code
551
+ && seg. ident . name . as_str ( ) == & self . arg_name
551
552
&& self . expr_span . source_callsite ( ) . contains ( expr. span )
552
553
{
553
554
self . match_arg_span = Some ( path. span ) ;
@@ -556,7 +557,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
556
557
}
557
558
}
558
559
559
- let mut finder = MatchArgFinder { expr_span : move_span, match_arg_span : None , arg_code } ;
560
+ let mut finder = MatchArgFinder { expr_span : move_span, match_arg_span : None , arg_name } ;
560
561
finder. visit_expr ( body) ;
561
562
if let Some ( macro_arg_span) = finder. match_arg_span {
562
563
err. span_suggestion_verbose (
0 commit comments