-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Documenting binding syntax for pattern matching #10917
Conversation
A couple of things:
|
|
||
~~~~ | ||
match (1, 2) { | ||
c@(a, b) => println!("{:?} {:?} {:?}", a, b, c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write this as c @ (a, b)
(just stylistic; and do it below too). Also, writing the a
and b
prints as {}
rather than {:?}
would be nicer.
I think this might be clearer (or would at least benefit from) having a subpattern as-pattern. i.e. let x: Option<(u8, i16)> = foo();
match x {
Some(tuple @ (a, b)) => { ... }
None => { ... }
} (Also, note that Haskell calls these "as patterns", and I personally don't see a reason to depart from this nomenclature; others might have a better name though.) |
|
||
~~~~ | ||
match (1, 2) { | ||
c @ (a, b) if a > 0 => println!("First arm {:?}", c), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to not have unused variables like b
here, and a, b
in the example below. For this one, replacing it with _
would be ok, for the one below, maybe print them as well as the entire tuple?
Closing due to inactivity; feel free to reopen! |
allow disabling module inception on private modules Fixes rust-lang#10842 changelog: Enhancement [`module_inception`]: Added `allow-private-module-inception` configuration. [rust-lang#10917](rust-lang/rust-clippy#10917) <!-- changelog_checked -->
Ref #7173.