Auto merge of #56649 - davidtwco:issue-46589, r=pnkfelix
MIR borrowck doesn't accept the example of iterating and updating a mutable reference Fixes #46589. r? @pnkfelix or @nikomatsakis
This commit is contained in:
commit
817dda7df0
21 changed files with 307 additions and 191 deletions
37
src/test/ui/nll/issue-46589.rs
Normal file
37
src/test/ui/nll/issue-46589.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
fn get_self(&mut self) -> Option<&mut Self> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn new_self(&mut self) -> &mut Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn trigger_bug(&mut self) {
|
||||
let other = &mut (&mut *self);
|
||||
|
||||
*other = match (*other).get_self() {
|
||||
Some(s) => s,
|
||||
None => (*other).new_self()
|
||||
//~^ ERROR cannot borrow `**other` as mutable more than once at a time [E0499]
|
||||
};
|
||||
|
||||
let c = other;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/nll/issue-46589.stderr
Normal file
15
src/test/ui/nll/issue-46589.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error[E0499]: cannot borrow `**other` as mutable more than once at a time
|
||||
--> $DIR/issue-46589.rs:29:21
|
||||
|
|
||||
LL | *other = match (*other).get_self() {
|
||||
| -------- first mutable borrow occurs here
|
||||
LL | Some(s) => s,
|
||||
LL | None => (*other).new_self()
|
||||
| ^^^^^^^^
|
||||
| |
|
||||
| second mutable borrow occurs here
|
||||
| first borrow later used here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0499`.
|
||||
|
|
@ -27,10 +27,8 @@ fn nll_fail() {
|
|||
//~| ERROR (Mir) [E0506]
|
||||
data.0 = 'f';
|
||||
//~^ ERROR (Ast) [E0506]
|
||||
//~| ERROR (Mir) [E0506]
|
||||
data.0 = 'g';
|
||||
//~^ ERROR (Ast) [E0506]
|
||||
//~| ERROR (Mir) [E0506]
|
||||
capitalize(c);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ LL | data.0 = 'f';
|
|||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Ast)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:31:5
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:30:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ------ borrow of `data.0` occurs here
|
||||
|
|
@ -26,7 +26,7 @@ LL | data.0 = 'g';
|
|||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Ast)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:41:5
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:39:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ------ borrow of `data.0` occurs here
|
||||
|
|
@ -34,21 +34,21 @@ LL | capitalize(c);
|
|||
LL | data.0 = 'e';
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Ast)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:41:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ------ borrow of `data.0` occurs here
|
||||
...
|
||||
LL | data.0 = 'f';
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Ast)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:43:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ------ borrow of `data.0` occurs here
|
||||
...
|
||||
LL | data.0 = 'f';
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Ast)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:45:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ------ borrow of `data.0` occurs here
|
||||
...
|
||||
LL | data.0 = 'g';
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
|
||||
|
|
@ -64,30 +64,6 @@ LL | data.0 = 'e';
|
|||
LL | capitalize(c);
|
||||
| - borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Mir)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:28:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ----------- borrow of `data.0` occurs here
|
||||
...
|
||||
LL | data.0 = 'f';
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
...
|
||||
LL | capitalize(c);
|
||||
| - borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `data.0` because it is borrowed (Mir)
|
||||
--> $DIR/loan_ends_mid_block_pair.rs:31:5
|
||||
|
|
||||
LL | let c = &mut data.0;
|
||||
| ----------- borrow of `data.0` occurs here
|
||||
...
|
||||
LL | data.0 = 'g';
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `data.0` occurs here
|
||||
...
|
||||
LL | capitalize(c);
|
||||
| - borrow later used here
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue