Skip to content

Commit

Permalink
Fixed new clippy warnings (#617)
Browse files Browse the repository at this point in the history
* Fixed new clippy warnings

* Undid breaking all the tests

* Fixed more clippy warnings

---------

Co-authored-by: Victor Koenders <[email protected]>
  • Loading branch information
VictorKoenders and Victor Koenders authored Mar 30, 2023
1 parent 6791311 commit 3431e6e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions benches/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn slice_varint_u8(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("slice_varint_u8", |b| {
b.iter(|| {
Expand All @@ -25,7 +25,7 @@ fn slice_varint_u16(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("slice_varint_u16", |b| {
b.iter(|| {
Expand All @@ -41,7 +41,7 @@ fn slice_varint_u32(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("slice_varint_u32", |b| {
b.iter(|| {
Expand All @@ -57,7 +57,7 @@ fn slice_varint_u64(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("slice_varint_u64", |b| {
b.iter(|| {
Expand All @@ -73,7 +73,7 @@ fn bufreader_varint_u8(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("bufreader_varint_u8", |b| {
b.iter(|| {
Expand All @@ -91,7 +91,7 @@ fn bufreader_varint_u16(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("bufreader_varint_u16", |b| {
b.iter(|| {
Expand All @@ -109,7 +109,7 @@ fn bufreader_varint_u32(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("bufreader_varint_u32", |b| {
b.iter(|| {
Expand All @@ -127,7 +127,7 @@ fn bufreader_varint_u64(c: &mut Criterion) {
.take(10_000)
.collect();
let config = config::standard();
let bytes = bincode::encode_to_vec(&input, config).unwrap();
let bytes = bincode::encode_to_vec(input, config).unwrap();

c.bench_function("bufreader_varint_u64", |b| {
b.iter(|| {
Expand Down
4 changes: 2 additions & 2 deletions src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ where
Ok(Err(u))
}
x => Err(DecodeError::UnexpectedVariant {
found: x as u32,
found: x,
allowed: &crate::error::AllowedEnumVariants::Range { max: 1, min: 0 },
type_name: core::any::type_name::<Result<T, U>>(),
}),
Expand All @@ -631,7 +631,7 @@ where
Ok(Err(u))
}
x => Err(DecodeError::UnexpectedVariant {
found: x as u32,
found: x,
allowed: &crate::error::AllowedEnumVariants::Range { max: 1, min: 0 },
type_name: core::any::type_name::<Result<T, U>>(),
}),
Expand Down
14 changes: 7 additions & 7 deletions src/varint/decode_unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ where
let mut bytes = [0u8; 4];
read.read(&mut bytes)?;
Ok(match endian {
Endian::Big => u32::from_be_bytes(bytes) as u32,
Endian::Little => u32::from_le_bytes(bytes) as u32,
Endian::Big => u32::from_be_bytes(bytes),
Endian::Little => u32::from_le_bytes(bytes),
})
}
U64_BYTE => invalid_varint_discriminant(IntegerType::U32, IntegerType::U64),
Expand Down Expand Up @@ -94,8 +94,8 @@ where
let mut bytes = [0u8; 8];
read.read(&mut bytes)?;
Ok(match endian {
Endian::Big => u64::from_be_bytes(bytes) as u64,
Endian::Little => u64::from_le_bytes(bytes) as u64,
Endian::Big => u64::from_be_bytes(bytes),
Endian::Little => u64::from_le_bytes(bytes),
})
}
U128_BYTE => invalid_varint_discriminant(IntegerType::U64, IntegerType::U128),
Expand Down Expand Up @@ -242,7 +242,7 @@ pub fn varint_decode_u32<R: Reader>(read: &mut R, endian: Endian) -> Result<u32,
Endian::Little => u32::from_le_bytes(bytes[..4].try_into().unwrap()),
};

(val as u32, 5)
(val, 5)
}
U64_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U64),
U128_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U128),
Expand Down Expand Up @@ -283,7 +283,7 @@ pub fn varint_decode_u64<R: Reader>(read: &mut R, endian: Endian) -> Result<u64,
Endian::Little => u64::from_le_bytes(bytes[..8].try_into().unwrap()),
};

(val as u64, 9)
(val, 9)
}
U128_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U128),
_ => return invalid_varint_discriminant(IntegerType::U32, IntegerType::Reserved),
Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn varint_decode_u128<R: Reader>(read: &mut R, endian: Endian) -> Result<u12
Endian::Little => u128::from_le_bytes(bytes[..16].try_into().unwrap()),
};

(val as u128, 17)
(val, 17)
}
_ => return invalid_varint_discriminant(IntegerType::Usize, IntegerType::Reserved),
};
Expand Down
2 changes: 1 addition & 1 deletion tests/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::blacklisted_name)]
#![allow(clippy::disallowed_names)]
#![cfg(feature = "alloc")]

extern crate alloc;
Expand Down
4 changes: 2 additions & 2 deletions tests/basic_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn test_duration_out_of_range() {
let mut input = [0u8; 14];

bincode::encode_into_slice(
&(u64::MAX, u32::MAX),
(u64::MAX, u32::MAX),
&mut input,
bincode::config::standard(),
)
Expand All @@ -269,7 +269,7 @@ fn test_duration_wrapping() {
let mut input = [0u8; 14];

bincode::encode_into_slice(
&(u64::MAX - 4, u32::MAX),
(u64::MAX - 4, u32::MAX),
&mut input,
bincode::config::standard(),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/issues/issue_474.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl MemCache {
let config = bincode::config::standard();
let mut guard = self.cache.write().unwrap();

let encoded = bincode::serde::encode_to_vec(&cache_data, config)?;
let encoded = bincode::serde::encode_to_vec(cache_data, config)?;
let cache_item = CacheItem::new(encoded, expire_seconds);

guard.insert(*key, cache_item);
Expand Down
2 changes: 1 addition & 1 deletion tests/std.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::blacklisted_name)]
#![allow(clippy::disallowed_names)]
#![cfg(feature = "std")]

mod utils;
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ where
CMP: Fn(&V, &V) -> bool,
{
let mut buffer = [0u8; 2048];
let len = bincode::encode_into_slice(&element, &mut buffer, config).unwrap();
let len = bincode::encode_into_slice(element, &mut buffer, config).unwrap();
println!(
"{:?} ({}): {:?} ({:?})",
element,
Expand Down Expand Up @@ -40,7 +40,7 @@ where
use bincode::error::EncodeError;

let mut buffer = [0u8; 2048];
let len = bincode::serde::encode_into_slice(&element, &mut buffer, config);
let len = bincode::serde::encode_into_slice(element, &mut buffer, config);

let decoded = bincode::serde::decode_from_slice(&buffer, config);

Expand Down

0 comments on commit 3431e6e

Please sign in to comment.