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 + match compilation error #105179

Closed
stormshield-pj50 opened this issue Dec 2, 2022 · 1 comment · Fixed by #105223
Closed

match + match compilation error #105179

stormshield-pj50 opened this issue Dec 2, 2022 · 1 comment · Fixed by #105223
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@stormshield-pj50
Copy link

I tried this code:

fn foo(a: u64, b: u64) -> u64 {
    match a {
        0 => 1,
        value => value
    } + match b {
        1 => 0,
        value => value
    }
}

fn main() {
    println!("{}", foo(0, 1));
}

I expected to see this happen: the program compiles

Instead, this happened: the program doesn't compile. Note that if you use a return the program compiles and in that case clippy suggests to remove the return.

error: expected expression, found `+`
 --> src/main.rs:5:7
  |
5 |     } + match b {
  |       ^ expected expression

error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
 --> src/main.rs:2:5
  |
2 | /     match a {
3 | |         0 => 1,
4 | |         value => value
5 | |     } + match b {
  | |     ^- help: consider using a semicolon here
  | |_____|
  |       expected `()`, found `u64`

Meta

rustc --version --verbose:

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0
@stormshield-pj50 stormshield-pj50 added the C-bug Category: This is a bug. label Dec 2, 2022
@estebank
Copy link
Contributor

estebank commented Dec 3, 2022

At the very least the suggestion should be telling you to surround the first match with parentheses.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed C-bug Category: This is a bug. labels Dec 3, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 5, 2022
…ochenkov

suggest parenthesis around ExprWithBlock BinOp ExprWithBlock

fix rust-lang#105179
fix rust-lang#102171
@bors bors closed this as completed in 66a4cb5 Dec 6, 2022
RalfJung pushed a commit to RalfJung/miri that referenced this issue Dec 9, 2022
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants