Fixed new clippy warnings (#617)

* Fixed new clippy warnings

* Undid breaking all the tests

* Fixed more clippy warnings

---------

Co-authored-by: Victor Koenders <git@trang.ar>
This commit is contained in:
Trangar 2023-03-30 11:06:34 +02:00 committed by GitHub
parent b1bbcd0ea4
commit 3aa269bfea
8 changed files with 24 additions and 24 deletions

View File

@ -9,7 +9,7 @@ fn slice_varint_u8(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("slice_varint_u8", |b| {
b.iter(|| { b.iter(|| {
@ -25,7 +25,7 @@ fn slice_varint_u16(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("slice_varint_u16", |b| {
b.iter(|| { b.iter(|| {
@ -41,7 +41,7 @@ fn slice_varint_u32(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("slice_varint_u32", |b| {
b.iter(|| { b.iter(|| {
@ -57,7 +57,7 @@ fn slice_varint_u64(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("slice_varint_u64", |b| {
b.iter(|| { b.iter(|| {
@ -73,7 +73,7 @@ fn bufreader_varint_u8(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("bufreader_varint_u8", |b| {
b.iter(|| { b.iter(|| {
@ -91,7 +91,7 @@ fn bufreader_varint_u16(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("bufreader_varint_u16", |b| {
b.iter(|| { b.iter(|| {
@ -109,7 +109,7 @@ fn bufreader_varint_u32(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("bufreader_varint_u32", |b| {
b.iter(|| { b.iter(|| {
@ -127,7 +127,7 @@ fn bufreader_varint_u64(c: &mut Criterion) {
.take(10_000) .take(10_000)
.collect(); .collect();
let config = config::standard(); 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| { c.bench_function("bufreader_varint_u64", |b| {
b.iter(|| { b.iter(|| {

View File

@ -606,7 +606,7 @@ where
Ok(Err(u)) Ok(Err(u))
} }
x => Err(DecodeError::UnexpectedVariant { x => Err(DecodeError::UnexpectedVariant {
found: x as u32, found: x,
allowed: &crate::error::AllowedEnumVariants::Range { max: 1, min: 0 }, allowed: &crate::error::AllowedEnumVariants::Range { max: 1, min: 0 },
type_name: core::any::type_name::<Result<T, U>>(), type_name: core::any::type_name::<Result<T, U>>(),
}), }),
@ -631,7 +631,7 @@ where
Ok(Err(u)) Ok(Err(u))
} }
x => Err(DecodeError::UnexpectedVariant { x => Err(DecodeError::UnexpectedVariant {
found: x as u32, found: x,
allowed: &crate::error::AllowedEnumVariants::Range { max: 1, min: 0 }, allowed: &crate::error::AllowedEnumVariants::Range { max: 1, min: 0 },
type_name: core::any::type_name::<Result<T, U>>(), type_name: core::any::type_name::<Result<T, U>>(),
}), }),

View File

@ -54,8 +54,8 @@ where
let mut bytes = [0u8; 4]; let mut bytes = [0u8; 4];
read.read(&mut bytes)?; read.read(&mut bytes)?;
Ok(match endian { Ok(match endian {
Endian::Big => u32::from_be_bytes(bytes) as u32, Endian::Big => u32::from_be_bytes(bytes),
Endian::Little => u32::from_le_bytes(bytes) as u32, Endian::Little => u32::from_le_bytes(bytes),
}) })
} }
U64_BYTE => invalid_varint_discriminant(IntegerType::U32, IntegerType::U64), U64_BYTE => invalid_varint_discriminant(IntegerType::U32, IntegerType::U64),
@ -94,8 +94,8 @@ where
let mut bytes = [0u8; 8]; let mut bytes = [0u8; 8];
read.read(&mut bytes)?; read.read(&mut bytes)?;
Ok(match endian { Ok(match endian {
Endian::Big => u64::from_be_bytes(bytes) as u64, Endian::Big => u64::from_be_bytes(bytes),
Endian::Little => u64::from_le_bytes(bytes) as u64, Endian::Little => u64::from_le_bytes(bytes),
}) })
} }
U128_BYTE => invalid_varint_discriminant(IntegerType::U64, IntegerType::U128), U128_BYTE => invalid_varint_discriminant(IntegerType::U64, IntegerType::U128),
@ -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()), 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), U64_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U64),
U128_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U128), U128_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U128),
@ -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()), 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), U128_BYTE => return invalid_varint_discriminant(IntegerType::U32, IntegerType::U128),
_ => return invalid_varint_discriminant(IntegerType::U32, IntegerType::Reserved), _ => return invalid_varint_discriminant(IntegerType::U32, IntegerType::Reserved),
@ -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()), 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), _ => return invalid_varint_discriminant(IntegerType::Usize, IntegerType::Reserved),
}; };

View File

@ -1,4 +1,4 @@
#![allow(clippy::blacklisted_name)] #![allow(clippy::disallowed_names)]
#![cfg(feature = "alloc")] #![cfg(feature = "alloc")]
extern crate alloc; extern crate alloc;

View File

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

View File

@ -63,7 +63,7 @@ impl MemCache {
let config = bincode::config::standard(); let config = bincode::config::standard();
let mut guard = self.cache.write().unwrap(); 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); let cache_item = CacheItem::new(encoded, expire_seconds);
guard.insert(*key, cache_item); guard.insert(*key, cache_item);

View File

@ -1,4 +1,4 @@
#![allow(clippy::blacklisted_name)] #![allow(clippy::disallowed_names)]
#![cfg(feature = "std")] #![cfg(feature = "std")]
mod utils; mod utils;

View File

@ -7,7 +7,7 @@ where
CMP: Fn(&V, &V) -> bool, CMP: Fn(&V, &V) -> bool,
{ {
let mut buffer = [0u8; 2048]; 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!( println!(
"{:?} ({}): {:?} ({:?})", "{:?} ({}): {:?} ({:?})",
element, element,
@ -40,7 +40,7 @@ where
use bincode::error::EncodeError; use bincode::error::EncodeError;
let mut buffer = [0u8; 2048]; 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); let decoded = bincode::serde::decode_from_slice(&buffer, config);