Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler suggests using the removed placement syntax #51602

Closed
mickethespike opened this issue Jun 16, 2018 · 7 comments
Closed

Compiler suggests using the removed placement syntax #51602

mickethespike opened this issue Jun 16, 2018 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@mickethespike
Copy link

mickethespike commented Jun 16, 2018

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`.
@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. labels Jun 16, 2018
@kennytm
Copy link
Member

kennytm commented Jun 18, 2018

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

@pietroalbini
Copy link
Member

Yeah #50832.

@kennytm
Copy link
Member

kennytm commented Jun 18, 2018

#50832 was about x <- y though

@aidanhs
Copy link
Member

aidanhs commented Jun 22, 2018

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.

@estebank
Copy link
Contributor

estebank commented Aug 8, 2018

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

@estebank estebank added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Aug 8, 2018
@PramodBisht
Copy link
Contributor

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

@estebank
Copy link
Contributor

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

PramodBisht added a commit to PramodBisht/rust that referenced this issue Aug 14, 2018
kennytm added a commit to kennytm/rust that referenced this issue Aug 16, 2018
Addressed rust-lang#51602

Fixed rust-lang#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.
bors added a commit that referenced this issue Aug 16, 2018
Rollup of 10 pull requests

Successful merges:

 - #52946 (Documented impl From on line 367 of libserialize/json.rs)
 - #53234 (Remove Travis shutdown debug scripts, and remove CI-specific DNS settings)
 - #53313 (Two small improvements)
 - #53360 (Addressed #51602)
 - #53364 (Warn if the user tries to use GATs)
 - #53373 (Tweak unclosed delimiter parser error)
 - #53377 (std: Use target_pointer_width for BACKTRACE_ELF_SIZE)
 - #53395 (Use #[non_exhaustive] on internal enums)
 - #53399 (Tidy: ignore non-Markdown files when linting for the Unstable Book)
 - #53412 (syntax_ext: remove leftover span_err_if_not_stage0 macro.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

7 participants