Skip to content

Documentation: How does match decide which identifiers bind and which match  #3851

Closed
@dobesv

Description

@dobesv

In the example match expression from the manual:

enum List<X> { Nil, Cons(X, @List<X>) }

let x: List<int> = Cons(10, @Cons(11, @Nil));

match x {
    Cons(a, @Cons(b, _)) => {
        process_pair(a,b);
    }
    Cons(10, _) => {
        process_ten();
    }
    Nil => {
        return;
    }
    _ => {
        fail;
    }
}

How is rust deciding that "Nil" here would be "matched" rather than "bound" in the third case?

The documentation could probably use a little clarification on this matter, as there could be a number of possible schemes being used. Some of these schemes are discussed in the "bike shed" but none of the proposals there match the syntax in the manual.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions