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

Issue when pattern matching on tuples using guards #14913

Closed
aochagavia opened this issue Jun 15, 2014 · 1 comment
Closed

Issue when pattern matching on tuples using guards #14913

aochagavia opened this issue Jun 15, 2014 · 1 comment

Comments

@aochagavia
Copy link
Contributor

The code:

fn main() {
    let (name, street) = ("John".to_str(), "Something".to_str());
    match (name, street) {
        (ref n, s) if *n == "...".to_str() => (),
        _ => ()
    }
}

The error message:

test.rs:4:17: 4:18 error: cannot bind by-move into a pattern guard
test.rs:4         (ref n, s) if *n == "...".to_str() => (),
                          ^
error: aborting due to previous error

This forces you to use ref s to satisfy the compiler, but s is not used at all in the pattern guard! I think it this code should compile without ref s.

@alexcrichton
Copy link
Member

Closing, this is just a fact of rustc right now. You're not allowed to move in a pattern with a guard. For relaxing these restrictions, rust-lang/rfcs#107 seems to do the trick.

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Evaluate `UnevalutedConst` before trait solving

cc rust-lang#14844
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants