Skip to content

Commit 8d85504

Browse files
committed
Auto merge of #41174 - estebank:issue-41155, r=nikomatsakis
Point at only one char on `Span::next_point` Avoid pointing at two chars so the diagnostic output doesn't display a multiline span when starting beyond a line end. Fix #41155. Instead of ```rust error: expected one of `(`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found `}` --> <anon>:3:1 | 1 | impl S { pub | _____________- starting here... 2 | | | | ...ending here: expected one of 7 possible tokens here 3 | } | ^ unexpected token ``` show ```rust error: expected one of `(`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found `}` --> <anon>:13:1 | 12 | pub | - expected one of 7 possible tokens here 13 | } | ^ unexpected token ```
2 parents 730e5ad + 4c80170 commit 8d85504

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/libsyntax/parse/parser.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,10 @@ impl<'a> Parser<'a> {
592592
} else {
593593
label_sp
594594
};
595-
err.span_label(sp, &label_exp);
596-
if !sp.source_equal(&self.span) {
595+
if self.span.contains(sp) {
596+
err.span_label(self.span, &label_exp);
597+
} else {
598+
err.span_label(sp, &label_exp);
597599
err.span_label(self.span, &"unexpected token");
598600
}
599601
Err(err)

src/libsyntax_pos/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Span {
8989
/// Returns a new span representing the next character after the end-point of this span
9090
pub fn next_point(self) -> Span {
9191
let lo = cmp::max(self.hi.0, self.lo.0 + 1);
92-
Span { lo: BytePos(lo), hi: BytePos(lo + 1), ..self }
92+
Span { lo: BytePos(lo), hi: BytePos(lo), ..self }
9393
}
9494

9595
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.

src/test/ui/token/issue-41155.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
impl S {
12+
pub
13+
}

src/test/ui/token/issue-41155.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `(`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found `}`
2+
--> $DIR/issue-41155.rs:13:1
3+
|
4+
12 | pub
5+
| - expected one of 7 possible tokens here
6+
13 | }
7+
| ^ unexpected token
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)