Skip to content

Commit ec4a464

Browse files
estebankcuviper
authored andcommitted
Change next_point when shrink_to_hi is more appropriate
(cherry picked from commit b93ef68)
1 parent 89c526a commit ec4a464

File tree

8 files changed

+13
-17
lines changed

8 files changed

+13
-17
lines changed

src/librustc_parse/parser/diagnostics.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,13 @@ impl<'a> Parser<'a> {
300300
expect.clone()
301301
};
302302
(format!("expected one of {}, found {}", expect, actual),
303-
(self.sess.source_map().next_point(self.prev_span),
304-
format!("expected one of {}", short_expect)))
303+
(self.prev_span.shrink_to_hi(), format!("expected one of {}", short_expect)))
305304
} else if expected.is_empty() {
306305
(format!("unexpected token: {}", actual),
307306
(self.prev_span, "unexpected token after this".to_string()))
308307
} else {
309308
(format!("expected {}, found {}", expect, actual),
310-
(self.sess.source_map().next_point(self.prev_span),
311-
format!("expected {}", expect)))
309+
(self.prev_span.shrink_to_hi(), format!("expected {}", expect)))
312310
};
313311
self.last_unexpected_token_span = Some(self.token.span);
314312
let mut err = self.fatal(&msg_exp);
@@ -871,7 +869,7 @@ impl<'a> Parser<'a> {
871869
_ if self.prev_span == DUMMY_SP => (self.token.span, self.token.span),
872870
// EOF, don't want to point at the following char, but rather the last token.
873871
(token::Eof, None) => (self.prev_span, self.token.span),
874-
_ => (self.sess.source_map().next_point(self.prev_span), self.token.span),
872+
_ => (self.prev_span.shrink_to_hi(), self.token.span),
875873
};
876874
let msg = format!(
877875
"expected `{}`, found {}",
@@ -1179,7 +1177,7 @@ impl<'a> Parser<'a> {
11791177
err.span_label(sp, "unclosed delimiter");
11801178
}
11811179
err.span_suggestion_short(
1182-
self.sess.source_map().next_point(self.prev_span),
1180+
self.prev_span.shrink_to_hi(),
11831181
&format!("{} may belong here", delim.to_string()),
11841182
delim.to_string(),
11851183
Applicability::MaybeIncorrect,

src/librustc_parse/parser/expr.rs

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

src/librustc_parse/parser/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ impl<'a> Parser<'a> {
17061706
// it's safe to peel off one character only when it has the close delim
17071707
self.prev_span.with_lo(self.prev_span.hi() - BytePos(1))
17081708
} else {
1709-
self.sess.source_map().next_point(self.prev_span)
1709+
self.prev_span.shrink_to_hi()
17101710
};
17111711

17121712
self.struct_span_err(
@@ -1720,7 +1720,7 @@ impl<'a> Parser<'a> {
17201720
],
17211721
Applicability::MaybeIncorrect,
17221722
).span_suggestion(
1723-
self.sess.source_map().next_point(self.prev_span),
1723+
self.prev_span.shrink_to_hi(),
17241724
"add a semicolon",
17251725
';'.to_string(),
17261726
Applicability::MaybeIncorrect,

src/librustc_parse/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ impl<'a> Parser<'a> {
803803
break;
804804
}
805805
Err(mut expect_err) => {
806-
let sp = self.sess.source_map().next_point(self.prev_span);
806+
let sp = self.prev_span.shrink_to_hi();
807807
let token_str = pprust::token_kind_to_string(t);
808808

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

src/librustc_typeck/check/callee.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
hir::ExprKind::Block(..),
255255
) = (parent_node, callee_node) {
256256
let start = sp.shrink_to_lo();
257-
let end = self.tcx.sess.source_map().next_point(callee_span);
257+
let end = callee_span.shrink_to_hi();
258258
err.multipart_suggestion(
259259
"if you meant to create this closure and immediately call it, surround the \
260260
closure with parenthesis",
@@ -332,9 +332,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
332332
let call_is_multiline =
333333
self.tcx.sess.source_map().is_multiline(call_expr.span);
334334
if call_is_multiline {
335-
let span = self.tcx.sess.source_map().next_point(callee.span);
336335
err.span_suggestion(
337-
span,
336+
callee.span.shrink_to_hi(),
338337
"try adding a semicolon",
339338
";".to_owned(),
340339
Applicability::MaybeIncorrect,

src/librustc_typeck/check/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4834,9 +4834,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
48344834
ExprKind::Loop(..) |
48354835
ExprKind::Match(..) |
48364836
ExprKind::Block(..) => {
4837-
let sp = self.tcx.sess.source_map().next_point(cause_span);
48384837
err.span_suggestion(
4839-
sp,
4838+
cause_span.shrink_to_hi(),
48404839
"try adding a semicolon",
48414840
";".to_string(),
48424841
Applicability::MachineApplicable);

src/libsyntax_expand/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ pub(super) fn parse(
708708
Token::new(token::Eof, if parser.token.span.is_dummy() {
709709
parser.token.span
710710
} else {
711-
sess.source_map().next_point(parser.token.span)
711+
parser.token.span.shrink_to_hi()
712712
}),
713713
"missing tokens in macro arguments",
714714
);

src/libsyntax_ext/assert.rs

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

0 commit comments

Comments
 (0)