Skip to content

Commit 0af255a

Browse files
committed
Fix the bug of next_point in span
1 parent 11432fe commit 0af255a

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

compiler/rustc_expand/src/expand.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,12 @@ pub fn ensure_complete_parse<'a>(
937937
kind_name,
938938
);
939939
err.note(&msg);
940-
let semi_span = this.sess.source_map().next_point(span);
941940

942-
let semi_full_span = semi_span.to(this.sess.source_map().next_point(semi_span));
943-
match this.sess.source_map().span_to_snippet(semi_full_span) {
941+
let semi_span = this.sess.source_map().next_point(span);
942+
match this.sess.source_map().span_to_snippet(semi_span) {
944943
Ok(ref snippet) if &snippet[..] != ";" && kind_name == "expression" => {
945944
err.span_suggestion(
946-
semi_span,
945+
span.shrink_to_hi(),
947946
"you might be missing a semicolon here",
948947
";",
949948
Applicability::MaybeIncorrect,

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn emit_frag_parse_err(
8282
);
8383
if !e.span.is_dummy() {
8484
// early end of macro arm (#52866)
85-
e.replace_span_with(parser.sess.source_map().next_point(parser.token.span));
85+
e.replace_span_with(parser.token.span.shrink_to_hi());
8686
}
8787
}
8888
if e.span.is_dummy() {

compiler/rustc_parse/src/parser/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ impl<'a> Parser<'a> {
14611461
let (prev_sp, sp) = match (&self.token.kind, self.subparser_name) {
14621462
// Point at the end of the macro call when reaching end of macro arguments.
14631463
(token::Eof, Some(_)) => {
1464-
let sp = self.sess.source_map().next_point(self.prev_token.span);
1464+
let sp = self.prev_token.span.shrink_to_hi();
14651465
(sp, sp)
14661466
}
14671467
// We don't want to point at the following span after DUMMY_SP.
@@ -2039,7 +2039,7 @@ impl<'a> Parser<'a> {
20392039
pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
20402040
let (span, msg) = match (&self.token.kind, self.subparser_name) {
20412041
(&token::Eof, Some(origin)) => {
2042-
let sp = self.sess.source_map().next_point(self.prev_token.span);
2042+
let sp = self.prev_token.span.shrink_to_hi();
20432043
(sp, format!("expected expression, found end of {origin}"))
20442044
}
20452045
_ => (

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ impl<'a> Parser<'a> {
21722172
},
21732173
ExprKind::Block(_, None) => {
21742174
self.sess.emit_err(IfExpressionMissingCondition {
2175-
if_span: self.sess.source_map().next_point(lo),
2175+
if_span: lo.shrink_to_hi(),
21762176
block_span: self.sess.source_map().start_point(cond_span),
21772177
});
21782178
std::mem::replace(&mut cond, this.mk_expr_err(cond_span.shrink_to_hi()))

compiler/rustc_parse/src/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ impl<'a> Parser<'a> {
16011601
self.sess.emit_err(err);
16021602
} else {
16031603
if !seen_comma {
1604-
let sp = self.sess.source_map().next_point(previous_span);
1604+
let sp = previous_span.shrink_to_hi();
16051605
err.missing_comma = Some(sp);
16061606
}
16071607
return Err(err.into_diagnostic(&self.sess.span_diagnostic));

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
17311731
for _ in 0..100 {
17321732
// Try to find an assignment
17331733
sp = sm.next_point(sp);
1734-
let snippet = sm.span_to_snippet(sp.to(sm.next_point(sp)));
1734+
let snippet = sm.span_to_snippet(sp);
17351735
match snippet {
17361736
Ok(ref x) if x.as_str() == "=" => {
17371737
err.span_suggestion(

compiler/rustc_span/src/source_map.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,15 @@ impl SourceMap {
859859
}
860860
let start_of_next_point = sp.hi().0;
861861

862-
let width = self.find_width_of_character_at_span(sp.shrink_to_hi(), true);
862+
let width = self.find_width_of_character_at_span(sp, true);
863+
debug_assert!(width > 0);
863864
// If the width is 1, then the next span should point to the same `lo` and `hi`. However,
864865
// in the case of a multibyte character, where the width != 1, the next span should
865866
// span multiple bytes to include the whole character.
866867
let end_of_next_point =
867-
start_of_next_point.checked_add(width - 1).unwrap_or(start_of_next_point);
868+
start_of_next_point.checked_add(width).unwrap_or(start_of_next_point);
868869

869-
let end_of_next_point = BytePos(cmp::max(sp.lo().0 + 1, end_of_next_point));
870+
let end_of_next_point = BytePos(cmp::max(start_of_next_point + 1, end_of_next_point));
870871
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None)
871872
}
872873

0 commit comments

Comments
 (0)