Skip to content

Commit 92a5d21

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

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Foo {
1515
fn foo(_: Pin<&mut Foo>) {
1616
}
1717

18-
fn bar(mut x: Pin<&mut Foo>) {
18+
fn bar(x: Pin<&mut Foo>) {
1919
foo(x);
2020
foo(x); // for this to work we need to automatically reborrow,
2121
// as if the user had written `foo(x.as_mut())`.

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)