Skip to content

Commit b93ef68

Browse files
committed
Change next_point when shrink_to_hi is more appropriate
1 parent d558f6a commit b93ef68

File tree

8 files changed

+13
-18
lines changed

8 files changed

+13
-18
lines changed

src/librustc_builtin_macros/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn parse_assert<'a>(
106106
let custom_message =
107107
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
108108
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
109-
let comma_span = cx.source_map().next_point(parser.prev_span);
109+
let comma_span = parser.prev_span.shrink_to_hi();
110110
err.span_suggestion_short(
111111
comma_span,
112112
"try adding a comma",

src/librustc_expand/mbe/macro_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ pub(super) fn parse(
696696
if parser.token.span.is_dummy() {
697697
parser.token.span
698698
} else {
699-
sess.source_map().next_point(parser.token.span)
699+
parser.token.span.shrink_to_hi()
700700
},
701701
),
702702
"missing tokens in macro arguments",

src/librustc_parse/parser/diagnostics.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,7 @@ impl<'a> Parser<'a> {
265265
};
266266
(
267267
format!("expected one of {}, found {}", expect, actual),
268-
(
269-
self.sess.source_map().next_point(self.prev_span),
270-
format!("expected one of {}", short_expect),
271-
),
268+
(self.prev_span.shrink_to_hi(), format!("expected one of {}", short_expect)),
272269
)
273270
} else if expected.is_empty() {
274271
(
@@ -278,7 +275,7 @@ impl<'a> Parser<'a> {
278275
} else {
279276
(
280277
format!("expected {}, found {}", expect, actual),
281-
(self.sess.source_map().next_point(self.prev_span), format!("expected {}", expect)),
278+
(self.prev_span.shrink_to_hi(), format!("expected {}", expect)),
282279
)
283280
};
284281
self.last_unexpected_token_span = Some(self.token.span);
@@ -809,7 +806,7 @@ impl<'a> Parser<'a> {
809806
_ if self.prev_span == DUMMY_SP => (self.token.span, self.token.span),
810807
// EOF, don't want to point at the following char, but rather the last token.
811808
(token::Eof, None) => (self.prev_span, self.token.span),
812-
_ => (self.sess.source_map().next_point(self.prev_span), self.token.span),
809+
_ => (self.prev_span.shrink_to_hi(), self.token.span),
813810
};
814811
let msg = format!(
815812
"expected `{}`, found {}",
@@ -1132,7 +1129,7 @@ impl<'a> Parser<'a> {
11321129
err.span_label(sp, "unclosed delimiter");
11331130
}
11341131
err.span_suggestion_short(
1135-
self.sess.source_map().next_point(self.prev_span),
1132+
self.prev_span.shrink_to_hi(),
11361133
&format!("{} may belong here", delim.to_string()),
11371134
delim.to_string(),
11381135
Applicability::MaybeIncorrect,

src/librustc_parse/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ impl<'a> Parser<'a> {
16461646
// | |
16471647
// | parsed until here as `"y" & X`
16481648
err.span_suggestion_short(
1649-
cm.next_point(arm_start_span),
1649+
arm_start_span.shrink_to_hi(),
16501650
"missing a comma here to end this `match` arm",
16511651
",".to_owned(),
16521652
Applicability::MachineApplicable,

src/librustc_parse/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ impl<'a> Parser<'a> {
16281628
// it's safe to peel off one character only when it has the close delim
16291629
self.prev_span.with_lo(self.prev_span.hi() - BytePos(1))
16301630
} else {
1631-
self.sess.source_map().next_point(self.prev_span)
1631+
self.prev_span.shrink_to_hi()
16321632
};
16331633

16341634
self.struct_span_err(
@@ -1644,7 +1644,7 @@ impl<'a> Parser<'a> {
16441644
Applicability::MaybeIncorrect,
16451645
)
16461646
.span_suggestion(
1647-
self.sess.source_map().next_point(self.prev_span),
1647+
self.prev_span.shrink_to_hi(),
16481648
"add a semicolon",
16491649
';'.to_string(),
16501650
Applicability::MaybeIncorrect,

src/librustc_parse/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'a> Parser<'a> {
765765
break;
766766
}
767767
Err(mut expect_err) => {
768-
let sp = self.sess.source_map().next_point(self.prev_span);
768+
let sp = self.prev_span.shrink_to_hi();
769769
let token_str = pprust::token_kind_to_string(t);
770770

771771
// Attempt to keep parsing if it was a similar separator.

src/librustc_typeck/check/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
242242
) = (parent_node, callee_node)
243243
{
244244
let start = sp.shrink_to_lo();
245-
let end = self.tcx.sess.source_map().next_point(callee_span);
245+
let end = callee_span.shrink_to_hi();
246246
err.multipart_suggestion(
247247
"if you meant to create this closure and immediately call it, surround the \
248248
closure with parenthesis",
@@ -319,9 +319,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
319319
let call_is_multiline =
320320
self.tcx.sess.source_map().is_multiline(call_expr.span);
321321
if call_is_multiline {
322-
let span = self.tcx.sess.source_map().next_point(callee.span);
323322
err.span_suggestion(
324-
span,
323+
callee.span.shrink_to_hi(),
325324
"try adding a semicolon",
326325
";".to_owned(),
327326
Applicability::MaybeIncorrect,

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4953,9 +4953,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
49534953
| ExprKind::Loop(..)
49544954
| ExprKind::Match(..)
49554955
| ExprKind::Block(..) => {
4956-
let sp = self.tcx.sess.source_map().next_point(cause_span);
49574956
err.span_suggestion(
4958-
sp,
4957+
cause_span.shrink_to_hi(),
49594958
"try adding a semicolon",
49604959
";".to_string(),
49614960
Applicability::MachineApplicable,

0 commit comments

Comments
 (0)