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

Match and binary operators in block body #43338

Closed
milibopp opened this issue Jul 19, 2017 · 3 comments
Closed

Match and binary operators in block body #43338

milibopp opened this issue Jul 19, 2017 · 3 comments
Labels
A-parser Area: The parsing of Rust source code to an AST

Comments

@milibopp
Copy link
Contributor

Just ran across this issue and wondered, whether this is some kind of syntax limitation or a parser bug:

The following code does not compile:

let x = { match 2 { _ => 1 } - 2 };

(playground)

The error message is somewhat confusing:

  Compiling playground v0.0.1 (file:///playground)
error[E0308]: mismatched types
 --> src/main.rs:2:15
  |
2 |     let x = { match 2 { _ => 1 } - 2 };
  |               ^^^^^^^^^^^^^^^^^^ expected (), found integral variable
  |
  = note: expected type `()`
             found type `{integer}`

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

I would have expected it to be equivalent to the following code, which does work (evaluating x to -1 as expected):

let x = match 2 { _ => 1 } - 2;
@Mark-Simulacrum Mark-Simulacrum added the A-parser Area: The parsing of Rust source code to an AST label Jul 19, 2017
@durka
Copy link
Contributor

durka commented Jul 19, 2017

I think this is the same as #13012 and #17930?

@milibopp
Copy link
Contributor Author

Ah, I almost thought something like this must be the reason. Still feels a little surprising, but so be it.

So… close as duplicate then?

@Mark-Simulacrum
Copy link
Member

Yeah, this seems to be a duplicate of the latter at least, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

3 participants