Skip to content
This repository has been archived by the owner. It is now read-only.

Improved match ergonomics around references #24

Open
nrc opened this Issue Feb 9, 2017 · 4 comments

Comments

Projects
None yet
5 participants
@nrc
Copy link
Member

nrc commented Feb 9, 2017

Point of contact

@nrc

Overview

Make match easier to use and less boilerplate-y by auto-dereferencing in the condition expression and inferring refs in the patterns.

E.g.,

fn foo(x: &AnEnum) {
    match x {
        AnEnum::VariantA(y) => { ... }
        AnEnum::VariantB(y, z) => { ... }
    }
}

rather than (currently):

fn foo(x: &AnEnum) {
    match *x {
        AnEnum::VariantA(ref y) => { ... }
        AnEnum::VariantB(ref y, ref z) => { ... }
    }
}

Status

Accepted as RFC 2005.

cc #17

@solson

This comment has been minimized.

Copy link
Member

solson commented Feb 9, 2017

If we infer ref in patterns, will we ever need to explicitly tell Rust not to add ref, like we need to use move on closures?

(Let me know if I should wait for the actual RFC to get posted and move this comment there.)

@aturon aturon referenced this issue Feb 10, 2017

Open

Language ergonomic/learnability improvements #17

10 of 31 tasks complete

@nrc nrc added the T-lang label Feb 10, 2017

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Mar 10, 2017

Updated with RFC.

@liigo

This comment has been minimized.

Copy link

liigo commented May 6, 2017

match type &AnEnum against AnEnum? I don't think it's kind of 'pattern matching'.

@cramertj

This comment has been minimized.

Copy link
Member

cramertj commented Jul 25, 2017

Note: this feature was accepted as RFC #2005.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.