Skip to content

Commit

Permalink
Derive trivial is_bit_valid when possible (#1303)
Browse files Browse the repository at this point in the history
When deriving `FromBytes` on a type with no generic parameters, the
implied `TryFromBytes` derive's `is_bit_valid` impl is generated as
always returning `true`. This is faster to codegen, is faster to
compile, and is friendlier on the optimizer.

Makes progress on #5
  • Loading branch information
joshlf authored Oct 2, 2024
1 parent f57b0d7 commit a9f09d7
Show file tree
Hide file tree
Showing 30 changed files with 1,415 additions and 155 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:18:28
|
18 | takes_try_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `takes_try_from_bytes`
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:21:28
Expand Down
12 changes: 6 additions & 6 deletions tests/ui-msrv/try_transmute-dst-not-tryfrombytes.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:58
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `try_transmute`
--> src/util/macro_util.rs
Expand All @@ -11,23 +11,23 @@ note: required by a bound in `try_transmute`
| ^^^^^^^^^^^^ required by this bound in `try_transmute`
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:33
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:58
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
Expand Down
12 changes: 6 additions & 6 deletions tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `try_transmute_mut`
--> src/util/macro_util.rs
Expand All @@ -11,23 +11,23 @@ note: required by a bound in `try_transmute_mut`
| ^^^^^^^^^^^^ required by this bound in `try_transmute_mut`
= note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:33
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
|
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `try_transmute_ref`
--> src/util/macro_util.rs
Expand All @@ -24,23 +24,23 @@ note: required by a bound in `try_transmute_ref`
| ^^^^^^^^^ required by this bound in `try_transmute_ref`
= note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:33
|
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
|
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
|
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
note: required by a bound in `ValidityError`
--> src/error.rs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.rs:18:28
|
18 | takes_try_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand Down
18 changes: 9 additions & 9 deletions tests/ui-nightly/try_transmute-dst-not-tryfrombytes.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs:17:33
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -21,14 +21,14 @@ note: required by a bound in `ValidityError`
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs:17:58
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -48,14 +48,14 @@ note: required by a bound in `try_transmute`
| ^^^^^^^^^^^^ required by this bound in `try_transmute`
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs:17:58
|
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand Down
18 changes: 9 additions & 9 deletions tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:33
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -21,14 +21,14 @@ note: required by a bound in `ValidityError`
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -48,14 +48,14 @@ note: required by a bound in `try_transmute_mut`
| ^^^^^^^^^^^^ required by this bound in `try_transmute_mut`
= note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
|
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:33
|
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -21,14 +21,14 @@ note: required by a bound in `ValidityError`
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
| ^^^^^^^^^^^^ required by this bound in `ValidityError`

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
|
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand Down Expand Up @@ -75,14 +75,14 @@ note: required by a bound in `try_transmute_ref`
| ^^^^^^^^^ required by this bound in `try_transmute_ref`
= note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
|
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-stable/diagnostic-not-implemented-try-from-bytes.rs:18:28
|
18 | takes_try_from_bytes::<NotZerocopy>();
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
|
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand Down
Loading

0 comments on commit a9f09d7

Please sign in to comment.