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

Allow mut qualification on idents in patterns #9792

Closed
huonw opened this issue Oct 10, 2013 · 4 comments · Fixed by #10026
Closed

Allow mut qualification on idents in patterns #9792

huonw opened this issue Oct 10, 2013 · 4 comments · Fixed by #10026
Labels
A-grammar Area: The grammar of Rust

Comments

@huonw
Copy link
Member

huonw commented Oct 10, 2013

e.g.

let (mut x, mut y) = ...;

match p {
    Foo(mut q) => { ... }
    mut s @ Baz(*) => { ... }
}

fn foo((mut a, mut b): (~str, ~[float])) { ... }

let f = |mut x| { ... };

The grammar would become approximately

ident_pat = "ref"? "mut"? ident
pat = "_" 
     | ident_pat
     | path "(" "*" ")"
     | path "(" pat* ")"
     | path "{" [ident ":" pat | ident^]* "}"
     | ident_pat "@" pat

(The ident marked ^ would become a ident_pat to solve #6137.)

This would also mean that the grammar for let could be simplified to just "let" pat "=" expr ";" (rather than "let" "mut"? pat "=" expr ";" as it currently is), and similarly for function arguments.

(I think this has been thrown about for a while, but I can't find an issue; and I very briefly experimented with this, but quite a few places seem to assume that only let and function args allow mut.)

@chris-morgan
Copy link
Member

Would this fix mut self and mut ~self?

@huonw
Copy link
Member Author

huonw commented Oct 12, 2013

They're not pattern contexts (yet?), so no.

@brson
Copy link
Contributor

brson commented Oct 22, 2013

Nominating.

@luqmana
Copy link
Member

luqmana commented Oct 23, 2013

From #rust-internals:

[08:28:31 pm] <Luqman> brson: was there any talk of mut on ident patterns in the meeting? ( https://github.com/mozilla/rust/issues/9792 )
[08:30:21 pm] <brson> Luqman: yes, I believe we want it
[08:30:26 pm] <brson> pcwalton: can you confirm?
[08:31:04 pm] <Luqman> sweet, once i clean up my branch later i'll send a pull
[08:39:29 pm] <pcwalton> brson: we didn't really talk about it at the meeting but I'm totally in favor and I think everyone is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants