aboutsummaryrefslogtreecommitdiff
path: root/tests/pinned_drop.rs
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-07-10 20:23:30 -0700
committerChih-Hung Hsieh <chh@google.com>2020-07-13 22:26:50 -0700
commitd58366dc4a1a1ec807bb02dfc7928051799130ac (patch)
tree99470e8e8e4787e90b156f71bafac98438d6c39a /tests/pinned_drop.rs
parent09ba014483c2506939704e0b993a728958553e25 (diff)
downloadpin-project-d58366dc4a1a1ec807bb02dfc7928051799130ac.tar.gz
Upgrade rust/crates/pin-project to 0.4.22android-r-beta-3android-r-beta-2
* Keep local change in src/lib.rs Test: make Change-Id: I63ca4a3f247df2028bcb6cb849823b296865f444
Diffstat (limited to 'tests/pinned_drop.rs')
-rw-r--r--tests/pinned_drop.rs230
1 files changed, 144 insertions, 86 deletions
diff --git a/tests/pinned_drop.rs b/tests/pinned_drop.rs
index b0677e2..e257758 100644
--- a/tests/pinned_drop.rs
+++ b/tests/pinned_drop.rs
@@ -1,5 +1,4 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]
-#![allow(dead_code)]
use pin_project::{pin_project, pinned_drop};
use std::pin::Pin;
@@ -26,66 +25,61 @@ fn safe_project() {
}
#[test]
-fn mut_self_argument() {
- #[pin_project(PinnedDrop)]
- struct Struct {
- data: usize,
- }
-
- #[pinned_drop]
- impl PinnedDrop for Struct {
- fn drop(mut self: Pin<&mut Self>) {
- let _: &mut _ = &mut self.data;
- }
- }
-}
+fn self_argument_in_macro() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
-#[test]
-fn self_in_vec() {
#[pin_project(PinnedDrop)]
struct Struct {
- data: usize,
+ x: (),
}
#[pinned_drop]
impl PinnedDrop for Struct {
fn drop(self: Pin<&mut Self>) {
- let _: Vec<_> = vec![self.data];
+ let _: Vec<_> = vec![self.x];
}
}
}
#[test]
fn self_in_macro_containing_fn() {
- #[pin_project(PinnedDrop)]
- pub struct Struct {
- data: usize,
- }
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
- macro_rules! emit {
+ macro_rules! mac {
($($tt:tt)*) => {
$($tt)*
};
}
+ #[pin_project(PinnedDrop)]
+ pub struct Struct {
+ _x: (),
+ }
+
#[pinned_drop]
impl PinnedDrop for Struct {
fn drop(self: Pin<&mut Self>) {
- let _ = emit!({
+ let _ = mac!({
impl Struct {
- pub fn f(self) {}
+ pub fn _f(self) -> Self {
+ self
+ }
}
});
- let _ = self.data;
}
}
}
#[test]
fn self_call() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
+
#[pin_project(PinnedDrop)]
- pub struct Struct {
- data: usize,
+ pub struct Struct<T> {
+ _x: T,
}
trait Trait {
@@ -96,10 +90,10 @@ fn self_call() {
fn assoc_fn(_this: Pin<&mut Self>) {}
}
- impl Trait for Struct {}
+ impl<T> Trait for Struct<T> {}
#[pinned_drop]
- impl PinnedDrop for Struct {
+ impl<T> PinnedDrop for Struct<T> {
fn drop(mut self: Pin<&mut Self>) {
self.self_ref();
self.as_ref().self_pin_ref();
@@ -112,53 +106,13 @@ fn self_call() {
}
#[test]
-fn self_expr() {
- #[pin_project(PinnedDrop)]
- pub struct Struct {
- x: usize,
- }
-
- #[pinned_drop]
- impl PinnedDrop for Struct {
- fn drop(mut self: Pin<&mut Self>) {
- let _: Self = Self { x: 0 };
- }
- }
-
- #[pin_project(PinnedDrop)]
- pub struct TupleStruct(usize);
-
- #[pinned_drop]
- impl PinnedDrop for TupleStruct {
- fn drop(mut self: Pin<&mut Self>) {
- let _: Self = Self(0);
- }
- }
-}
-
-#[rustversion::since(1.37)]
-#[test]
-fn self_expr_enum() {
- #[pin_project(PinnedDrop)]
- pub enum Enum {
- StructVariant { x: usize },
- TupleVariant(usize),
- }
-
- #[pinned_drop]
- impl PinnedDrop for Enum {
- fn drop(mut self: Pin<&mut Self>) {
- let _: Self = Self::StructVariant { x: 0 };
- let _: Self = Self::TupleVariant(0);
- }
- }
-}
+fn self_struct() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
-#[test]
-fn self_pat() {
#[pin_project(PinnedDrop)]
pub struct Struct {
- x: usize,
+ pub x: (),
}
#[pinned_drop]
@@ -166,6 +120,10 @@ fn self_pat() {
#[allow(irrefutable_let_patterns)]
#[allow(clippy::match_single_binding)]
fn drop(mut self: Pin<&mut Self>) {
+ // expr
+ let _: Self = Self { x: () };
+
+ // pat
match *self {
Self { x: _ } => {}
}
@@ -175,12 +133,16 @@ fn self_pat() {
}
#[pin_project(PinnedDrop)]
- pub struct TupleStruct(usize);
+ pub struct TupleStruct(());
#[pinned_drop]
impl PinnedDrop for TupleStruct {
#[allow(irrefutable_let_patterns)]
fn drop(mut self: Pin<&mut Self>) {
+ // expr
+ let _: Self = Self(());
+
+ // pat
match *self {
Self(_) => {}
}
@@ -190,24 +152,32 @@ fn self_pat() {
}
}
-#[rustversion::since(1.37)]
+#[rustversion::since(1.37)] // type_alias_enum_variants requires Rust 1.37
#[test]
-fn self_pat_enum() {
+fn self_enum() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
+
#[pin_project(PinnedDrop)]
pub enum Enum {
- StructVariant { x: usize },
- TupleVariant(usize),
+ Struct { x: () },
+ Tuple(()),
}
#[pinned_drop]
impl PinnedDrop for Enum {
fn drop(mut self: Pin<&mut Self>) {
+ // expr
+ let _: Self = Self::Struct { x: () };
+ let _: Self = Self::Tuple(());
+
+ // pat
match *self {
- Self::StructVariant { x: _ } => {}
- Self::TupleVariant(_) => {}
+ Self::Struct { x: _ } => {}
+ Self::Tuple(_) => {}
}
- if let Self::StructVariant { x: _ } = *self {}
- if let Self::TupleVariant(_) = *self {}
+ if let Self::Struct { x: _ } = *self {}
+ if let Self::Tuple(_) = *self {}
}
}
}
@@ -216,20 +186,108 @@ fn self_pat_enum() {
#[rustversion::since(1.40)] // https://github.com/rust-lang/rust/pull/64690
#[test]
fn self_in_macro_def() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
+
#[pin_project(PinnedDrop)]
pub struct Struct {
- x: usize,
+ _x: (),
}
#[pinned_drop]
impl PinnedDrop for Struct {
fn drop(self: Pin<&mut Self>) {
- macro_rules! t {
+ macro_rules! mac {
() => {{
let _ = self;
}};
}
- t!();
+ mac!();
+ }
+ }
+}
+
+#[test]
+fn self_inside_macro() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
+
+ macro_rules! mac {
+ ($($tt:tt)*) => {
+ $($tt)*
+ };
+ }
+
+ #[pin_project(PinnedDrop)]
+ pub struct Struct<T: Send>
+ where
+ mac!(Self): Send,
+ {
+ _x: T,
+ }
+
+ impl<T: Send> Struct<T> {
+ const ASSOCIATED1: &'static str = "1";
+ fn associated1() {}
+ }
+
+ trait Trait {
+ type Associated2;
+ const ASSOCIATED2: &'static str;
+ fn associated2();
+ }
+
+ impl<T: Send> Trait for Struct<T> {
+ type Associated2 = ();
+ const ASSOCIATED2: &'static str = "2";
+ fn associated2() {}
+ }
+
+ #[pinned_drop]
+ impl<T: Send> PinnedDrop for Struct<T>
+ where
+ mac!(Self): Send,
+ {
+ #[allow(path_statements)]
+ #[allow(clippy::no_effect)]
+ fn drop(self: Pin<&mut Self>) {
+ // inherent items
+ mac!(Self::ASSOCIATED1;);
+ mac!(<Self>::ASSOCIATED1;);
+ mac!(Self::associated1(););
+ mac!(<Self>::associated1(););
+
+ // trait items
+ mac!(let _: <Self as Trait>::Associated2;);
+ mac!(Self::ASSOCIATED2;);
+ mac!(<Self>::ASSOCIATED2;);
+ mac!(<Self as Trait>::ASSOCIATED2;);
+ mac!(Self::associated2(););
+ mac!(<Self>::associated2(););
+ mac!(<Self as Trait>::associated2(););
}
}
}
+
+#[test]
+fn inside_macro() {
+ use pin_project::{pin_project, pinned_drop};
+ use std::pin::Pin;
+
+ #[pin_project(PinnedDrop)]
+ struct Struct(());
+
+ macro_rules! mac {
+ ($expr:expr) => {
+ #[pinned_drop]
+ impl PinnedDrop for Struct {
+ #[allow(clippy::no_effect)]
+ fn drop(self: Pin<&mut Self>) {
+ $expr;
+ }
+ }
+ };
+ }
+
+ mac!(1);
+}