Skip to content

Commit 1149c58

Browse files
committed
Add test for #46589.
This commit adds the test for writing into a projection of a local to confirm there are no remaining borrows.
1 parent 77a6a61 commit 1149c58

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/test/ui/nll/issue-46589.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(nll)]
12+
13+
struct Foo;
14+
15+
impl Foo {
16+
fn get_self(&mut self) -> Option<&mut Self> {
17+
Some(self)
18+
}
19+
20+
fn new_self(&mut self) -> &mut Self {
21+
self
22+
}
23+
24+
fn trigger_bug(&mut self) {
25+
let other = &mut (&mut *self);
26+
27+
*other = match (*other).get_self() {
28+
Some(s) => s,
29+
None => (*other).new_self()
30+
//~^ ERROR cannot borrow `**other` as mutable more than once at a time [E0499]
31+
};
32+
33+
let c = other;
34+
//~^ ERROR cannot move out of `other` because it is borrowed [E0505]
35+
}
36+
}
37+
38+
fn main() {}

src/test/ui/nll/issue-46589.stderr

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0499]: cannot borrow `**other` as mutable more than once at a time
2+
--> $DIR/issue-46589.rs:29:21
3+
|
4+
LL | *other = match (*other).get_self() {
5+
| -------- first mutable borrow occurs here
6+
LL | Some(s) => s,
7+
LL | None => (*other).new_self()
8+
| ^^^^^^^^
9+
| |
10+
| second mutable borrow occurs here
11+
| first borrow later used here
12+
13+
error[E0505]: cannot move out of `other` because it is borrowed
14+
--> $DIR/issue-46589.rs:33:17
15+
|
16+
LL | *other = match (*other).get_self() {
17+
| -------- borrow of `**other` occurs here
18+
...
19+
LL | let c = other;
20+
| ^^^^^
21+
| |
22+
| move out of `other` occurs here
23+
| borrow later used here
24+
25+
error: aborting due to 2 previous errors
26+
27+
Some errors occurred: E0499, E0505.
28+
For more information about an error, try `rustc --explain E0499`.

0 commit comments

Comments
 (0)