Skip to content

Commit 7714715

Browse files
committed
Autofix of clippy::checked_conversions
1 parent 88a557c commit 7714715

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ impl QueueFile {
292292
first_pos = buf.get_u64();
293293
last_pos = buf.get_u64();
294294

295-
assert!(file_len <= i64::max_value() as u64);
296-
assert!(elem_cnt <= i32::max_value() as usize);
297-
assert!(first_pos <= i64::max_value() as u64);
298-
assert!(last_pos <= i64::max_value() as u64);
295+
assert!(i64::try_from(file_len).is_ok());
296+
assert!(i32::try_from(elem_cnt).is_ok());
297+
assert!(i64::try_from(first_pos).is_ok());
298+
assert!(i64::try_from(last_pos).is_ok());
299299
} else {
300300
header_len = 16;
301301

@@ -304,10 +304,10 @@ impl QueueFile {
304304
first_pos = u64::from(buf.get_u32());
305305
last_pos = u64::from(buf.get_u32());
306306

307-
assert!(file_len <= i32::max_value() as u64);
308-
assert!(elem_cnt <= i32::max_value() as usize);
309-
assert!(first_pos <= i32::max_value() as u64);
310-
assert!(last_pos <= i32::max_value() as u64);
307+
assert!(i32::try_from(file_len).is_ok());
308+
assert!(i32::try_from(elem_cnt).is_ok());
309+
assert!(i32::try_from(first_pos).is_ok());
310+
assert!(i32::try_from(last_pos).is_ok());
311311
}
312312

313313
let real_file_len = file.metadata()?.len();
@@ -515,7 +515,7 @@ impl QueueFile {
515515
for elem in elems {
516516
let elem = elem.as_ref();
517517
let len = elem.len();
518-
ensure!(len <= i32::max_value() as usize, ElementTooBigSnafu {});
518+
ensure!(i32::try_from(len).is_ok(), ElementTooBigSnafu {});
519519

520520
if first_added.is_none() {
521521
first_added = Some(Element::new(pos, len));
@@ -779,21 +779,21 @@ impl QueueFile {
779779

780780
// Never allow write values that will render file unreadable by Java library.
781781
if self.versioned {
782-
assert!(file_len <= i64::max_value() as u64);
783-
assert!(elem_cnt <= i32::max_value() as usize);
784-
assert!(first_pos <= i64::max_value() as u64);
785-
assert!(last_pos <= i64::max_value() as u64);
782+
assert!(i64::try_from(file_len).is_ok());
783+
assert!(i32::try_from(elem_cnt).is_ok());
784+
assert!(i64::try_from(first_pos).is_ok());
785+
assert!(i64::try_from(last_pos).is_ok());
786786

787787
header_buf.put_u32(Self::VERSIONED_HEADER);
788788
header_buf.put_u64(file_len);
789789
header_buf.put_i32(elem_cnt as i32);
790790
header_buf.put_u64(first_pos);
791791
header_buf.put_u64(last_pos);
792792
} else {
793-
assert!(file_len <= i32::max_value() as u64);
794-
assert!(elem_cnt <= i32::max_value() as usize);
795-
assert!(first_pos <= i32::max_value() as u64);
796-
assert!(last_pos <= i32::max_value() as u64);
793+
assert!(i32::try_from(file_len).is_ok());
794+
assert!(i32::try_from(elem_cnt).is_ok());
795+
assert!(i32::try_from(first_pos).is_ok());
796+
assert!(i32::try_from(last_pos).is_ok());
797797

798798
header_buf.put_i32(file_len as i32);
799799
header_buf.put_i32(elem_cnt as i32);
@@ -1080,7 +1080,7 @@ impl QueueFileInner {
10801080
debug_assert!(read_pos < self.file_len);
10811081
debug_assert!(write_pos <= self.file_len);
10821082
debug_assert!(count < self.file_len);
1083-
debug_assert!(count <= i64::max_value() as u64);
1083+
debug_assert!(i64::try_from(count).is_ok());
10841084

10851085
let mut bytes_left = count as i64;
10861086

@@ -1133,12 +1133,12 @@ impl Element {
11331133

11341134
fn new(pos: u64, len: usize) -> Self {
11351135
assert!(
1136-
pos <= i64::max_value() as u64,
1136+
i64::try_from(pos).is_ok(),
11371137
"element position must be less than {}",
11381138
i64::max_value()
11391139
);
11401140
assert!(
1141-
len <= i32::max_value() as usize,
1141+
i32::try_from(len).is_ok(),
11421142
"element length must be less than {}",
11431143
i32::max_value()
11441144
);

tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum Action {
5454
}
5555

5656
impl quickcheck::Arbitrary for Action {
57-
fn arbitrary(mut g: &mut quickcheck::Gen) -> Self {
57+
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
5858
let kind = u32::arbitrary(g);
5959

6060
match kind % 3 {
@@ -301,7 +301,7 @@ fn iter_nth() {
301301
assert_eq!(qf.iter().nth(2), Some(c.clone().into_boxed_slice()));
302302
assert_eq!(qf.iter().skip(0).nth(1), Some(b.clone().into_boxed_slice()));
303303
assert_eq!(qf.iter().skip(0).nth(2), Some(c.clone().into_boxed_slice()));
304-
assert_eq!(qf.iter().skip(1).next(), Some(b.into_boxed_slice()));
304+
assert_eq!(qf.iter().nth(1), Some(b.into_boxed_slice()));
305305
assert_eq!(qf.iter().skip(1).nth(1), Some(c.into_boxed_slice()));
306306
assert_eq!(qf.iter().nth(3), None);
307307
assert_eq!(qf.iter().nth(123), None);

0 commit comments

Comments
 (0)