Skip to content

Commit ac5e0dc

Browse files
committed
Add a test case to make sure we don't reborrow twice
1 parent b2b76fb commit ac5e0dc

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: tests/ui/async-await/pin-reborrow-once.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(pin_ergonomics)]
2+
#![allow(dead_code, incomplete_features)]
3+
4+
// Make sure with pin reborrowing that we can only get one mutable reborrow of a pinned reference.
5+
6+
use std::pin::{pin, Pin};
7+
8+
fn twice(_: Pin<&mut i32>, _: Pin<&mut i32>) {}
9+
10+
fn main() {
11+
let x = pin!(42);
12+
twice(x, x); //~ ERROR cannot borrow
13+
}

Diff for: tests/ui/async-await/pin-reborrow-once.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0499]: cannot borrow `*x.__pointer` as mutable more than once at a time
2+
--> $DIR/pin-reborrow-once.rs:12:14
3+
|
4+
LL | twice(x, x);
5+
| ----- - ^ second mutable borrow occurs here
6+
| | |
7+
| | first mutable borrow occurs here
8+
| first borrow later used by call
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0499`.

0 commit comments

Comments
 (0)