diff options
| author | Eric Holk <ericholk@microsoft.com> | 2024-09-19 15:29:01 -0700 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2024-09-19 15:40:56 -0700 |
| commit | 92a5d21bc4a0b735750a4dff1eac204ce636b513 (patch) | |
| tree | 0f0400117eeed2d0a14ef0fd3d8ab9a77f88f893 | |
| parent | b2b76fb70659f55d5e1842b28c7d6c451ae916d9 (diff) | |
| download | rust-92a5d21bc4a0b735750a4dff1eac204ce636b513.tar.gz rust-92a5d21bc4a0b735750a4dff1eac204ce636b513.zip | |
Add a test case to make sure we don't reborrow twice
| -rw-r--r-- | tests/ui/async-await/pin-reborrow-arg.rs | 2 | ||||
| -rw-r--r-- | tests/ui/async-await/pin-reborrow-once.rs | 13 | ||||
| -rw-r--r-- | tests/ui/async-await/pin-reborrow-once.stderr | 12 |
3 files changed, 26 insertions, 1 deletions
diff --git a/tests/ui/async-await/pin-reborrow-arg.rs b/tests/ui/async-await/pin-reborrow-arg.rs index 34f23533b65..b3e8718d036 100644 --- a/tests/ui/async-await/pin-reborrow-arg.rs +++ b/tests/ui/async-await/pin-reborrow-arg.rs @@ -15,7 +15,7 @@ impl Foo { 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())`. diff --git a/tests/ui/async-await/pin-reborrow-once.rs b/tests/ui/async-await/pin-reborrow-once.rs new file mode 100644 index 00000000000..241efadef7d --- /dev/null +++ b/tests/ui/async-await/pin-reborrow-once.rs @@ -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 +} diff --git a/tests/ui/async-await/pin-reborrow-once.stderr b/tests/ui/async-await/pin-reborrow-once.stderr new file mode 100644 index 00000000000..b8fde8ffee8 --- /dev/null +++ b/tests/ui/async-await/pin-reborrow-once.stderr @@ -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`. |
