-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Futureproof box
and &
patterns
#462
Conversation
box
and &
patternsbox
and &
patterns
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 |
@P1start The main point this RFC is making is that types that will in the future support the |
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 |
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 |
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. |
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? |
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 |
Perhaps some change is necessary but I'm not convinced this would be a significant improvement. I like |
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 |
|
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. |
@nikomatsakis What about renaming the destructuring Agree with everything else there. |
cc me |
@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 |
I'm not sure this is the best solution, but I definitely like it better than the status quo. |
Cross-linking: there's also some discussion going on on discourse here. |
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 |
Futureproof
box
patterns by renaming them toderef
.In an effort to consolidate
box
and&
patterns, change the latter to use thederef
syntax as well, in recognition of them being semantically equivalent tobox
patterns.Make the newly introduced
deref
keyword a non-strict keyword.Rendered view