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: Futureproof `box` and `&` patterns #462
Conversation
ghost
changed the title
Futureproof `box` and `&` patterns
RFC: Futureproof `box` and `&` patterns
Nov 11, 2014
This comment has been minimized.
This comment has been minimized.
|
I’m not so sure that this is a good idea. Patterns intentionally look very similar to their expression counterparts; e.g., the expression I think the best way of avoiding the problem with |
This comment has been minimized.
This comment has been minimized.
|
@P1start The main point this RFC is making is that types that will in the future support the |
This comment has been minimized.
This comment has been minimized.
|
I'm not sure if this is the exact right solution, but I would like to see
spits out
The correct way is:
Which is different than construction. Having Just some notes of things that were discussed on IRC:
Using |
This comment has been minimized.
This comment has been minimized.
reem
commented
Nov 11, 2014
|
I'm a fan of some version of this proposal because of the possible integration with smart pointers - matching against stuff contained inside of Also, I agree with @Gankro that in a perfect world |
This comment has been minimized.
This comment has been minimized.
|
I agree with some form of this, but I don't really like
I strongly, completely agree with @Gankro
That is a great idea. I for one would love to have true symmetry. It has always seemed like a wart to me how confusing matches could be due to not being truly symmetrical. |
This comment has been minimized.
This comment has been minimized.
Just to give everyone an idea, the following: match ty::get(function_type).sty {
ty::ty_closure(box ty::ClosureTy {
store: ref store,
..
}) => {}
_ => {}
}would, with & *, read: match ty::get(function_type).sty {
ty::ty_closure(&ty::ClosureTy {
store: *store,
..
}) => {}
_ => {}
}In general, I really appreciate this reusing existing sigils and not introducing new keywords, as well as the symmetry with expressions. I am, however, dubious about it being easy to grok. As you've mentioned, @Gankro, cc @steveklabnik Any thoughts? |
This comment has been minimized.
This comment has been minimized.
|
I agree that patterns are initially confusing, because everything is backwards, but it gets much easier once you realize that "oh, everything is backwards". I suspect that having some parts be backwards and others "forwards" would just end up making things more confusing in the long run. The bigger problem with using
(Or how else?) This is made even more confusing by the fact that we also have an unrelated type called That said, the fact that in expressions you would specify mutability for |
This comment has been minimized.
This comment has been minimized.
|
Perhaps some change is necessary but I'm not convinced this would be a significant improvement. I like |
This comment has been minimized.
This comment has been minimized.
Actually this seems to make sense to me. The fact that they have some overlap isn't really a bad thing. There should be more than one way of doing something. I'm no so fond of removing the I'm also a bit wary about I'm also okayish with |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
I was just discussing this with @jakub- on IRC. TL;DR is:
More details:
UPDATE: Tweaked order of text very slightly, putting TL;DR on the top where it belongs. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis What about renaming the destructuring Agree with everything else there. |
pnkfelix
assigned
zwarich
Nov 13, 2014
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis A note on your 4th point: it is actually Also, as I think emerged from some of the discussion on IRC, I am certainly in favour of feature-gating
I am rather skeptical about this when picturing real code that'd use the generalised box patterns in the future: Exampleuse std::cell::RefCell;
fn main() {
let cell = RefCell::new(42u);
if let box 42u = cell.borrow() {
}
}In this particular case, I think feature-gating |
This comment has been minimized.
This comment has been minimized.
I'm not sure this is the best solution, but I definitely like it better than the status quo. |
This comment has been minimized.
This comment has been minimized.
|
Cross-linking: there's also some discussion going on on discourse here. |
ghost
unassigned
zwarich
Jan 31, 2015
pnkfelix
assigned
nikomatsakis
Feb 5, 2015
This comment has been minimized.
This comment has been minimized.
|
We discussed this RFC at the triage meeting today and decided to close it. We do not plan major breaking changes to the syntax of |
ghost commentedNov 11, 2014
Futureproof
boxpatterns by renaming them toderef.In an effort to consolidate
boxand&patterns, change the latter to use thederefsyntax as well, in recognition of them being semantically equivalent toboxpatterns.Make the newly introduced
derefkeyword a non-strict keyword.Rendered view