Skip to content

Commit

Permalink
hir_typeck: use end_point over BytePos manipulations
Browse files Browse the repository at this point in the history
Parser has error recovery for Unicode-confusables, which includes the
right parentheses `)`. If a multi-byte right parentheses look-alike
reaches the argument removal suggestion diagnostics, it would trigger an
assertion because the diagnostics used `- BytePos(1)` which can land
within a multi-byte codepoint.

This is fixed by using `SourceMap::end_point` to find the final right
delimiter codepoint, which correctly respects codepoint boundaries.
  • Loading branch information
jieyouxu committed Aug 9, 2024
1 parent b589f86 commit 879bfd7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_session::Session;
use rustc_span::symbol::{kw, Ident};
use rustc_span::{sym, BytePos, Span, DUMMY_SP};
use rustc_span::{sym, Span, DUMMY_SP};
use rustc_trait_selection::error_reporting::infer::{FailureCode, ObligationCauseExt};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
Expand Down Expand Up @@ -1140,8 +1140,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.get(arg_idx + 1)
.map(|&(_, sp)| sp)
.unwrap_or_else(|| {
// Subtract one to move before `)`
call_expr.span.with_lo(call_expr.span.hi() - BytePos(1))
// Try to move before `)`. Note that `)` here is not necessarily
// the latin right paren, it could be a Unicode-confusable that
// looks like a `)`, so we must not use `- BytePos(1)`
// manipulations here.
self.tcx().sess.source_map().end_point(call_expr.span)
});

// Include next comma
Expand Down

0 comments on commit 879bfd7

Please sign in to comment.