Skip to content

Commit 4eb2e68

Browse files
authored
Unrolled build for rust-lang#139097
Rollup merge of rust-lang#139097 - m-ou-se:pin-tests, r=WaffleLapkin Add more tests for pin!(). This adds the tests suggested by `@danielhenrymantilla` in this comment: rust-lang#138717 (comment) by
2 parents 8989165 + 163ea4a commit 4eb2e68

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

library/coretests/tests/pin_macro.rs

+11
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ fn temp_lifetime() {
4747
}
4848
async fn foo(_: &mut usize) {}
4949
}
50+
51+
#[test]
52+
fn transitive_extension() {
53+
async fn temporary() {}
54+
55+
// `pin!` witnessed in the wild being used like this, even if it yields
56+
// a `Pin<&mut &mut impl Unpin>`; it does work because `pin!`
57+
// happens to transitively extend the lifespan of `temporary()`.
58+
let p = pin!(&mut temporary());
59+
let _use = p;
60+
}

tests/ui/pin-macro/pin_move.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ edition:2024
2+
3+
use core::marker::PhantomPinned;
4+
use core::pin::pin;
5+
6+
fn a() {
7+
struct NotCopy<T>(T);
8+
#[allow(unused_mut)]
9+
let mut pointee = NotCopy(PhantomPinned);
10+
pin!(pointee);
11+
let _moved = pointee;
12+
//~^ ERROR use of moved value
13+
}
14+
15+
fn b() {
16+
struct NotCopy<T>(T);
17+
let mut pointee = NotCopy(PhantomPinned);
18+
pin!(*&mut pointee);
19+
//~^ ERROR cannot move
20+
let _moved = pointee;
21+
}
22+
23+
fn main() {
24+
a();
25+
b();
26+
}

tests/ui/pin-macro/pin_move.stderr

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error[E0382]: use of moved value: `pointee`
2+
--> $DIR/pin_move.rs:11:18
3+
|
4+
LL | let mut pointee = NotCopy(PhantomPinned);
5+
| ----------- move occurs because `pointee` has type `a::NotCopy<PhantomPinned>`, which does not implement the `Copy` trait
6+
LL | pin!(pointee);
7+
| ------- value moved here
8+
LL | let _moved = pointee;
9+
| ^^^^^^^ value used here after move
10+
|
11+
note: if `a::NotCopy<PhantomPinned>` implemented `Clone`, you could clone the value
12+
--> $DIR/pin_move.rs:7:5
13+
|
14+
LL | struct NotCopy<T>(T);
15+
| ^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
16+
...
17+
LL | pin!(pointee);
18+
| ------- you could clone this value
19+
20+
error[E0507]: cannot move out of a mutable reference
21+
--> $DIR/pin_move.rs:18:10
22+
|
23+
LL | pin!(*&mut pointee);
24+
| ^^^^^^^^^^^^^ move occurs because value has type `b::NotCopy<PhantomPinned>`, which does not implement the `Copy` trait
25+
|
26+
note: if `b::NotCopy<PhantomPinned>` implemented `Clone`, you could clone the value
27+
--> $DIR/pin_move.rs:16:5
28+
|
29+
LL | struct NotCopy<T>(T);
30+
| ^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
31+
LL | let mut pointee = NotCopy(PhantomPinned);
32+
LL | pin!(*&mut pointee);
33+
| ------------- you could clone this value
34+
35+
error: aborting due to 2 previous errors
36+
37+
Some errors have detailed explanations: E0382, E0507.
38+
For more information about an error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)