]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #53360 - PramodBisht:issue/51602, r=estebank
authorkennytm <kennytm@gmail.com>
Thu, 16 Aug 2018 16:13:21 +0000 (00:13 +0800)
committerGitHub <noreply@github.com>
Thu, 16 Aug 2018 16:13:21 +0000 (00:13 +0800)
Addressed #51602

Fixed #51602
r? @estebank

here I have addressed the case where `in` was not expected right after `if` block. Speaking of `type ascription` I am not sure if this the best approach which I have implemented. Plus I think one more test case can be added to test `type-ascription` case, though I don't have any at this point of time. I will ping you again if all existing testcases pass.

1  2 
src/libsyntax/parse/parser.rs

index b1e1cdee2ee8e5c66ee292e829c2a46697788349,8e11104b3f68ebe39fefe2018ff2f484c3f94e58..345464c66642570e2e39a6d22358f54192c5b5f8
@@@ -825,7 -825,7 +825,7 @@@ impl<'a> Parser<'a> 
      ///
      /// 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);