Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 7, 2019
1 parent 9e04e2a commit 41eee20
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/ui/cfg/proper_unpin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// compile-fail

use pin_project::pin_project;
use std::{marker::PhantomPinned, pin::Pin};

#[pin_project]
struct Foo<T> {
#[cfg(any())]
#[pin]
inner: T,
#[cfg(not(any()))]
inner: T,
}

#[pin_project]
struct Bar<T> {
#[cfg(any())]
inner: T,
#[cfg(not(any()))]
#[pin]
inner: T,
}

fn is_unpin<T: Unpin>() {}

fn baz<T, U>() {
is_unpin::<Foo<PhantomPinned>>(); // Ok
is_unpin::<Bar<PhantomPinned>>(); //~ ERROR E0277
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/cfg/proper_unpin.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `UnpinStructBar<std::marker::PhantomPinned>`
--> $DIR/proper_unpin.rs:28:5
|
24 | fn is_unpin<T: Unpin>() {}
| ----------------------- required by `is_unpin`
...
28 | is_unpin::<Bar<PhantomPinned>>(); //~ ERROR E0277
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `UnpinStructBar<std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned`
|
= help: the following implementations were found:
<std::marker::PhantomPinned as std::marker::Unpin>
= note: required because it appears within the type `UnpinStructBar<std::marker::PhantomPinned>`
= note: required because of the requirements on the impl of `std::marker::Unpin` for `Bar<std::marker::PhantomPinned>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
21 changes: 21 additions & 0 deletions tests/ui/unsafe_unpin/proper_unpin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// compile-fail

use pin_project::{pin_project, UnsafeUnpin};
use std::{marker::PhantomPinned, pin::Pin};

#[pin_project(UnsafeUnpin)]
struct Foo<T, U> {
#[pin]
inner: T,
other: U,
}

unsafe impl<T: Unpin, U> UnsafeUnpin for Foo<T, U> {}

fn is_unpin<T: Unpin>() {}

fn bar<T, U>() {
is_unpin::<Foo<PhantomPinned, U>>(); //~ ERROR E0277
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/unsafe_unpin/proper_unpin.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied
--> $DIR/proper_unpin.rs:18:5
|
15 | fn is_unpin<T: Unpin>() {}
| ----------------------- required by `is_unpin`
...
18 | is_unpin::<Foo<PhantomPinned, U>>(); //~ ERROR E0277
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned`
|
= help: the following implementations were found:
<std::marker::PhantomPinned as std::marker::Unpin>
= note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `Foo<std::marker::PhantomPinned, U>`
= note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<Foo<std::marker::PhantomPinned, U>>`
= note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned, U>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 41eee20

Please sign in to comment.