From 41eee2052afbcda9edb7ddcfdb924f82aa69a862 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 8 Sep 2019 00:43:15 +0900 Subject: [PATCH] Add tests --- tests/ui/cfg/proper_unpin.rs | 31 +++++++++++++++++++++++ tests/ui/cfg/proper_unpin.stderr | 17 +++++++++++++ tests/ui/unsafe_unpin/proper_unpin.rs | 21 +++++++++++++++ tests/ui/unsafe_unpin/proper_unpin.stderr | 18 +++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 tests/ui/cfg/proper_unpin.rs create mode 100644 tests/ui/cfg/proper_unpin.stderr create mode 100644 tests/ui/unsafe_unpin/proper_unpin.rs create mode 100644 tests/ui/unsafe_unpin/proper_unpin.stderr diff --git a/tests/ui/cfg/proper_unpin.rs b/tests/ui/cfg/proper_unpin.rs new file mode 100644 index 00000000..57b15db4 --- /dev/null +++ b/tests/ui/cfg/proper_unpin.rs @@ -0,0 +1,31 @@ +// compile-fail + +use pin_project::pin_project; +use std::{marker::PhantomPinned, pin::Pin}; + +#[pin_project] +struct Foo { + #[cfg(any())] + #[pin] + inner: T, + #[cfg(not(any()))] + inner: T, +} + +#[pin_project] +struct Bar { + #[cfg(any())] + inner: T, + #[cfg(not(any()))] + #[pin] + inner: T, +} + +fn is_unpin() {} + +fn baz() { + is_unpin::>(); // Ok + is_unpin::>(); //~ ERROR E0277 +} + +fn main() {} diff --git a/tests/ui/cfg/proper_unpin.stderr b/tests/ui/cfg/proper_unpin.stderr new file mode 100644 index 00000000..4f1acef0 --- /dev/null +++ b/tests/ui/cfg/proper_unpin.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `UnpinStructBar` + --> $DIR/proper_unpin.rs:28:5 + | +24 | fn is_unpin() {} + | ----------------------- required by `is_unpin` +... +28 | is_unpin::>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `UnpinStructBar`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` + | + = help: the following implementations were found: + + = note: required because it appears within the type `UnpinStructBar` + = note: required because of the requirements on the impl of `std::marker::Unpin` for `Bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/unsafe_unpin/proper_unpin.rs b/tests/ui/unsafe_unpin/proper_unpin.rs new file mode 100644 index 00000000..41d9d664 --- /dev/null +++ b/tests/ui/unsafe_unpin/proper_unpin.rs @@ -0,0 +1,21 @@ +// compile-fail + +use pin_project::{pin_project, UnsafeUnpin}; +use std::{marker::PhantomPinned, pin::Pin}; + +#[pin_project(UnsafeUnpin)] +struct Foo { + #[pin] + inner: T, + other: U, +} + +unsafe impl UnsafeUnpin for Foo {} + +fn is_unpin() {} + +fn bar() { + is_unpin::>(); //~ ERROR E0277 +} + +fn main() {} diff --git a/tests/ui/unsafe_unpin/proper_unpin.stderr b/tests/ui/unsafe_unpin/proper_unpin.stderr new file mode 100644 index 00000000..c93ee766 --- /dev/null +++ b/tests/ui/unsafe_unpin/proper_unpin.stderr @@ -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() {} + | ----------------------- required by `is_unpin` +... +18 | is_unpin::>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` + | + = help: the following implementations were found: + + = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `Foo` + = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper>` + = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.