Skip to content

Commit

Permalink
Derive trivial is_bit_valid when possible
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 committed May 19, 2024
1 parent 3aef801 commit b8eeb75
Show file tree
Hide file tree
Showing 22 changed files with 1,088 additions and 161 deletions.
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/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
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,10 +1,10 @@
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`
|
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -20,13 +20,13 @@ 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`
|
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
()
*const T
*mut T
Expand All @@ -46,13 +46,13 @@ 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`
|
= 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-stable/try_transmute-dst-not-tryfrombytes.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
--> tests/ui-stable/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`
|
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
bool
char
isize
Expand All @@ -20,13 +20,13 @@ 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-stable/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`
|
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
bool
char
isize
Expand All @@ -46,13 +46,13 @@ 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-stable/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`
|
= help: the following other types implement trait `TryFromBytes`:
= help: the following other types implement trait `zerocopy::TryFromBytes`:
bool
char
isize
Expand Down

0 comments on commit b8eeb75

Please sign in to comment.