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 uptracking issue for default binding modes in match (RFC 2005, match_default_bindings) #42640
Comments
nikomatsakis
added
B-RFC-approved
T-lang
labels
Jun 13, 2017
nikomatsakis
referenced this issue
Jun 13, 2017
Merged
Match Ergonomics Using Default Binding Modes #2005
This comment has been minimized.
This comment has been minimized.
|
I'm actually not 100% sure the best way to implement this. It seems like we will need to add adjustments to patterns, and then integrate those into the various bits of the compiler. @eddyb, have any thoughts on that? You usually have some clever ideas when it comes to this sort of thing. =) |
This comment has been minimized.
This comment has been minimized.
|
We should be able to treat adjustments more uniformly now, although it'd still be a lot of plumbing. |
This comment has been minimized.
This comment has been minimized.
crazymykl
commented
Jun 15, 2017
|
How does this interact with slice patterns (#23121)? |
This comment has been minimized.
This comment has been minimized.
|
My expectation would be that, when we encounter a pattern like |
This comment has been minimized.
This comment has been minimized.
|
@eddyb do we want to use general purpose adjustments here, or something more limited (the current RFC, after all, only requires autoderef of |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Autoderef or autoref? If it's one bit per pattern making it separate for now is fine. |
This comment has been minimized.
This comment has been minimized.
autoderef -- that is, where you have a pattern like |
This comment has been minimized.
This comment has been minimized.
|
Here is a rough and incomplete implementation plan for the match ergonomics RFC. There are a few high-level things we have to do:
Right now, the code is setup to scrape this information directly from the "HIR" (the compiler's AST). The HIR node for a pattern is
We want to make this equivalent to
We don't however have enough information to do this when we construct the HIR, since we need type checking results to do it, so we can't change the HIR itself. The way we typically handle this sort of thing then is to have the typeck encode "side tables" with auxiliary information. These tables are stored in In this case, I think we want two tables:
Probably a decent first PR is just to introduce the second table (
This is not a comprehensive list, but it does have the major use-sites. You can get a more comprehensive list by doing OK, no time for more, but hopefully this helps somebody get started! Please leave a note if you are interested in taking this on, and feel free to ping me on IRC ( |
nikomatsakis
added
the
E-mentor
label
Jul 6, 2017
This comment has been minimized.
This comment has been minimized.
|
I'll look into the first step:
|
This comment has been minimized.
This comment has been minimized.
|
@tschottdorf woohoo! |
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 21, 2017
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 27, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 28, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 28, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 28, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 28, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 28, 2017
nikomatsakis
added a commit
to tbg/rust
that referenced
this issue
Jul 29, 2017
bors
added a commit
that referenced
this issue
Jul 30, 2017
bors
added a commit
that referenced
this issue
Jul 30, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 30, 2017
tbg
added a commit
to tbg/rust
that referenced
this issue
Jul 30, 2017
bors
added a commit
that referenced
this issue
Jul 31, 2017
bors
added a commit
that referenced
this issue
Jul 31, 2017
matthewhammer
pushed a commit
to matthewhammer/rust
that referenced
this issue
Aug 3, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm a bit torn on all this. On the one hand, I find @eddyb's idea interesting — though I think there are many variants and I'm not 100% sure what is being proposed. My understanding was roughly "if you have a value of type For example, if I am matching a value of type So basically it seems to me that we are really talking about rolling back the whole match default bindings change. This is a much bigger thing than #46688. (When I thought it was just #46688 that was under discussion, I was considering this to be rather similar to the "course correction" that we took for Object Lifetime Default rules. The reasoning here is slightly difference, but ultimately I think that was the right call. But this seems to be a much larger proposal.) Now, maybe there are other proposals where reverting |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I would expect an error and require |
This comment has been minimized.
This comment has been minimized.
|
@eddyb the need to sometimes introduce dummy temps just to make "doubly indirect" references feels bad to me, if that's what you mean (i.e., if we were going to produce a |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis No, in my view, you would never add more than one reference to bindings, because you wouldn't add more than one reference to sub-patterns on a constructor matching a single level of reference to the type of the constructor. |
This comment has been minimized.
This comment has been minimized.
|
I see nothing wrong with the current rules, and certainly see no motive to rollback stabilized functionality. In fact I like the extension that makes strictly more things compile, it's a DWIM approach. The interpretation is that a |
This comment has been minimized.
This comment has been minimized.
|
@leodasvacas I agree with that sentiment, now that I've seen examples with nested references. |
This comment has been minimized.
This comment has been minimized.
|
Ah, I hadn't quite realized the difference between @Boscop's and @eddyb's proposals. I agree we probably want to keep the ability to match multiple non-reference patterns without "accumulating" references. (Those extra "layers" of pointers do exist in the match-ee, but they can't be reused in the I do still think that a) we definitely want something like @Boscop's extension (which should be backwards-compatible) and that b) it interacts weirdly with the change from #46688. That is, I would like a single way to reset the binding mode that applies anywhere; not just at pre-existing references. The confusion in #46688 comes from the fact that the RFC "hasn't quite made up its mind" on whether So here's an idea to solve both of these problems: once we're in a This gives the same result as the current implementation for #46688- matching Or in other words, you can no longer match against actual Edit: Actually the more I think about this version, the more it feels like 50% pedagogical change and 50% just adding @Boscop's extension. Which is great, because that means it's more likely to be compatible and also more likely to offer better error messages! |
This comment has been minimized.
This comment has been minimized.
Boscop
commented
May 17, 2018
|
@rpjohnst Just to clarify: You propose that all It works well for read-only ( So, if we want to preserve the ability to keep all the So then we can't auto-remove all the (But I think it makes sense to allow undoing a |
This comment has been minimized.
This comment has been minimized.
Yes, exactly. Kind of doubling down on the idea that
IMO we shouldn't do this at all- the move binding mode is sufficient to control the levels of references. If you need that control, just switch back to that mode with a The idea of accumulating extra reference levels, as you propose, is basically the thing that we (mis)interpreted @eddyb's version as, and which has the problem of introducing dummy temporaries, and which is backwards-incompatible with the #46688 fix. |
This comment has been minimized.
This comment has been minimized.
Boscop
commented
May 17, 2018
Hm, which dummy temporaries would it introduce? Wouldn't your proposal also be backwards incompatible (because currently, matching |
This comment has been minimized.
This comment has been minimized.
|
It introduces dummy temporaries when you have some structure in between the layers of references. If you're just matching against an And yes, my proposal is backwards-incompatible in cases like matching |
Centril
added
disposition-merge
finished-final-comment-period
and removed
final-comment-period
labels
May 24, 2018
kennytm
referenced this issue
May 26, 2018
Closed
rewrite `...` to `..=` as an idiom lint for Rust 2018 edition #51043
fabianfreyer
added a commit
to fabianfreyer/sysctl-rs
that referenced
this issue
May 28, 2018
tmatth
referenced this issue
Jun 12, 2018
Closed
context: fix non-reference pattern used to match a reference #236
This comment has been minimized.
This comment has been minimized.
Boscop
commented
Jul 19, 2018
|
Any update on this issue? :) |
This comment has been minimized.
This comment has been minimized.
|
So I think the place we're at now is @Boscop's original proposal, summarized by @nikomatsakis in #42640 (comment) as "make While in a sense this gives I'd like to solve this---it came up again on Reddit and it's kind of a pain. Is the next step just to write an RFC for it? |
This comment has been minimized.
This comment has been minimized.
|
@rpjohnst The blocker I think is that there are several possible solutions to this problem and considerable dissensus among the lang team (and certainly the community also) about what would be best:
Personally, I lean toward one of the latter two options because I think the use of |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats Ah, I didn't realize this would be in conflict with the second two options, especially in light of #48448. So would the next step be to get consensus on which approach to take? Do we need to stick with just one, or could we have both to round out the existing behavior? |
This comment has been minimized.
This comment has been minimized.
|
@rpjohnst yea, we need consensus building to move forward here. as far as i know, we don't even have consensus that we shouldn't do more than one of them. |
This comment has been minimized.
This comment has been minimized.
Boscop
commented
Jul 27, 2018
•
Always, unconditionally? But (Also, wouldn't this solution break existing code (on stable) that uses
Please don't forget, it should be possible to mark the moved-out copy as
I really think the best option is to use the Btw, what I would like (in addition to going with the
I've talked to several people who expected it to already work like this because it also works like this when the reference wasn't created implicitly by |
This comment has been minimized.
This comment has been minimized.
|
Having thought through this some more, this is one place in the language where I can easily see supporting both So people (and, more importantly IMO, particular pieces of programs given their context) can use the one that expresses their intent more clearly. When Does this make sense to anyone else? Or would people rather stick to just one solution? Or do people like the "coerce |
Centril
added
I-nominated
and removed
I-nominated
labels
Jan 13, 2019
This comment has been minimized.
This comment has been minimized.
|
This is implemented and stabilizing, but we never closed it! The only real remaining question is #44849 and we have a separate issue for that. |
nikomatsakis commentedJun 13, 2017
•
edited by Centril
This is a tracking issue for the "match ergonomics using default bindings mode" RFC (rust-lang/rfcs#2005).
Status: Awaiting stabilization PR and docs PR! Mentoring instructions here.
Steps:
Unresolved questions: