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

Documenting binding syntax for pattern matching #10917

Closed
wants to merge 2 commits into from
Closed

Documenting binding syntax for pattern matching #10917

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 11, 2013

Ref #7173.

@ghost
Copy link
Author

ghost commented Dec 11, 2013

A couple of things:

  • I'm not a fan of the description I've given of this syntax, it doesn't flow very well. Improvements are much desired.
  • Should something be written for the manual as well?
  • Are there instructions around for updating doc/po/tutorial.md.pot?


~~~~
match (1, 2) {
c@(a, b) => println!("{:?} {:?} {:?}", a, b, c)
Copy link
Member

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.

@huonw
Copy link
Member

huonw commented Dec 11, 2013

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),
Copy link
Member

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?

@emberian
Copy link
Member

Closing due to inactivity; feel free to reopen!

@emberian emberian closed this Jan 11, 2014
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2023
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants