Skip to content

Commit 55885d4

Browse files
Rollup merge of rust-lang#157069 - Darksonn:unpin-for-fut-tait, r=lcnr,RalfJung
Test that you can't implement Unpin for a compiler-generated future using TAIT I came up with this while trying to break pinning. Seems like a good idea to have a test that this doesn't change. r? @RalfJung
2 parents 53b94ea + 307310c commit 55885d4

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ edition:2024
2+
//
3+
// Tests that you can't implement Unpin for a compiler-generated future using TAIT.
4+
5+
#![feature(type_alias_impl_trait)]
6+
7+
use core::marker::PhantomPinned;
8+
use core::pin::Pin;
9+
10+
type MyFut = impl Future<Output = ()>;
11+
12+
async fn my_async_fn() {}
13+
14+
#[define_opaque(MyFut)]
15+
fn fut() -> MyFut {
16+
my_async_fn()
17+
}
18+
19+
impl Unpin for MyFut {}
20+
//~^ ERROR: only traits defined in the current crate can be implemented for arbitrary types
21+
22+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2+
--> $DIR/unpin-for-future.rs:19:1
3+
|
4+
LL | impl Unpin for MyFut {}
5+
| ^^^^^^^^^^^^^^^-----
6+
| |
7+
| type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate
8+
|
9+
= note: impl doesn't have any local type before any uncovered type parameters
10+
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
11+
= note: define and implement a trait or new type instead
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0117`.

0 commit comments

Comments
 (0)