Skip to content

Commit 0586497

Browse files
committed
blake2: fix clippy nits
1 parent 18c740f commit 0586497

File tree

12 files changed

+67
-67
lines changed

12 files changed

+67
-67
lines changed

.github/workflows/workspace.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v1
1717
- uses: actions-rs/toolchain@v1
1818
with:
19-
toolchain: 1.41.0 # MSRV
19+
toolchain: 1.53.0
2020
components: clippy
2121
profile: minimal
2222
override: true

blake2/src/blake2b.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl Hash {
598598

599599
/// Convert the hash to a lowercase hexadecimal
600600
/// [`ArrayString`](https://docs.rs/arrayvec/0.4/arrayvec/struct.ArrayString.html).
601-
pub fn to_hex(&self) -> HexString {
601+
pub fn to_hex(self) -> HexString {
602602
bytes_to_hex(self.as_bytes())
603603
}
604604
}
@@ -616,14 +616,14 @@ fn bytes_to_hex(bytes: &[u8]) -> HexString {
616616
/// This implementation is constant time, if the two hashes are the same length.
617617
impl PartialEq for Hash {
618618
fn eq(&self, other: &Hash) -> bool {
619-
constant_time_eq::constant_time_eq(&self.as_bytes(), &other.as_bytes())
619+
constant_time_eq::constant_time_eq(self.as_bytes(), other.as_bytes())
620620
}
621621
}
622622

623623
/// This implementation is constant time, if the slice is the same length as the hash.
624624
impl PartialEq<[u8]> for Hash {
625625
fn eq(&self, other: &[u8]) -> bool {
626-
constant_time_eq::constant_time_eq(&self.as_bytes(), other)
626+
constant_time_eq::constant_time_eq(self.as_bytes(), other)
627627
}
628628
}
629629

blake2/src/blake2b/avx2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,8 @@ pub unsafe fn compress4_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
844844
jobs[2].input.as_ptr(),
845845
jobs[3].input.as_ptr(),
846846
];
847-
let mut h_vecs = transpose_state_vecs(&jobs);
848-
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
847+
let mut h_vecs = transpose_state_vecs(jobs);
848+
let (mut counts_lo, mut counts_hi) = load_counts(jobs);
849849

850850
// Prepare the final blocks (note, which could be empty if the input is
851851
// empty). Do all this before entering the main loop.

blake2/src/blake2b/guts.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ pub const MAX_DEGREE: usize = 4;
88
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
99
pub const MAX_DEGREE: usize = 1;
1010

11-
// Variants other than Portable are unreachable in no_std, unless CPU features
12-
// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
13-
// This might change in the future if is_x86_feature_detected moves into libcore.
11+
/// Variants other than Portable are unreachable in no_std, unless CPU features
12+
/// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
13+
/// This might change in the future if is_x86_feature_detected moves into libcore.
1414
#[allow(dead_code)]
1515
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1616
enum Platform {
1717
Portable,
1818
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
19-
SSE41,
19+
Sse41,
2020
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
21-
AVX2,
21+
Avx2,
2222
}
2323

2424
#[derive(Clone, Copy, Debug)]
@@ -53,13 +53,13 @@ impl Implementation {
5353
// Check whether SSE4.1 support is assumed by the build.
5454
#[cfg(target_feature = "sse4.1")]
5555
{
56-
return Some(Implementation(Platform::SSE41));
56+
return Some(Implementation(Platform::Sse41));
5757
}
5858
// Otherwise dynamically check for support if we can.
5959
#[cfg(feature = "std")]
6060
{
6161
if is_x86_feature_detected!("sse4.1") {
62-
return Some(Implementation(Platform::SSE41));
62+
return Some(Implementation(Platform::Sse41));
6363
}
6464
}
6565
None
@@ -71,13 +71,13 @@ impl Implementation {
7171
// Check whether AVX2 support is assumed by the build.
7272
#[cfg(target_feature = "avx2")]
7373
{
74-
return Some(Implementation(Platform::AVX2));
74+
return Some(Implementation(Platform::Avx2));
7575
}
7676
// Otherwise dynamically check for support if we can.
7777
#[cfg(feature = "std")]
7878
{
7979
if is_x86_feature_detected!("avx2") {
80-
return Some(Implementation(Platform::AVX2));
80+
return Some(Implementation(Platform::Avx2));
8181
}
8282
}
8383
None
@@ -86,9 +86,9 @@ impl Implementation {
8686
pub fn degree(&self) -> usize {
8787
match self.0 {
8888
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
89-
Platform::AVX2 => avx2::DEGREE,
89+
Platform::Avx2 => avx2::DEGREE,
9090
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
91-
Platform::SSE41 => sse41::DEGREE,
91+
Platform::Sse41 => sse41::DEGREE,
9292
Platform::Portable => 1,
9393
}
9494
}
@@ -104,7 +104,7 @@ impl Implementation {
104104
) {
105105
match self.0 {
106106
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
107-
Platform::AVX2 => unsafe {
107+
Platform::Avx2 => unsafe {
108108
avx2::compress1_loop(input, words, count, last_node, finalize, stride);
109109
},
110110
// Note that there's an SSE version of compress1 in the official C
@@ -118,7 +118,7 @@ impl Implementation {
118118
pub fn compress2_loop(&self, jobs: &mut [Job<'_, '_>; 2], finalize: Finalize, stride: Stride) {
119119
match self.0 {
120120
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
121-
Platform::AVX2 | Platform::SSE41 => unsafe {
121+
Platform::Avx2 | Platform::Sse41 => unsafe {
122122
sse41::compress2_loop(jobs, finalize, stride)
123123
},
124124
_ => panic!("unsupported"),
@@ -128,7 +128,7 @@ impl Implementation {
128128
pub fn compress4_loop(&self, jobs: &mut [Job<'_, '_>; 4], finalize: Finalize, stride: Stride) {
129129
match self.0 {
130130
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
131-
Platform::AVX2 => unsafe { avx2::compress4_loop(jobs, finalize, stride) },
131+
Platform::Avx2 => unsafe { avx2::compress4_loop(jobs, finalize, stride) },
132132
_ => panic!("unsupported"),
133133
}
134134
}
@@ -271,20 +271,20 @@ mod test {
271271
#[cfg(feature = "std")]
272272
{
273273
if is_x86_feature_detected!("avx2") {
274-
assert_eq!(Platform::AVX2, Implementation::detect().0);
274+
assert_eq!(Platform::Avx2, Implementation::detect().0);
275275
assert_eq!(
276-
Platform::AVX2,
276+
Platform::Avx2,
277277
Implementation::avx2_if_supported().unwrap().0
278278
);
279279
assert_eq!(
280-
Platform::SSE41,
280+
Platform::Sse41,
281281
Implementation::sse41_if_supported().unwrap().0
282282
);
283283
} else if is_x86_feature_detected!("sse4.1") {
284-
assert_eq!(Platform::SSE41, Implementation::detect().0);
284+
assert_eq!(Platform::Sse41, Implementation::detect().0);
285285
assert!(Implementation::avx2_if_supported().is_none());
286286
assert_eq!(
287-
Platform::SSE41,
287+
Platform::Sse41,
288288
Implementation::sse41_if_supported().unwrap().0
289289
);
290290
} else {
@@ -302,9 +302,9 @@ mod test {
302302
{
303303
// Chose counts to hit the relevant overflow cases.
304304
let counts = &[
305-
(0 as Count),
306-
((1 as Count) << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
307-
(0 as Count).wrapping_sub(BLOCKBYTES as Count),
305+
0_u128,
306+
(1_u128 << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
307+
0_u128.wrapping_sub(BLOCKBYTES as Count),
308308
];
309309
for &stride in &[Stride::Serial, Stride::Parallel] {
310310
let lengths = [

blake2/src/blake2b/sse41.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ pub unsafe fn compress2_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
380380
}
381381

382382
let msg_ptrs = [jobs[0].input.as_ptr(), jobs[1].input.as_ptr()];
383-
let mut h_vecs = transpose_state_vecs(&jobs);
384-
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
383+
let mut h_vecs = transpose_state_vecs(jobs);
384+
let (mut counts_lo, mut counts_hi) = load_counts(jobs);
385385

386386
// Prepare the final blocks (note, which could be empty if the input is
387387
// empty). Do all this before entering the main loop.

blake2/src/blake2bp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn finalize_root_words(
464464
Stride::Serial,
465465
);
466466
Hash {
467-
bytes: crate::blake2b::state_words_to_bytes(&root_words),
467+
bytes: crate::blake2b::state_words_to_bytes(root_words),
468468
len: hash_length,
469469
}
470470
}
@@ -537,7 +537,7 @@ pub(crate) mod test {
537537
force_portable(&mut params);
538538
}
539539
let input = &buf[..num_blocks * BLOCKBYTES + extra];
540-
let expected = blake2bp_reference(&input);
540+
let expected = blake2bp_reference(input);
541541
let mut state = params.to_state();
542542
let found = state.update(input).finalize();
543543
assert_eq!(expected, found);

blake2/src/blake2s.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl Hash {
589589

590590
/// Convert the hash to a lowercase hexadecimal
591591
/// [`ArrayString`](https://docs.rs/arrayvec/0.4/arrayvec/struct.ArrayString.html).
592-
pub fn to_hex(&self) -> HexString {
592+
pub fn to_hex(self) -> HexString {
593593
bytes_to_hex(self.as_bytes())
594594
}
595595
}
@@ -607,14 +607,14 @@ fn bytes_to_hex(bytes: &[u8]) -> HexString {
607607
/// This implementation is constant time, if the two hashes are the same length.
608608
impl PartialEq for Hash {
609609
fn eq(&self, other: &Hash) -> bool {
610-
constant_time_eq::constant_time_eq(&self.as_bytes(), &other.as_bytes())
610+
constant_time_eq::constant_time_eq(self.as_bytes(), other.as_bytes())
611611
}
612612
}
613613

614614
/// This implementation is constant time, if the slice is the same length as the hash.
615615
impl PartialEq<[u8]> for Hash {
616616
fn eq(&self, other: &[u8]) -> bool {
617-
constant_time_eq::constant_time_eq(&self.as_bytes(), other)
617+
constant_time_eq::constant_time_eq(self.as_bytes(), other)
618618
}
619619
}
620620

blake2/src/blake2s/avx2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ pub unsafe fn compress8_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
477477
jobs[6].input.as_ptr(),
478478
jobs[7].input.as_ptr(),
479479
];
480-
let mut h_vecs = transpose_state_vecs(&jobs);
481-
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
480+
let mut h_vecs = transpose_state_vecs(jobs);
481+
let (mut counts_lo, mut counts_hi) = load_counts(jobs);
482482

483483
// Prepare the final blocks (note, which could be empty if the input is
484484
// empty). Do all this before entering the main loop.

blake2/src/blake2s/guts.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ pub const MAX_DEGREE: usize = 8;
88
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
99
pub const MAX_DEGREE: usize = 1;
1010

11-
// Variants other than Portable are unreachable in no_std, unless CPU features
12-
// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
13-
// This might change in the future if is_x86_feature_detected moves into libcore.
11+
/// Variants other than Portable are unreachable in no_std, unless CPU features
12+
/// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
13+
/// This might change in the future if is_x86_feature_detected moves into libcore.
1414
#[allow(dead_code)]
1515
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1616
enum Platform {
1717
Portable,
1818
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
19-
SSE41,
19+
Sse41,
2020
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
21-
AVX2,
21+
Avx2,
2222
}
2323

2424
#[derive(Clone, Copy, Debug)]
@@ -53,13 +53,13 @@ impl Implementation {
5353
// Check whether SSE4.1 support is assumed by the build.
5454
#[cfg(target_feature = "sse4.1")]
5555
{
56-
return Some(Implementation(Platform::SSE41));
56+
return Some(Implementation(Platform::Sse41));
5757
}
5858
// Otherwise dynamically check for support if we can.
5959
#[cfg(feature = "std")]
6060
{
6161
if is_x86_feature_detected!("sse4.1") {
62-
return Some(Implementation(Platform::SSE41));
62+
return Some(Implementation(Platform::Sse41));
6363
}
6464
}
6565
None
@@ -71,13 +71,13 @@ impl Implementation {
7171
// Check whether AVX2 support is assumed by the build.
7272
#[cfg(target_feature = "avx2")]
7373
{
74-
return Some(Implementation(Platform::AVX2));
74+
return Some(Implementation(Platform::Avx2));
7575
}
7676
// Otherwise dynamically check for support if we can.
7777
#[cfg(feature = "std")]
7878
{
7979
if is_x86_feature_detected!("avx2") {
80-
return Some(Implementation(Platform::AVX2));
80+
return Some(Implementation(Platform::Avx2));
8181
}
8282
}
8383
None
@@ -86,9 +86,9 @@ impl Implementation {
8686
pub fn degree(&self) -> usize {
8787
match self.0 {
8888
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
89-
Platform::AVX2 => avx2::DEGREE,
89+
Platform::Avx2 => avx2::DEGREE,
9090
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
91-
Platform::SSE41 => sse41::DEGREE,
91+
Platform::Sse41 => sse41::DEGREE,
9292
Platform::Portable => 1,
9393
}
9494
}
@@ -104,7 +104,7 @@ impl Implementation {
104104
) {
105105
match self.0 {
106106
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
107-
Platform::AVX2 | Platform::SSE41 => unsafe {
107+
Platform::Avx2 | Platform::Sse41 => unsafe {
108108
sse41::compress1_loop(input, words, count, last_node, finalize, stride);
109109
},
110110
Platform::Portable => {
@@ -116,7 +116,7 @@ impl Implementation {
116116
pub fn compress4_loop(&self, jobs: &mut [Job<'_, '_>; 4], finalize: Finalize, stride: Stride) {
117117
match self.0 {
118118
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
119-
Platform::AVX2 | Platform::SSE41 => unsafe {
119+
Platform::Avx2 | Platform::Sse41 => unsafe {
120120
sse41::compress4_loop(jobs, finalize, stride)
121121
},
122122
_ => panic!("unsupported"),
@@ -126,7 +126,7 @@ impl Implementation {
126126
pub fn compress8_loop(&self, jobs: &mut [Job<'_, '_>; 8], finalize: Finalize, stride: Stride) {
127127
match self.0 {
128128
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
129-
Platform::AVX2 => unsafe { avx2::compress8_loop(jobs, finalize, stride) },
129+
Platform::Avx2 => unsafe { avx2::compress8_loop(jobs, finalize, stride) },
130130
_ => panic!("unsupported"),
131131
}
132132
}
@@ -269,20 +269,20 @@ mod test {
269269
#[cfg(feature = "std")]
270270
{
271271
if is_x86_feature_detected!("avx2") {
272-
assert_eq!(Platform::AVX2, Implementation::detect().0);
272+
assert_eq!(Platform::Avx2, Implementation::detect().0);
273273
assert_eq!(
274-
Platform::AVX2,
274+
Platform::Avx2,
275275
Implementation::avx2_if_supported().unwrap().0
276276
);
277277
assert_eq!(
278-
Platform::SSE41,
278+
Platform::Sse41,
279279
Implementation::sse41_if_supported().unwrap().0
280280
);
281281
} else if is_x86_feature_detected!("sse4.1") {
282-
assert_eq!(Platform::SSE41, Implementation::detect().0);
282+
assert_eq!(Platform::Sse41, Implementation::detect().0);
283283
assert!(Implementation::avx2_if_supported().is_none());
284284
assert_eq!(
285-
Platform::SSE41,
285+
Platform::Sse41,
286286
Implementation::sse41_if_supported().unwrap().0
287287
);
288288
} else {
@@ -299,9 +299,9 @@ mod test {
299299
{
300300
// Chose counts to hit the relevant overflow cases.
301301
let counts = &[
302-
(0 as Count),
303-
((1 as Count) << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
304-
(0 as Count).wrapping_sub(BLOCKBYTES as Count),
302+
0_u64,
303+
(1_u64 << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
304+
0_u64.wrapping_sub(BLOCKBYTES as Count),
305305
];
306306
for &stride in &[Stride::Serial, Stride::Parallel] {
307307
let lengths = [

blake2/src/blake2s/sse41.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ pub unsafe fn compress4_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
800800
jobs[2].input.as_ptr(),
801801
jobs[3].input.as_ptr(),
802802
];
803-
let mut h_vecs = transpose_state_vecs(&jobs);
804-
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
803+
let mut h_vecs = transpose_state_vecs(jobs);
804+
let (mut counts_lo, mut counts_hi) = load_counts(jobs);
805805

806806
// Prepare the final blocks (note, which could be empty if the input is
807807
// empty). Do all this before entering the main loop.

0 commit comments

Comments
 (0)