Skip to content

Commit 953407a

Browse files
authored
ctutils: replace [T]: ... bounds with T: *Slice (#1395)
This should make it clearer to users which traits their types need to impl to be valid for the bounds, rather than indirectly relying on the blanket impl of `*Slice` traits for `[T]`.
1 parent f636ed7 commit 953407a

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

ctutils/src/traits/ct_assign.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ impl_ct_assign_with_ct_select!(
123123

124124
impl<T, const N: usize> CtAssign for [T; N]
125125
where
126-
[T]: CtAssign,
126+
T: CtAssignSlice,
127127
{
128128
#[inline]
129129
fn ct_assign(&mut self, rhs: &Self, choice: Choice) {
130130
self.as_mut_slice().ct_assign(rhs, choice);
131131
}
132132
}
133133

134-
impl<T, const N: usize> CtAssignSlice for [T; N] where [T]: CtAssign {}
134+
impl<T, const N: usize> CtAssignSlice for [T; N] where T: CtAssignSlice {}
135135

136136
#[cfg(feature = "subtle")]
137137
impl CtAssign for subtle::Choice {
@@ -154,7 +154,7 @@ where
154154
}
155155
#[cfg(feature = "alloc")]
156156
mod alloc {
157-
use super::{Choice, CtAssign};
157+
use super::{Choice, CtAssign, CtAssignSlice};
158158
use ::alloc::{boxed::Box, vec::Vec};
159159

160160
impl<T> CtAssign for Box<T>
@@ -170,7 +170,7 @@ mod alloc {
170170

171171
impl<T> CtAssign for Box<[T]>
172172
where
173-
[T]: CtAssign,
173+
T: CtAssignSlice,
174174
{
175175
#[inline]
176176
#[track_caller]
@@ -181,7 +181,7 @@ mod alloc {
181181

182182
impl<T> CtAssign<[T]> for Box<[T]>
183183
where
184-
[T]: CtAssign,
184+
T: CtAssignSlice,
185185
{
186186
#[inline]
187187
#[track_caller]
@@ -192,7 +192,7 @@ mod alloc {
192192

193193
impl<T> CtAssign for Vec<T>
194194
where
195-
[T]: CtAssign,
195+
T: CtAssignSlice,
196196
{
197197
#[inline]
198198
#[track_caller]
@@ -203,7 +203,7 @@ mod alloc {
203203

204204
impl<T> CtAssign<[T]> for Vec<T>
205205
where
206-
[T]: CtAssign,
206+
T: CtAssignSlice,
207207
{
208208
#[inline]
209209
#[track_caller]

ctutils/src/traits/ct_eq.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ impl CtEqSlice for cmp::Ordering {}
152152

153153
impl<T, const N: usize> CtEq for [T; N]
154154
where
155-
[T]: CtEq,
155+
T: CtEqSlice,
156156
{
157157
#[inline]
158158
fn ct_eq(&self, other: &[T; N]) -> Choice {
159159
self.as_slice().ct_eq(other.as_slice())
160160
}
161161
}
162162

163-
impl<T, const N: usize> CtEqSlice for [T; N] where [T]: CtEq {}
163+
impl<T, const N: usize> CtEqSlice for [T; N] where T: CtEqSlice {}
164164

165165
#[cfg(feature = "subtle")]
166166
impl CtEq for subtle::Choice {
@@ -183,7 +183,7 @@ where
183183

184184
#[cfg(feature = "alloc")]
185185
mod alloc {
186-
use super::{Choice, CtEq};
186+
use super::{Choice, CtEq, CtEqSlice};
187187
use ::alloc::{boxed::Box, vec::Vec};
188188

189189
impl<T> CtEq for Box<T>
@@ -199,7 +199,7 @@ mod alloc {
199199

200200
impl<T> CtEq for Box<[T]>
201201
where
202-
[T]: CtEq,
202+
T: CtEqSlice,
203203
{
204204
#[inline]
205205
#[track_caller]
@@ -210,7 +210,7 @@ mod alloc {
210210

211211
impl<T> CtEq<[T]> for Box<[T]>
212212
where
213-
[T]: CtEq,
213+
T: CtEqSlice,
214214
{
215215
#[inline]
216216
#[track_caller]
@@ -221,7 +221,7 @@ mod alloc {
221221

222222
impl<T> CtEq for Vec<T>
223223
where
224-
[T]: CtEq,
224+
T: CtEqSlice,
225225
{
226226
#[inline]
227227
#[track_caller]
@@ -232,7 +232,7 @@ mod alloc {
232232

233233
impl<T> CtEq<[T]> for Vec<T>
234234
where
235-
[T]: CtEq,
235+
T: CtEqSlice,
236236
{
237237
#[inline]
238238
#[track_caller]

ctutils/src/traits/ct_select.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Choice, CtAssign};
1+
use crate::{Choice, CtAssign, CtAssignSlice};
22
use core::{
33
cmp,
44
num::{
@@ -63,8 +63,7 @@ where
6363

6464
impl<T, const N: usize> CtSelectArray<N> for T
6565
where
66-
T: Clone + CtSelect,
67-
[T]: CtAssign,
66+
T: Clone + CtAssignSlice + CtSelect,
6867
{
6968
#[inline]
7069
fn ct_select_array(a: &[Self; N], b: &[Self; N], choice: Choice) -> [Self; N] {
@@ -181,12 +180,7 @@ mod alloc {
181180
impl<T: Clone + CtAssign> CtSelectUsingCtAssign for Box<T> {}
182181

183182
#[cfg(feature = "alloc")]
184-
impl<T> CtSelectUsingCtAssign for Box<[T]>
185-
where
186-
T: Clone,
187-
[T]: CtAssign,
188-
{
189-
}
183+
impl<T> CtSelectUsingCtAssign for Box<[T]> where T: Clone + CtAssignSlice {}
190184

191185
#[cfg(feature = "alloc")]
192186
impl<T: Clone + CtAssignSlice> CtSelectUsingCtAssign for Vec<T> {}

0 commit comments

Comments
 (0)