Skip to content

Compiler suggests using the removed placement syntax #51602

Description

@mickethespike

So I'm writing a hangman app in Rust and I get this weird error message. It doesn't make sense since <- isn't even in Rust anymore.

error: expected `{`, found `in`
  --> src/main.rs:8:17
   |
8  |           if line in words {
   |  _________________-^
9  | |             println!("Success");
10 | |         } else {
   | |_________- help: try placing this code inside a block: `{ words <- { println!("Success"); }; }`

error: aborting due to previous error

error: Could not compile `hangman`.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-parserArea: The lexing & parsing of Rust source code to an AST
    C-bugCategory: This is a bug.
    on Jun 16, 2018
  2. kennytm commented on Jun 18, 2018

    @kennytm
    Member

    Could we just stop parsing in «expr» «block» as an ObsoleteInPlace expression? Will it break any macros or code behind #[cfg]?

  3. emilyalbini commented on Jun 18, 2018

    @emilyalbini
    Member

    Yeah #50832.

  4. kennytm commented on Jun 18, 2018

    @kennytm
    Member

    #50832 was about x <- y though

  5. aidanhs commented on Jun 22, 2018

    @aidanhs
    Contributor

    I think the same issue applies though - the parser still needs to be able to recognise the code as something. So if there are crates using that syntax, they'll break in the same way.

  6. estebank commented on Aug 8, 2018

    @estebank
    Contributor

    Current output:

    error: expected `{`, found `in`
     --> src/main.rs:2:10
      |
    2 |       if i in 0..10 {
      |       --   -^
      |  _____|____|
      | |     |
      | |     this `if` statement has a condition, but no block
    3 | |         break;
    4 | |     }
      | |_____- help: try placing this code inside a block: `{ (0..10) <- { break ; }; }`
    

    Still need to remove the suggestion, but otherwise the error would seem reasonable:

    error: expected `{`, found `in`
     --> src/main.rs:2:10
      |
    2 |     if i in 0..10 {
      |     --   ^^ expected `{`
      |     |
      |     this `if` statement has a condition, but no block
    
  7. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Aug 8, 2018
  8. PramodBisht commented on Aug 11, 2018

    @PramodBisht
    Contributor

    @estebank should this be done only for in keyword or you also have other statements in mind.

  9. estebank commented on Aug 11, 2018

    @estebank
    Contributor

    @PramodBisht I believe that in and type ascription (:) are the only two that regularly cause problems with this kind of errors.

  10. added a commit that references this issue on Aug 16, 2018
  11. added a commit that references this issue on Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions