Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Match ergonomics means bindings have different types in patterns and match arm; cannot deref references in pattern #64586

Copy link
Copy link
@varkor

Description

@varkor
Issue body actions

Consider the following:

struct S(u32);

fn foo(x: &S) {
    let _: &u32 = match x {
        S(y) => y,
        _ => &0,
    };
}

Here, the variable binding y has type &u32 outside the pattern. However, inside the pattern it has type u32. The fact that these types do not align is confusing, as it means you can't dereference y inside the pattern like this:

fn foo(x: &S) {
    let _: u32 = match x {
        S(&y) => y,
        _ => 0,
    };
}

and instead have to dereference it outside the pattern:

fn foo(x: &S) {
    let _: u32 = match x {
        S(y) => *y,
        _ => 0,
    };
}

Is there any reason this was chosen to be the case, or is required to be the case? As it stands, this behaviour is very counter-intuitive.

mark-i-m, CryZe, bluss, Boscop, sollyucko and 7 moremark-i-m, CryZe, RalfJung, Boscop, jplatte and 2 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team

    Type

    No type

    Projects

    Status

    Idea
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.