Skip to content

Commit 1767432

Browse files
committed
use var_debug_info for arg_name
1 parent ab7b29d commit 1767432

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_hir::{CoroutineKind, CoroutineSource, LangItem};
1616
use rustc_middle::bug;
1717
use rustc_middle::hir::nested_filter::OnlyBodies;
1818
use rustc_middle::mir::tcx::PlaceTy;
19+
use rustc_middle::mir::VarDebugInfoContents;
1920
use rustc_middle::mir::{
2021
self, AggregateKind, BindingForm, BorrowKind, CallSource, ClearCrossCrate, ConstraintCategory,
2122
FakeBorrowKind, FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, MutBorrowKind,
@@ -495,7 +496,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
495496
}
496497
}
497498

498-
self.suggest_ref_for_dbg_args(expr, span, move_span, err);
499+
self.suggest_ref_for_dbg_args(expr, place, move_span, err);
499500

500501
// it's useless to suggest inserting `ref` when the span don't comes from local code
501502
if let Some(pat) = finder.pat
@@ -522,22 +523,23 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
522523
fn suggest_ref_for_dbg_args(
523524
&self,
524525
body: &hir::Expr<'_>,
525-
span: Option<Span>,
526+
place: &Place<'tcx>,
526527
move_span: Span,
527-
err: &mut Diag<'tcx>,
528+
err: &mut Diag<'infcx>,
528529
) {
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()
534536
} else {
535537
return;
536538
};
537539
struct MatchArgFinder {
538540
expr_span: Span,
539541
match_arg_span: Option<Span>,
540-
arg_code: String,
542+
arg_name: String,
541543
}
542544
impl Visitor<'_> for MatchArgFinder {
543545
fn visit_expr(&mut self, e: &hir::Expr<'_>) {
@@ -547,7 +549,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
547549
_,
548550
path @ Path { segments: [seg], .. },
549551
)) = &expr.kind
550-
&& seg.ident.name.as_str() == &self.arg_code
552+
&& seg.ident.name.as_str() == &self.arg_name
551553
&& self.expr_span.source_callsite().contains(expr.span)
552554
{
553555
self.match_arg_span = Some(path.span);
@@ -556,7 +558,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
556558
}
557559
}
558560

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 };
560562
finder.visit_expr(body);
561563
if let Some(macro_arg_span) = finder.match_arg_span {
562564
err.span_suggestion_verbose(

0 commit comments

Comments
 (0)