Skip to content

Commit

Permalink
tests: Add ui tests about negative_impls for !Unpin and UnsafeUnpin o…
Browse files Browse the repository at this point in the history
…ptions
  • Loading branch information
taiki-e committed Oct 24, 2024
1 parent 31fb40c commit a36afd1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/ui/not_unpin/negative_impls_stable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

// https://github.com/taiki-e/pin-project/issues/340#issuecomment-2428002670

#[pin_project::pin_project(!Unpin)]
struct Foo<Pinned, Unpinned> {
#[pin]
pinned: Pinned,
unpinned: Unpinned,
}

struct MyPhantomPinned(::core::marker::PhantomPinned);
impl Unpin for MyPhantomPinned where for<'cursed> str: Sized {}
impl Unpin for Foo<MyPhantomPinned, ()> {}

fn is_unpin<T: Unpin>() {}

fn main() {
is_unpin::<Foo<MyPhantomPinned, ()>>()
}
8 changes: 8 additions & 0 deletions tests/ui/not_unpin/negative_impls_stable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error[E0119]: conflicting implementations of trait `Unpin` for type `Foo<MyPhantomPinned, ()>`
--> tests/ui/not_unpin/negative_impls_stable.rs:5:28
|
5 | #[pin_project::pin_project(!Unpin)]
| ^^^^^^ conflicting implementation for `Foo<MyPhantomPinned, ()>`
...
14 | impl Unpin for Foo<MyPhantomPinned, ()> {}
| --------------------------------------- first implementation here
22 changes: 22 additions & 0 deletions tests/ui/unsafe_unpin/negative_impls_stable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

// https://github.com/taiki-e/pin-project/issues/340#issuecomment-2428002670

#[pin_project::pin_project(UnsafeUnpin)]
struct Foo<Pinned, Unpinned> {
#[pin]
pinned: Pinned,
unpinned: Unpinned,
}

unsafe impl<Pinned: Unpin, Unpinned> pin_project::UnsafeUnpin for Foo<Pinned, Unpinned> {}

struct MyPhantomPinned(::core::marker::PhantomPinned);
impl Unpin for MyPhantomPinned where for<'cursed> str: Sized {}
impl Unpin for Foo<MyPhantomPinned, ()> {}

fn is_unpin<T: Unpin>() {}

fn main() {
is_unpin::<Foo<MyPhantomPinned, ()>>()
}
8 changes: 8 additions & 0 deletions tests/ui/unsafe_unpin/negative_impls_stable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error[E0119]: conflicting implementations of trait `Unpin` for type `Foo<MyPhantomPinned, ()>`
--> tests/ui/unsafe_unpin/negative_impls_stable.rs:5:28
|
5 | #[pin_project::pin_project(UnsafeUnpin)]
| ^^^^^^^^^^^ conflicting implementation for `Foo<MyPhantomPinned, ()>`
...
16 | impl Unpin for Foo<MyPhantomPinned, ()> {}
| --------------------------------------- first implementation here

0 comments on commit a36afd1

Please sign in to comment.