Skip to content

Commit 278070d

Browse files
committed
tests: add expand and compile-fail tests for [Maybe]Zeroable
Signed-off-by: Benno Lossin <[email protected]>
1 parent ab0985a commit 278070d

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extern crate pin_init;
2+
use pin_init::*;
3+
4+
#[derive(Zeroable)]
5+
struct Foo {
6+
a: usize,
7+
b: &'static Foo,
8+
}
9+
10+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `&'static Foo: pin_init::Zeroable` is not satisfied
2+
--> tests/ui/compile-fail/zeroable/not_all_fields_zeroable.rs:7:8
3+
|
4+
7 | b: &'static Foo,
5+
| ^^^^^^^^^^^^ the trait `pin_init::Zeroable` is not implemented for `&'static Foo`
6+
|
7+
note: required by a bound in `assert_zeroable`
8+
--> tests/ui/compile-fail/zeroable/not_all_fields_zeroable.rs:4:10
9+
|
10+
4 | #[derive(Zeroable)]
11+
| ^^^^^^^^ required by this bound in `assert_zeroable`
12+
= note: this error originates in the macro `::pin_init::__derive_zeroable` which comes from the expansion of the derive macro `Zeroable` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
help: consider removing the leading `&`-reference
14+
|
15+
7 - b: &'static Foo,
16+
7 + b: Foo,
17+
|
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use pin_init::*;
2+
struct Foo {
3+
a: usize,
4+
pub(crate) b: usize,
5+
}
6+
#[automatically_derived]
7+
unsafe impl ::pin_init::Zeroable for Foo {}
8+
const _: () = {
9+
fn assert_zeroable<T: ?::core::marker::Sized + ::pin_init::Zeroable>() {}
10+
fn ensure_zeroable() {
11+
assert_zeroable::<usize>();
12+
assert_zeroable::<usize>();
13+
}
14+
};
15+
struct Bar {
16+
a: usize,
17+
b: &'static usize,
18+
}
19+
#[automatically_derived]
20+
unsafe impl ::pin_init::Zeroable for Bar
21+
where
22+
usize: for<'__dummy> ::pin_init::Zeroable,
23+
&'static usize: for<'__dummy> ::pin_init::Zeroable,
24+
{}
25+
trait Trait {}
26+
struct WithGenerics<'a, T, U: Trait> {
27+
a: T,
28+
u: &'a U,
29+
}
30+
#[automatically_derived]
31+
unsafe impl<
32+
'a,
33+
T: ::pin_init::Zeroable,
34+
U: ::pin_init::Zeroable + Trait,
35+
> ::pin_init::Zeroable for WithGenerics<'a, T, U> {}
36+
const _: () = {
37+
fn assert_zeroable<T: ?::core::marker::Sized + ::pin_init::Zeroable>() {}
38+
fn ensure_zeroable<'a, T: ::pin_init::Zeroable, U: ::pin_init::Zeroable + Trait>() {
39+
assert_zeroable::<T>();
40+
assert_zeroable::<&'a U>();
41+
}
42+
};

tests/ui/expand/zeroable.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use pin_init::*;
2+
3+
#[derive(Zeroable)]
4+
struct Foo {
5+
a: usize,
6+
pub(crate) b: usize,
7+
}
8+
9+
#[derive(MaybeZeroable)]
10+
struct Bar {
11+
a: usize,
12+
b: &'static usize,
13+
}
14+
15+
trait Trait {}
16+
17+
#[derive(Zeroable)]
18+
struct WithGenerics<'a, T, U: Trait> {
19+
a: T,
20+
u: &'a U,
21+
}

0 commit comments

Comments
 (0)