review comments
This commit is contained in:
parent
ac037c1359
commit
9b6b3d618c
@ -796,10 +796,6 @@ impl<'a> Parser<'a> {
|
||||
.chain(inedible.iter().map(|x| TokenType::Token(x.clone())))
|
||||
.chain(self.expected_tokens.iter().cloned())
|
||||
.collect::<Vec<_>>();
|
||||
let expects_semi = expected.iter().any(|t| match t {
|
||||
TokenType::Token(token::Semi) => true,
|
||||
_ => false,
|
||||
});
|
||||
expected.sort_by_cached_key(|x| x.to_string());
|
||||
expected.dedup();
|
||||
let expect = tokens_to_string(&expected[..]);
|
||||
@ -839,17 +835,6 @@ impl<'a> Parser<'a> {
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
let is_semi_suggestable = expects_semi && (
|
||||
self.token.is_keyword(keywords::Break) ||
|
||||
self.token.is_keyword(keywords::Continue) ||
|
||||
self.token.is_keyword(keywords::For) ||
|
||||
self.token.is_keyword(keywords::If) ||
|
||||
self.token.is_keyword(keywords::Let) ||
|
||||
self.token.is_keyword(keywords::Loop) ||
|
||||
self.token.is_keyword(keywords::Match) ||
|
||||
self.token.is_keyword(keywords::Return) ||
|
||||
self.token.is_keyword(keywords::While)
|
||||
);
|
||||
let sp = if self.token == token::Token::Eof {
|
||||
// This is EOF, don't want to point at the following char, but rather the last token
|
||||
self.prev_span
|
||||
@ -866,6 +851,20 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let is_semi_suggestable = expected.iter().any(|t| match t {
|
||||
TokenType::Token(token::Semi) => true, // we expect a `;` here
|
||||
_ => false,
|
||||
}) && ( // a `;` would be expected before the current keyword
|
||||
self.token.is_keyword(keywords::Break) ||
|
||||
self.token.is_keyword(keywords::Continue) ||
|
||||
self.token.is_keyword(keywords::For) ||
|
||||
self.token.is_keyword(keywords::If) ||
|
||||
self.token.is_keyword(keywords::Let) ||
|
||||
self.token.is_keyword(keywords::Loop) ||
|
||||
self.token.is_keyword(keywords::Match) ||
|
||||
self.token.is_keyword(keywords::Return) ||
|
||||
self.token.is_keyword(keywords::While)
|
||||
);
|
||||
let cm = self.sess.source_map();
|
||||
match (cm.lookup_line(self.span.lo()), cm.lookup_line(sp.lo())) {
|
||||
(Ok(ref a), Ok(ref b)) if a.line != b.line && is_semi_suggestable => {
|
||||
@ -873,7 +872,7 @@ impl<'a> Parser<'a> {
|
||||
// High likelihood that it is only a missing `;`.
|
||||
err.span_suggestion_short(
|
||||
label_sp,
|
||||
"missing semicolon here",
|
||||
"a semicolon may be missing here",
|
||||
";".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -2,7 +2,7 @@ error: expected one of `.`, `;`, `?`, or an operator, found `let`
|
||||
--> $DIR/recover-missing-semi.rs:4:5
|
||||
|
|
||||
LL | let _: usize = ()
|
||||
| - help: missing semicolon here
|
||||
| - help: a semicolon may be missing here
|
||||
LL |
|
||||
LL | let _ = 3;
|
||||
| ^^^
|
||||
@ -11,7 +11,7 @@ error: expected one of `.`, `;`, `?`, or an operator, found `return`
|
||||
--> $DIR/recover-missing-semi.rs:11:5
|
||||
|
|
||||
LL | let _: usize = ()
|
||||
| - help: missing semicolon here
|
||||
| - help: a semicolon may be missing here
|
||||
LL |
|
||||
LL | return 3;
|
||||
| ^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user