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

Variable labeling of complex match arms should be able to label the whole arm #15219

Closed
Manishearth opened this Issue Jun 27, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@Manishearth
Copy link
Member

Manishearth commented Jun 27, 2014

If I have a match arm like this:

0x2A | 0x2D | 0x2E | 0x30 .. 0x39 | 0x41 .. 0x5A | 0x5F | 0x61..0x7A => {}

the following does not work:

a @ 0x2A | 0x2D | 0x2E | 0x30 .. 0x39 | 0x41 .. 0x5A | 0x5F | 0x61..0x7A => {println("{}",a)}
a @ (0x2A | 0x2D | 0x2E | 0x30 .. 0x39 | 0x41 .. 0x5A | 0x5F | 0x61..0x7A) => {println("{}",a)}

In the former example, the a is bound to the first literal only, and in the latter the compiler thinks that it is a tuple (and complains about the lack of commas).

Of course, one can do

a @ 0x2A | a @ 0x2D | a@ 0x2E | a@ 0x30 .. 0x39 /* etc */=> {println("{}",a)}

but that is cumbersome.

Could we get a way to easily bind a variable to the entire match arm?

@jdm jdm added the I-papercut label Jun 27, 2014

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Jun 28, 2014

As work-around for types like primitives, you can write match ... { a @ ( 0x2A | ... ) => println!("{}", a), ... } as

let x = ...;
match x {
    0x2A | 0x2D | ... => println!("{}", x),
}

i.e. doing the binding outside the match.

@Manishearth

This comment has been minimized.

Copy link
Member Author

Manishearth commented Jun 28, 2014

Yeah, that's close to what I ended up doing.

@ghost ghost added the B-RFC label Oct 28, 2014

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 21, 2015

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#673

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