Skip to content

Issue when pattern matching on tuples using guards #14913

Closed
@aochagavia

Description

@aochagavia
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.

Activity

alexcrichton

alexcrichton commented on Jun 16, 2014

@alexcrichton
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.

added a commit that references this issue on Jun 5, 2023

Auto merge of rust-lang#14913 - HKalbasi:fix14844, r=HKalbasi

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @alexcrichton@aochagavia

        Issue actions

          Issue when pattern matching on tuples using guards · Issue #14913 · rust-lang/rust