Auto merge of #46381 - estebank:expected-span, r=nikomatsakis
Point to next token when it is in the expected line r? @nikomatsakis
This commit is contained in:
commit
f9b0897c5d
4 changed files with 26 additions and 15 deletions
|
@ -358,7 +358,7 @@ impl CodeMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the relevant filemap is empty, we don't return a line number.
|
// If the relevant filemap is empty, we don't return a line number.
|
||||||
fn lookup_line(&self, pos: BytePos) -> Result<FileMapAndLine, Rc<FileMap>> {
|
pub fn lookup_line(&self, pos: BytePos) -> Result<FileMapAndLine, Rc<FileMap>> {
|
||||||
let idx = self.lookup_filemap_idx(pos);
|
let idx = self.lookup_filemap_idx(pos);
|
||||||
|
|
||||||
let files = self.files.borrow();
|
let files = self.files.borrow();
|
||||||
|
|
|
@ -660,11 +660,28 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
label_sp
|
label_sp
|
||||||
};
|
};
|
||||||
if self.span.contains(sp) {
|
|
||||||
err.span_label(self.span, label_exp);
|
let cm = self.sess.codemap();
|
||||||
} else {
|
match (cm.lookup_line(self.span.lo()), cm.lookup_line(sp.lo())) {
|
||||||
err.span_label(sp, label_exp);
|
(Ok(ref a), Ok(ref b)) if a.line == b.line => {
|
||||||
err.span_label(self.span, "unexpected token");
|
// When the spans are in the same line, it means that the only content between
|
||||||
|
// them is whitespace, point at the found token in that case:
|
||||||
|
//
|
||||||
|
// X | () => { syntax error };
|
||||||
|
// | ^^^^^ expected one of 8 possible tokens here
|
||||||
|
//
|
||||||
|
// instead of having:
|
||||||
|
//
|
||||||
|
// X | () => { syntax error };
|
||||||
|
// | -^^^^^ unexpected token
|
||||||
|
// | |
|
||||||
|
// | expected one of 8 possible tokens here
|
||||||
|
err.span_label(self.span, label_exp);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
err.span_label(sp, label_exp);
|
||||||
|
err.span_label(self.span, "unexpected token");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,7 @@ error: expected one of `!` or `::`, found `(`
|
||||||
--> $DIR/issue-40006.rs:24:9
|
--> $DIR/issue-40006.rs:24:9
|
||||||
|
|
|
|
||||||
24 | ::Y (); //~ ERROR expected one of
|
24 | ::Y (); //~ ERROR expected one of
|
||||||
| -^ unexpected token
|
| ^ expected one of `!` or `::` here
|
||||||
| |
|
|
||||||
| expected one of `!` or `::` here
|
|
||||||
|
|
||||||
error: missing `fn`, `type`, or `const` for impl-item declaration
|
error: missing `fn`, `type`, or `const` for impl-item declaration
|
||||||
--> $DIR/issue-40006.rs:28:8
|
--> $DIR/issue-40006.rs:28:8
|
||||||
|
|
|
@ -2,18 +2,14 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found
|
||||||
--> $DIR/main.rs:19:20
|
--> $DIR/main.rs:19:20
|
||||||
|
|
|
|
||||||
19 | () => { syntax error }; //~ ERROR expected one of
|
19 | () => { syntax error }; //~ ERROR expected one of
|
||||||
| -^^^^^ unexpected token
|
| ^^^^^ expected one of 8 possible tokens here
|
||||||
| |
|
|
||||||
| expected one of 8 possible tokens here
|
|
||||||
$DIR/main.rs:24:5: 24:13 note: in this expansion of pong! (defined in $DIR/main.rs)
|
$DIR/main.rs:24:5: 24:13 note: in this expansion of pong! (defined in $DIR/main.rs)
|
||||||
|
|
||||||
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
|
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
|
||||||
--> $DIR/main.rs:19:20
|
--> $DIR/main.rs:19:20
|
||||||
|
|
|
|
||||||
19 | () => { syntax error }; //~ ERROR expected one of
|
19 | () => { syntax error }; //~ ERROR expected one of
|
||||||
| -^^^^^ unexpected token
|
| ^^^^^ expected one of 8 possible tokens here
|
||||||
| |
|
|
||||||
| expected one of 8 possible tokens here
|
|
||||||
$DIR/main.rs:25:5: 25:13 note: in this expansion of ping! (defined in <ping macros>)
|
$DIR/main.rs:25:5: 25:13 note: in this expansion of ping! (defined in <ping macros>)
|
||||||
<ping macros>:1:11: 1:24 note: in this expansion of pong! (defined in $DIR/main.rs)
|
<ping macros>:1:11: 1:24 note: in this expansion of pong! (defined in $DIR/main.rs)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue