[NLL] make temp for each candidate in match arm#52733
Conversation
… *for each* candidate pat. This required a bit of plumbing to keep track of candidates. But I took advantage of the hack session to try to improve the docs for the relevant structs here. (I also tried to simplify some of the related code in passing.)
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
@nikomatsakis you may want to skim over this in order to help decide whether we will try to resolve #51348 for EP2. |
nikomatsakis
left a comment
There was a problem hiding this comment.
just a few nits but looks good to me
| { | ||
| let borrow_data = &mut self.idx_vec[borrow_index]; | ||
| borrow_data.activation_location = TwoPhaseActivation::NotActivated; | ||
| } |
There was a problem hiding this comment.
too bad we don't have NLL already! =)
src/librustc_mir/build/block.rs
Outdated
| remainder_span, | ||
| lint_level, | ||
| &pattern, | ||
| &[pattern.clone()], |
There was a problem hiding this comment.
is this just to convert from &T to &[T]? I know there was some helper for doing this somewhere...
There was a problem hiding this comment.
Oh, hey, the libs team finally gave in:
https://doc.rust-lang.org/std/slice/fn.from_ref.html
well, I guess it's still unstable.
There was a problem hiding this comment.
i was lazy. will fix.
src/librustc_mir/build/block.rs
Outdated
| scope = this.declare_bindings(None, remainder_span, lint_level, &pattern, | ||
| ArmHasGuard(false), None); | ||
| scope = this.declare_bindings( | ||
| None, remainder_span, lint_level, &[pattern.clone()], |
There was a problem hiding this comment.
same here, slice::from_ref?
|
r? @nikomatsakis -- @michaelwoerister feel free to take review back if you want to =) |
|
I'm going to interpret niko's "looks good to me" as an r+. |
|
@bors r=nikomatsakis |
|
📌 Commit 9462645 has been approved by |
…ate-in-arm, r=nikomatsakis [NLL] make temp for each candidate in `match` arm In NLL, `ref mut` patterns leverage the two-phase borrow infrastructure to allow the shared borrows within a guard before the "activation" of the mutable borrow when we begin execution of the match arm's body. (There is further discussion of this on PR #50783.) To accommodate the restrictions we impose on two-phase borrows (namely that there is a one-to-one mapping between each activation and the original initialization), this PR is making separate temps for each candidate pattern. So in an arm like this: ```rust PatA(_, ref mut ident) | PatB(ref mut ident) | PatC(_, _, ref mut ident) | PatD(ref mut ident) if guard_stuff(ident) => ... ``` instead of 3 temps (two for the guard and one for the arm body), we now have 4 + 2 temps associated with `ident`: one for each candidate plus the actual temp that the guard uses directly, and then the sixth is the temp used in the arm body. Fix #51348
|
☀️ Test successful - status-appveyor, status-travis |
In NLL,
ref mutpatterns leverage the two-phase borrow infrastructure to allow the shared borrows within a guard before the "activation" of the mutable borrow when we begin execution of the match arm's body. (There is further discussion of this on PR #50783.)To accommodate the restrictions we impose on two-phase borrows (namely that there is a one-to-one mapping between each activation and the original initialization), this PR is making separate temps for each candidate pattern. So in an arm like this:
instead of 3 temps (two for the guard and one for the arm body), we now have 4 + 2 temps associated with
ident: one for each candidate plus the actual temp that the guard uses directly, and then the sixth is the temp used in the arm body.Fix #51348