Skip to content

Commit

Permalink
use var_debug_info for arg_name
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 4, 2024
1 parent ab7b29d commit b01c541
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,20 +524,21 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
body: &hir::Expr<'_>,
span: Option<Span>,
move_span: Span,
err: &mut Diag<'tcx>,
err: &mut Diag<'infcx>,
) {
let sm = self.infcx.tcx.sess.source_map();
let arg_code = if let Some(span) = span
&& let Ok(code) = sm.span_to_snippet(span)
{
code
let Some(span) = span else {
return;
};
let var_info = self.body.var_debug_info.iter().find(|info| info.source_info.span == span);
let arg_name = if let Some(var_info) = var_info {
var_info.name.to_string()
} else {
return;
};
struct MatchArgFinder {
expr_span: Span,
match_arg_span: Option<Span>,
arg_code: String,
arg_name: String,
}
impl Visitor<'_> for MatchArgFinder {
fn visit_expr(&mut self, e: &hir::Expr<'_>) {
Expand All @@ -547,7 +548,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
_,
path @ Path { segments: [seg], .. },
)) = &expr.kind
&& seg.ident.name.as_str() == &self.arg_code
&& seg.ident.name.as_str() == &self.arg_name
&& self.expr_span.source_callsite().contains(expr.span)
{
self.match_arg_span = Some(path.span);
Expand All @@ -556,7 +557,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
}
}

let mut finder = MatchArgFinder { expr_span: move_span, match_arg_span: None, arg_code };
let mut finder = MatchArgFinder { expr_span: move_span, match_arg_span: None, arg_name };
finder.visit_expr(body);
if let Some(macro_arg_span) = finder.match_arg_span {
err.span_suggestion_verbose(
Expand Down

0 comments on commit b01c541

Please sign in to comment.