Commit 2fc06e6
authored
ctutils: enforce
The `Bytes*` traits exist because we don't have specialization[1] and
the generic implementation of these traits for `[T]` and `[T; N]` will
operate a byte-at-a-time on byte slices and byte arrays, when efficient
implementations from the `cmov` crate can instead perform the same
operations a word-at-a-time.
Adds != 1 const size assertions for `T` in the impls of `CtAssign`,
`CtEq` for `[T]` and `[T; N]` as well as the `CtSelect` impl for `[T;
N]` which cause a compile-time error if they're requested to be used
with 1-byte values:
error[E0080]: evaluation panicked: use `BytesCtEq::bytes_ct_eq` when
working with byte-sized values
--> ctutils/src/traits/ct_eq.rs:81:13
|
81 | / assert!(
82 | | size_of::<T>() != 1,
83 | | "use `BytesCtEq::bytes_ct_eq` when working with byte-sized
values"
84 | | );
| |_____________^ evaluation of `<[u8] as
traits::ct_eq::CtEq>::ct_eq::{constant#0}` failed here
Each of them has been configured with a message that steers the user
instead towards the appropriate `BytesCt*` trait to use instead.
[1]: https://rust-lang.github.io/rfcs/1210-impl-specialization.htmlBytes* trait usage at compile-time (#1364)1 parent 450a85b commit 2fc06e6
3 files changed
+33
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
73 | 80 | | |
74 | 81 | | |
75 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
86 | 105 | | |
87 | 106 | | |
88 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
101 | 108 | | |
102 | 109 | | |
103 | 110 | | |
| |||
0 commit comments