Add a test case to make sure we don't reborrow twice
This commit is contained in:
parent
b2b76fb706
commit
92a5d21bc4
@ -15,7 +15,7 @@ fn baz(self: Pin<&mut Self>) {
|
||||
fn foo(_: Pin<&mut Foo>) {
|
||||
}
|
||||
|
||||
fn bar(mut x: Pin<&mut Foo>) {
|
||||
fn bar(x: Pin<&mut Foo>) {
|
||||
foo(x);
|
||||
foo(x); // for this to work we need to automatically reborrow,
|
||||
// as if the user had written `foo(x.as_mut())`.
|
||||
|
13
tests/ui/async-await/pin-reborrow-once.rs
Normal file
13
tests/ui/async-await/pin-reborrow-once.rs
Normal file
@ -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
tests/ui/async-await/pin-reborrow-once.stderr
Normal file
12
tests/ui/async-await/pin-reborrow-once.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user