Visitar URL original
Use static_assertions for Unpin/!Unpin assertions · taiki-e/pin-project-lite@eef3155 · GitHub
Skip to content

Commit eef3155

Browse files
committed
Use static_assertions for Unpin/!Unpin assertions
This allows the merging of some ui tests into normal tests.
1 parent 6134be4 commit eef3155

6 files changed

Lines changed: 69 additions & 80 deletions

File tree

‎Cargo.toml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ members = [
2828
[dependencies]
2929

3030
[dev-dependencies]
31-
rustversion = "1.0"
32-
trybuild = "1.0"
31+
rustversion = "1"
32+
static_assertions = "1"
33+
trybuild = "1"

‎tests/auxiliary/mod.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![allow(dead_code, unused_macros)]
2+
3+
macro_rules! assert_unpin {
4+
($ty:ty) => {
5+
static_assertions::assert_impl_all!($ty: Unpin);
6+
};
7+
}
8+
macro_rules! assert_not_unpin {
9+
($ty:ty) => {
10+
static_assertions::assert_not_impl_all!($ty: Unpin);
11+
};
12+
}

‎tests/proper_unpin.rs‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#![warn(rust_2018_idioms, single_use_lifetimes)]
2+
#![allow(dead_code)]
3+
4+
#[macro_use]
5+
mod auxiliary;
6+
7+
pub mod default {
8+
use pin_project_lite::pin_project;
9+
use std::marker::PhantomPinned;
10+
11+
struct Inner<T> {
12+
f: T,
13+
}
14+
15+
assert_unpin!(Inner<()>);
16+
assert_not_unpin!(Inner<PhantomPinned>);
17+
18+
pin_project! {
19+
struct Foo<T, U> {
20+
#[pin]
21+
f1: Inner<T>,
22+
f2: U,
23+
}
24+
}
25+
26+
assert_unpin!(Foo<(), ()>);
27+
assert_unpin!(Foo<(), PhantomPinned>);
28+
assert_not_unpin!(Foo<PhantomPinned, ()>);
29+
assert_not_unpin!(Foo<PhantomPinned, PhantomPinned>);
30+
31+
pin_project! {
32+
struct TrivialBounds {
33+
#[pin]
34+
f: PhantomPinned,
35+
}
36+
}
37+
38+
assert_not_unpin!(TrivialBounds);
39+
40+
pin_project! {
41+
struct Bar<'a, T, U> {
42+
#[pin]
43+
f1: &'a mut Inner<T>,
44+
f2: U,
45+
}
46+
}
47+
48+
assert_unpin!(Bar<'_, PhantomPinned, PhantomPinned>);
49+
}

‎tests/test.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#![warn(rust_2018_idioms, single_use_lifetimes)]
22
#![allow(dead_code)]
33

4+
#[macro_use]
5+
mod auxiliary;
6+
47
use core::{marker::PhantomPinned, pin::Pin};
58
use pin_project_lite::pin_project;
69

@@ -260,6 +263,8 @@ fn trivial_bounds() {
260263
f: PhantomPinned,
261264
}
262265
}
266+
267+
assert_not_unpin!(NoGenerics);
263268
}
264269

265270
#[test]

‎tests/ui/proper_unpin.rs‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎tests/ui/proper_unpin.stderr‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)