Skip to content

Commit

Permalink
Add a test case to make sure we don't reborrow twice
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Sep 19, 2024
1 parent b2b76fb commit ac5e0dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/ui/async-await/pin-reborrow-once.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(pin_ergonomics)]
#![allow(dead_code, incomplete_features)]

// Make sure with pin reborrowing that we can only get one mutable reborrow of a pinned reference.

use std::pin::{pin, Pin};

fn twice(_: Pin<&mut i32>, _: Pin<&mut i32>) {}

fn main() {
let x = pin!(42);
twice(x, x); //~ ERROR cannot borrow
}
12 changes: 12 additions & 0 deletions tests/ui/async-await/pin-reborrow-once.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0499]: cannot borrow `*x.__pointer` as mutable more than once at a time
--> $DIR/pin-reborrow-once.rs:12:14
|
LL | twice(x, x);
| ----- - ^ second mutable borrow occurs here
| | |
| | first mutable borrow occurs here
| first borrow later used by call

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0499`.

0 comments on commit ac5e0dc

Please sign in to comment.