Skip to content

Commit d0c0c38

Browse files
committed
clippy
1 parent 7ff581d commit d0c0c38

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

serde/src/de/impls.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,8 @@ macro_rules! int_to_int {
249249
where
250250
E: Error,
251251
{
252-
if Self::Value::MIN as i64 <= v as i64 && v as i64 <= Self::Value::MAX as i64 {
253-
Ok(v as Self::Value)
254-
} else {
255-
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
256-
}
252+
Self::Value::try_from(v as i64)
253+
.map_err(|_| Error::invalid_value(Unexpected::Signed(v as i64), &self))
257254
}
258255
};
259256

@@ -262,8 +259,8 @@ macro_rules! int_to_int {
262259
where
263260
E: Error,
264261
{
265-
if $primitive::MIN as i64 <= v as i64 && v as i64 <= $primitive::MAX as i64 {
266-
if let Some(nonzero) = Self::Value::new(v as $primitive) {
262+
if let Ok(v) = $primitive::try_from(v as i64) {
263+
if let Some(nonzero) = Self::Value::new(v) {
267264
return Ok(nonzero);
268265
}
269266
}
@@ -294,11 +291,13 @@ macro_rules! int_to_uint {
294291
where
295292
E: Error,
296293
{
297-
if 0 <= v && v as u64 <= Self::Value::MAX as u64 {
298-
Ok(v as Self::Value)
299-
} else {
300-
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
294+
if 0 <= v {
295+
#[allow(irrefutable_let_patterns)]
296+
if let Ok(v) = Self::Value::try_from(v as u64) {
297+
return Ok(v as Self::Value);
298+
}
301299
}
300+
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
302301
}
303302
};
304303

@@ -307,9 +306,12 @@ macro_rules! int_to_uint {
307306
where
308307
E: Error,
309308
{
310-
if 0 < v && v as u64 <= $primitive::MAX as u64 {
311-
if let Some(nonzero) = Self::Value::new(v as $primitive) {
312-
return Ok(nonzero);
309+
if 0 < v {
310+
#[allow(irrefutable_let_patterns)]
311+
if let Ok(v) = $primitive::try_from(v as u64) {
312+
if let Some(nonzero) = Self::Value::new(v) {
313+
return Ok(nonzero);
314+
}
313315
}
314316
}
315317
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
@@ -339,11 +341,8 @@ macro_rules! uint_to_self {
339341
where
340342
E: Error,
341343
{
342-
if v as u64 <= Self::Value::MAX as u64 {
343-
Ok(v as Self::Value)
344-
} else {
345-
Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
346-
}
344+
Self::Value::try_from(v as u64)
345+
.map_err(|_| Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
347346
}
348347
};
349348

@@ -352,8 +351,8 @@ macro_rules! uint_to_self {
352351
where
353352
E: Error,
354353
{
355-
if v as u64 <= $primitive::MAX as u64 {
356-
if let Some(nonzero) = Self::Value::new(v as $primitive) {
354+
if let Ok(v) = $primitive::try_from(v as u64) {
355+
if let Some(nonzero) = Self::Value::new(v) {
357356
return Ok(nonzero);
358357
}
359358
}
@@ -366,7 +365,7 @@ macro_rules! uint_to_self {
366365
where
367366
E: Error,
368367
{
369-
if v as u64 <= $primitive::MAX as u64 {
368+
if let Ok(v) = $primitive::try_from(v as u64) {
370369
Ok(Saturating(v as $primitive))
371370
} else {
372371
Ok(Saturating($primitive::MAX))

serde/src/de/size_hint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(any(feature = "std", feature = "alloc"))]
12
use crate::lib::*;
23

34
pub fn from_bounds<I>(iter: &I) -> Option<usize>

serde/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ mod lib {
175175
}
176176

177177
pub use self::core::{f32, f64};
178-
pub use self::core::{i16, i32, i64, i8, isize};
179178
pub use self::core::{iter, num, ptr, str};
180-
pub use self::core::{u16, u32, u64, u8, usize};
181179

182180
#[cfg(any(feature = "std", feature = "alloc"))]
183181
pub use self::core::{cmp, mem, slice};

0 commit comments

Comments
 (0)