///
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
/// encountered.
- fn check(&mut self, tok: &token::Token) -> bool {
+ crate fn check(&mut self, tok: &token::Token) -> bool {
let is_present = self.token == *tok;
if !is_present { self.expected_tokens.push(TokenType::Token(tok.clone())); }
is_present
if !self.eat(&token::OpenDelim(token::Brace)) {
let sp = self.span;
let tok = self.this_token_to_string();
+ let mut do_not_suggest_help = false;
let mut e = self.span_fatal(sp, &format!("expected `{{`, found `{}`", tok));
+ if self.token.is_keyword(keywords::In) || self.token == token::Colon {
+ do_not_suggest_help = true;
+ e.span_label(sp, "expected `{`");
+ }
// Check to see if the user has written something like
//
// Which is valid in other languages, but not Rust.
match self.parse_stmt_without_recovery(false) {
Ok(Some(stmt)) => {
- if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) {
+ if self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
+ || do_not_suggest_help {
// if the next token is an open brace (e.g., `if a b {`), the place-
// inside-a-block suggestion would be more likely wrong than right
return Err(e);