@@ -16,6 +16,7 @@ use rustc_hir::{CoroutineKind, CoroutineSource, LangItem};
16
16
use rustc_middle:: bug;
17
17
use rustc_middle:: hir:: nested_filter:: OnlyBodies ;
18
18
use rustc_middle:: mir:: tcx:: PlaceTy ;
19
+ use rustc_middle:: mir:: VarDebugInfoContents ;
19
20
use rustc_middle:: mir:: {
20
21
self , AggregateKind , BindingForm , BorrowKind , CallSource , ClearCrossCrate , ConstraintCategory ,
21
22
FakeBorrowKind , FakeReadCause , LocalDecl , LocalInfo , LocalKind , Location , MutBorrowKind ,
@@ -495,7 +496,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
495
496
}
496
497
}
497
498
498
- self . suggest_ref_for_dbg_args ( expr, span , move_span, err) ;
499
+ self . suggest_ref_for_dbg_args ( expr, place , move_span, err) ;
499
500
500
501
// it's useless to suggest inserting `ref` when the span don't comes from local code
501
502
if let Some ( pat) = finder. pat
@@ -522,22 +523,23 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
522
523
fn suggest_ref_for_dbg_args (
523
524
& self ,
524
525
body : & hir:: Expr < ' _ > ,
525
- span : Option < Span > ,
526
+ place : & Place < ' tcx > ,
526
527
move_span : Span ,
527
- err : & mut Diag < ' tcx > ,
528
+ err : & mut Diag < ' infcx > ,
528
529
) {
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
530
+ let var_info = self . body . var_debug_info . iter ( ) . find ( |info| match info. value {
531
+ VarDebugInfoContents :: Place ( ref p) => p == place,
532
+ _ => false ,
533
+ } ) ;
534
+ let arg_name = if let Some ( var_info) = var_info {
535
+ var_info. name . to_string ( )
534
536
} else {
535
537
return ;
536
538
} ;
537
539
struct MatchArgFinder {
538
540
expr_span : Span ,
539
541
match_arg_span : Option < Span > ,
540
- arg_code : String ,
542
+ arg_name : String ,
541
543
}
542
544
impl Visitor < ' _ > for MatchArgFinder {
543
545
fn visit_expr ( & mut self , e : & hir:: Expr < ' _ > ) {
@@ -547,7 +549,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
547
549
_,
548
550
path @ Path { segments : [ seg] , .. } ,
549
551
) ) = & expr. kind
550
- && seg. ident . name . as_str ( ) == & self . arg_code
552
+ && seg. ident . name . as_str ( ) == & self . arg_name
551
553
&& self . expr_span . source_callsite ( ) . contains ( expr. span )
552
554
{
553
555
self . match_arg_span = Some ( path. span ) ;
@@ -556,7 +558,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
556
558
}
557
559
}
558
560
559
- let mut finder = MatchArgFinder { expr_span : move_span, match_arg_span : None , arg_code } ;
561
+ let mut finder = MatchArgFinder { expr_span : move_span, match_arg_span : None , arg_name } ;
560
562
finder. visit_expr ( body) ;
561
563
if let Some ( macro_arg_span) = finder. match_arg_span {
562
564
err. span_suggestion_verbose (
0 commit comments