]> git.lizzy.rs Git - rust.git/commit
Auto merge of #57609 - matthewjasper:more-restrictive-match, r=pnkfelix
authorbors <bors@rust-lang.org>
Mon, 25 Feb 2019 06:27:35 +0000 (06:27 +0000)
committerbors <bors@rust-lang.org>
Mon, 25 Feb 2019 06:27:35 +0000 (06:27 +0000)
commit31eb0e2d3c0bfd2e0f5b662d82971c1a203708be
treed54f740779bf1dcdc1d499831dca0aa4e649f504
parentc1911babed0364ede7dedc646dbca63fac03d5c5
parent5ffc9197264a07a50bfb27e436fe284ae8c0687c
Auto merge of #57609 - matthewjasper:more-restrictive-match, r=pnkfelix

Use normal mutable borrows in matches

`ref mut` borrows are currently two-phase with NLL enabled. This changes them to be proper mutable borrows. To accommodate this, first the position of fake borrows is changed:

```text
[ 1. Pre-match ]
       |
[ (old create fake borrows) ]
[ 2. Discriminant testing -- check discriminants ] <-+
       |                                             |
       | (once a specific arm is chosen)             |
       |                                             |
[ (old read fake borrows) ]                          |
[ 3. Create "guard bindings" for arm ]               |
[ (create fake borrows) ]                            |
       |                                             |
[ 4. Execute guard code ]                            |
[ (read fake borrows) ] --(guard is false)-----------+
       |
       | (guard results in true)
       |
[ 5. Create real bindings and execute arm ]
       |
[ Exit match ]
```

The following additional changes are made to accommodate `ref mut` bindings:

* We no longer create fake `Shared` borrows. These borrows are no longer needed for soundness, just to avoid some arguably strange cases.
* `Shallow` borrows no longer conflict with existing borrows, avoiding conflicting access between the guard borrow access and the `ref mut` borrow.

There is some further clean up done in this PR:

* Avoid the "later used here" note for Shallow borrows (since it's not relevant with the message provided)
* Make any use of a two-phase borrow activate it.
* Simplify the cleanup_post_borrowck passes into a single pass.

cc #56254

r? @nikomatsakis
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/diagnostics.rs
src/librustc_mir/transform/mod.rs