You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pattern guard can consume value that is being matched #31287
@alexcrichton unfortunately no. I fixed a very similar issue involving multiple guards, but not this case.
I did try to fix it, but it essentially requires SEME to work. This is because preventing this case introduces edges between successive patterns in the CFG and consequentially causes code like this:
match foo {
(ref a, 0) => (),
(ref a, 1) => ()
_ => ()
}
to be rejected because the borrow in the first pattern overlaps the borrow in the second pattern. The reason why this has to be this way is because both move checking and borrow checking are done using the CFG, right now the CFG for a match "visits" all the arms in parallel, with pattern guards chaining into each other where appropriate. Improving it further requires chaining from the guard to the next pattern instead, but also requires indicating that the borrow in the pattern ends at both the "else" branch of the guard and the end of the block for the arm. In other words, we need regions with multiple exits aka SEME.
Can't we just borrow the discriminant in all guards separately (cc @pnkfelix)? Actually, that might cause conflicts with ref mut borrows, but that conflict can be ignored (actually, we may want to mark patterns as aliasable in guards).
This issue won't be really fixed with MIR if we are talking about bypassing-exhaustiveness rather than
@landaire Yeah but shouldn't Rust 2018 turn on the NLL borrowck in its full mode?
Unless BorrowckMode::Mir was never on stable and the Compare mode was enabled for 2015 recently?
(after having been the mode on the 2018 edition all this time)
@landaire Yeah but shouldn't Rust 2018 turn on the NLL borrowck in its full mode?
Unless BorrowckMode::Mir was never on stable and the Compare mode was enabled for 2015 recently?
(after having been the mode on the 2018 edition all this time)
Activity
apasel422 commentedon Jan 29, 2016
CC rust-lang/rfcs#107 (comment), #27282.
alexcrichton commentedon Jan 29, 2016
triage: T-lang I-nominated
I thought we fixed this :(
Aatch commentedon Jan 30, 2016
@alexcrichton unfortunately no. I fixed a very similar issue involving multiple guards, but not this case.
I did try to fix it, but it essentially requires SEME to work. This is because preventing this case introduces edges between successive patterns in the CFG and consequentially causes code like this:
to be rejected because the borrow in the first pattern overlaps the borrow in the second pattern. The reason why this has to be this way is because both move checking and borrow checking are done using the CFG, right now the CFG for a match "visits" all the arms in parallel, with pattern guards chaining into each other where appropriate. Improving it further requires chaining from the guard to the next pattern instead, but also requires indicating that the borrow in the pattern ends at both the "else" branch of the guard and the end of the block for the arm. In other words, we need regions with multiple exits aka SEME.
arielb1 commentedon Jan 31, 2016
Can't we just borrow the discriminant in all guards separately (cc @pnkfelix)? Actually, that might cause conflicts with
ref mutborrows, but that conflict can be ignored (actually, we may want to mark patterns as aliasable in guards).This issue won't be really fixed with MIR if we are talking about bypassing-exhaustiveness rather than
Aatch commentedon Feb 1, 2016
@arielb1 did you accidentally comment on the wrong issue? I'm not sure how discriminants and exhaustiveness come in here.
nikomatsakis commentedon Feb 18, 2016
triage: P-high
nikomatsakis commentedon Apr 7, 2016
I think this is one of those "fixed by moving region/borrowck to MIR"
brson commentedon Jun 23, 2016
@pnkfelix Is this still on your radar? It's been assigned a while.
37 remaining items
landaire commentedon May 22, 2019
I think the downgrade is performed here:
rust/src/librustc_mir/borrow_check/mod.rs
Lines 394 to 411 in 2f1bc91
And references these issues related to the downgrade #55492 #58776
For the explicit
#![feature(nll)], it looks like this has to do withif tcx.migrate_borrowck(), which going down the call graph leads us to:rust/src/librustc/ty/context.rs
Lines 1555 to 1583 in fe5f42c
Can't seem to find the relevant discussion for the decision here though.
eddyb commentedon May 23, 2019
@landaire Yeah but shouldn't Rust 2018 turn on the NLL borrowck in its full mode?
Unless
BorrowckMode::Mirwas never on stable and theComparemode was enabled for 2015 recently?(after having been the mode on the 2018 edition all this time)
matthewjasper commentedon May 23, 2019
it wasn't.
pnkfelix commentedon May 24, 2019
@eddyb wrote:
and also wrote:
See also #58781.
In particular is mention there of making full NLL mode the default for the 2018 edition on its own (vs doing that for all editions en masse).
p.s. the default is
BorrowckMode::Migrate, notCompare. We should kill offComparemode in the short term, as its not serving a real purpose anymore.Add tests for rust-lang#27282, rust-lang#31287 as hard errors.
Rollup merge of rust-lang#63059 - Centril:sound-bind-by-move, r=matth…
Rollup merge of rust-lang#63059 - Centril:sound-bind-by-move, r=matth…
Add tests for rust-lang#27282, rust-lang#31287 as hard errors.
Rollup merge of rust-lang#63059 - Centril:sound-bind-by-move, r=matth…
Rollup merge of rust-lang#106005 - LeSeulArtichaut:if-let-guard-borro…