Skip to content

Commit d01d187

Browse files
committed
Derive trivial is_bit_valid when possible
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
1 parent ea28664 commit d01d187

30 files changed

+771
-154
lines changed

tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:18:28
33
|
44
18 | takes_try_from_bytes::<NotZerocopy>();
5-
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
note: required by a bound in `takes_try_from_bytes`
88
--> tests/ui-msrv/diagnostic-not-implemented-try-from-bytes.rs:21:28

tests/ui-msrv/try_transmute-dst-not-tryfrombytes.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:58
33
|
44
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
note: required by a bound in `try_transmute`
88
--> src/util/macro_util.rs
@@ -11,23 +11,23 @@ note: required by a bound in `try_transmute`
1111
| ^^^^^^^^^^^^ required by this bound in `try_transmute`
1212
= note: this error originates in the macro `try_transmute` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

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

26-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
26+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
2727
--> tests/ui-msrv/try_transmute-dst-not-tryfrombytes.rs:17:58
2828
|
2929
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
30-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
30+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
3131
|
3232
note: required by a bound in `ValidityError`
3333
--> src/error.rs

tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
33
|
44
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
note: required by a bound in `try_transmute_mut`
88
--> src/util/macro_util.rs
@@ -11,23 +11,23 @@ note: required by a bound in `try_transmute_mut`
1111
| ^^^^^^^^^^^^ required by this bound in `try_transmute_mut`
1212
= note: this error originates in the macro `try_transmute_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
1313

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

26-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
26+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
2727
--> tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
2828
|
2929
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
30-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
30+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
3131
|
3232
note: required by a bound in `ValidityError`
3333
--> src/error.rs

tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
33
|
44
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
note: required by a bound in `try_transmute_ref`
88
--> src/util/macro_util.rs
@@ -24,23 +24,23 @@ note: required by a bound in `try_transmute_ref`
2424
| ^^^^^^^^^ required by this bound in `try_transmute_ref`
2525
= note: this error originates in the macro `try_transmute_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
2626

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

39-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
39+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
4040
--> tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
4141
|
4242
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
4444
|
4545
note: required by a bound in `ValidityError`
4646
--> src/error.rs

tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-nightly/diagnostic-not-implemented-try-from-bytes.rs:18:28
33
|
44
18 | takes_try_from_bytes::<NotZerocopy>();
5-
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
8-
= help: the following other types implement trait `TryFromBytes`:
8+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
99
()
1010
*const T
1111
*mut T

tests/ui-nightly/try_transmute-dst-not-tryfrombytes.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs:17:33
33
|
44
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
5-
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
8-
= help: the following other types implement trait `TryFromBytes`:
8+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
99
()
1010
*const T
1111
*mut T
@@ -21,14 +21,14 @@ note: required by a bound in `ValidityError`
2121
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
2222
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
2323

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

51-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
51+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
5252
--> tests/ui-nightly/try_transmute-dst-not-tryfrombytes.rs:17:58
5353
|
5454
17 | let dst_not_try_from_bytes: Result<NotZerocopy, _> = try_transmute!(AU16(0));
55-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
5656
|
5757
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
58-
= help: the following other types implement trait `TryFromBytes`:
58+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
5959
()
6060
*const T
6161
*mut T

tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:33
33
|
44
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
8-
= help: the following other types implement trait `TryFromBytes`:
8+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
99
()
1010
*const T
1111
*mut T
@@ -21,14 +21,14 @@ note: required by a bound in `ValidityError`
2121
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
2222
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
2323

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

51-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
51+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
5252
--> tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.rs:20:63
5353
|
5454
20 | let dst_not_try_from_bytes: Result<&mut NotZerocopy, _> = try_transmute_mut!(src);
55-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
5656
|
5757
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
58-
= help: the following other types implement trait `TryFromBytes`:
58+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
5959
()
6060
*const T
6161
*mut T

tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:33
33
|
44
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
8-
= help: the following other types implement trait `TryFromBytes`:
8+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
99
()
1010
*const T
1111
*mut T
@@ -21,14 +21,14 @@ note: required by a bound in `ValidityError`
2121
| pub struct ValidityError<Src, Dst: ?Sized + TryFromBytes> {
2222
| ^^^^^^^^^^^^ required by this bound in `ValidityError`
2323

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

78-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
78+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
7979
--> tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.rs:19:59
8080
|
8181
19 | let dst_not_try_from_bytes: Result<&NotZerocopy, _> = try_transmute_ref!(&AU16(0));
82-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
8383
|
8484
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
85-
= help: the following other types implement trait `TryFromBytes`:
85+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
8686
()
8787
*const T
8888
*mut T

tests/ui-stable/diagnostic-not-implemented-try-from-bytes.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0277]: the trait bound `NotZerocopy: TryFromBytes` is not satisfied
1+
error[E0277]: the trait bound `NotZerocopy: zerocopy::TryFromBytes` is not satisfied
22
--> tests/ui-stable/diagnostic-not-implemented-try-from-bytes.rs:18:28
33
|
44
18 | takes_try_from_bytes::<NotZerocopy>();
5-
| ^^^^^^^^^^^ the trait `TryFromBytes` is not implemented for `NotZerocopy`
5+
| ^^^^^^^^^^^ the trait `zerocopy::TryFromBytes` is not implemented for `NotZerocopy`
66
|
77
= note: Consider adding `#[derive(TryFromBytes)]` to `NotZerocopy`
8-
= help: the following other types implement trait `TryFromBytes`:
8+
= help: the following other types implement trait `zerocopy::TryFromBytes`:
99
()
1010
*const T
1111
*mut T

0 commit comments

Comments
 (0)