Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Replace `ref` by `*` in patterns #742
Conversation
This comment has been minimized.
This comment has been minimized.
|
+1 from my part, though it doesn't seem like people are very receptive towards syntax changes post-alpha. |
This comment has been minimized.
This comment has been minimized.
rpjohnst
commented
Jan 27, 2015
|
I like this because it makes more patterns work by destructuring, although that can't be done with |
This comment has been minimized.
This comment has been minimized.
gsingh93
commented
Jan 27, 2015
|
When I was first learning Rust, this is what I tried to do instead of using On Tue Jan 27 2015 at 10:13:30 AM Russell Johnston notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
nstoddard
commented
Jan 27, 2015
|
When I was learning Rust, I thought |
This comment has been minimized.
This comment has been minimized.
bfops
commented
Jan 28, 2015
|
I wouldn't mind replacing |
P1start
reviewed
Jan 28, 2015
|
|
||
| Note that most common usage of `mut` would be `mut *x` (corresponding to current `ref mut x`), | ||
| so the raw-pointer-resembling `* mut` wouldn't appear very often | ||
| (in rust source `ref mut` appears 139 times, compared to only 9 usages of `mut ref`). |
This comment has been minimized.
This comment has been minimized.
P1start
Jan 28, 2015
Contributor
git grep 'mut ref' actually shows that although there are nine occurrences of the phrase mut ref in the Rust codebase, the first is just part of a list of keywords, the next four are examples in documentation (using &mut ref mut, which seems to be redundant), the next is a substring of mut reference in a comment, the next is in legitimate code, the next is a substring of mut ref_kind: in a function declarations’s argument list, and the final one is in a test. Of all of those, I think only one really counts, and only six are actual uses of mut ref at all.
This comment has been minimized.
This comment has been minimized.
huonw
Jan 28, 2015
Member
Furthermore, none of them are equivalent to let mut x: &T = &val;: mut ref <ident> isn't a valid pattern. (They're all parsed as &mut (ref ...), i.e. pattern matching through a &mut.)
This comment has been minimized.
This comment has been minimized.
P1start
Jan 28, 2015
Contributor
Oh, I didn’t know that mut ref <ident> wasn’t even a valid pattern! The RFC should probably be updated to reflect that, then, given that it suggests *mut as a replacement.
This comment has been minimized.
This comment has been minimized.
krdln
Jan 28, 2015
Author
Contributor
So it wasn't only me who thought that mut ref is a valid pattern! I've updated the RFC.
This comment has been minimized.
This comment has been minimized.
suhr
commented
Jan 28, 2015
|
I think |
This comment has been minimized.
This comment has been minimized.
|
I like the idea, but I’m worried that it will turn out to be confusing. Also, I wonder how this would interact with RFC #495, where subslice patterns require match &mut [1, 2, 3] {
&mut [a, mut *b..] => { ... },
...
}where the |
This comment has been minimized.
This comment has been minimized.
DanielKeep
commented
Jan 28, 2015
|
This change just does my brain in. In pattern-matching, you're supposed to be destructuring things. So when I see Not only does this not have anything to do with unsafe pointers, it's also adding a level of indirection, which is the outright opposite of how all the other type constructors work in a pattern. As Pedro would say: very no! |
This comment has been minimized.
This comment has been minimized.
|
@DanielKeep |
This comment has been minimized.
This comment has been minimized.
suhr
commented
Jan 28, 2015
|
Actually, unsafe pointer types are |
This comment has been minimized.
This comment has been minimized.
|
@bfops Notice that when you write @suhr You could read @P1start And I agree that |
This comment has been minimized.
This comment has been minimized.
suhr
commented
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
nwin
commented
Jan 28, 2015
|
-1 They way that Coincidentally it works the same way as If I'm wrong with this I would at least only rename |
This comment has been minimized.
This comment has been minimized.
|
@nwin I tried to explain to myself that both One other possibility that in my opinion would make |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
whatisaphone
commented
Jan 28, 2015
|
I'm for it. We're still alpha. Consider the symmetry between the pattern and the assert in these matches:
The current syntax does not maintain the symmetry, and has a syntax error in the assert:
The proposed syntax would maintain the pattern nicely:
|
This comment has been minimized.
This comment has been minimized.
taralx
commented
Jan 28, 2015
|
|
This comment has been minimized.
This comment has been minimized.
|
As @krdln says, this is not a new proposal. Overall, though, I feel like this debate was settled long ago and I don't see any pressing reason to revisit it. Update: Corrected name of RFC author. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I have quite opposite feeling – from what I've read in this discussion, I can't see an actual decision. Maybe I've missed something? Also, this RFC additionally addresses the |
This comment has been minimized.
This comment has been minimized.
|
@krdln this decision far predates the RFC tracker or other discussion. Here is the thread where discussion began. As you can see, it began with a proposal (by me, in fact) to use |
This comment has been minimized.
This comment has been minimized.
|
In the triage meeting today we decided to close this RFC. A syntactic change of this magnitude seems out of scope at this time, and the current syntax was agreed upon long ago. |
krdln commentedJan 27, 2015
Change
refin patterns to*, to make pattern syntax better match expression syntax. Example:Some(ref x)becomesSome(*x). This change removes all the usage ofrefkeyword, so the RFC also discusses the fate of it.Rendered
This is not a new proposal, because discussions (eg. here, here and there) about this change happen from time to time, but I think it deserves an RFC.