Skip to content

Commit 21f7275

Browse files
authored
Merge pull request #48 from Rust-for-Linux/dev/sync-v6.16-fixes
Dev/sync v6.16 fixes
2 parents 479f9bd + 278070d commit 21f7275

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

src/lib.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,10 @@ pub use ::pin_init_internal::pin_data;
395395
/// ```
396396
pub use ::pin_init_internal::pinned_drop;
397397

398-
/// Derives the [`Zeroable`] trait for the given struct.
398+
/// Derives the [`Zeroable`] trait for the given `struct` or `union`.
399399
///
400-
/// This can only be used for structs where every field implements the [`Zeroable`] trait.
400+
/// This can only be used for `struct`s/`union`s where every field implements the [`Zeroable`]
401+
/// trait.
401402
///
402403
/// # Examples
403404
///
@@ -406,14 +407,25 @@ pub use ::pin_init_internal::pinned_drop;
406407
///
407408
/// #[derive(Zeroable)]
408409
/// pub struct DriverData {
409-
/// id: i64,
410+
/// pub(crate) id: i64,
410411
/// buf_ptr: *mut u8,
411412
/// len: usize,
412413
/// }
413414
/// ```
415+
///
416+
/// ```
417+
/// use pin_init::Zeroable;
418+
///
419+
/// #[derive(Zeroable)]
420+
/// pub union SignCast {
421+
/// signed: i64,
422+
/// unsigned: u64,
423+
/// }
424+
/// ```
414425
pub use ::pin_init_internal::Zeroable;
415426

416-
/// Derives the [`Zeroable`] trait for the given struct if all fields implement [`Zeroable`].
427+
/// Derives the [`Zeroable`] trait for the given `struct` or `union` if all fields implement
428+
/// [`Zeroable`].
417429
///
418430
/// Contrary to the derive macro named [`macro@Zeroable`], this one silently fails when a field
419431
/// doesn't implement [`Zeroable`].
@@ -426,15 +438,15 @@ pub use ::pin_init_internal::Zeroable;
426438
/// // implmements `Zeroable`
427439
/// #[derive(MaybeZeroable)]
428440
/// pub struct DriverData {
429-
/// id: i64,
441+
/// pub(crate) id: i64,
430442
/// buf_ptr: *mut u8,
431443
/// len: usize,
432444
/// }
433445
///
434446
/// // does not implmement `Zeroable`
435447
/// #[derive(MaybeZeroable)]
436448
/// pub struct DriverData2 {
437-
/// id: i64,
449+
/// pub(crate) id: i64,
438450
/// buf_ptr: *mut u8,
439451
/// len: usize,
440452
/// // this field doesn't implement `Zeroable`
@@ -1580,7 +1592,7 @@ impl_tuple_zeroable!(A, B, C, D, E, F, G, H, I, J);
15801592
/// });
15811593
/// ```
15821594
pub trait Wrapper<T> {
1583-
/// Create an pin-initializer for a [`Self`] containing `T` form the `value_init` initializer.
1595+
/// Creates an pin-initializer for a [`Self`] containing `T` from the `value_init` initializer.
15841596
fn pin_init<E>(value_init: impl PinInit<T, E>) -> impl PinInit<Self, E>;
15851597
}
15861598

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+
|

tests/ui/expand/zeroable.expanded.rs

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)