Skip to content

Commit 740916f

Browse files
authored
Warnings and clippy fixes (sharksforarms#575)
1 parent 43cb41b commit 740916f

File tree

23 files changed

+89
-80
lines changed

23 files changed

+89
-80
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
with:
5252
toolchain: stable
5353

54-
- run: cargo clippy -- -D warnings
54+
- run: cargo clippy --all-targets -- -D warnings
5555
- run: cargo fmt --all -- --check
5656

5757
ensure_no_std:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ trybuild = "1.0.99"
4444
rustc-hash = "=2.1.0"
4545
env_logger = "0.11.5"
4646
assert_hex = "0.4.1"
47+
log = { version = "0.4.22" }
4748

4849
[[bench]]
4950
name = "deku"

benches/deku.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io::{Cursor, Read, Seek};
22

3-
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
3+
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
44
use deku::prelude::*;
55

66
#[cfg(feature = "bits")]
@@ -55,7 +55,7 @@ fn criterion_benchmark(c: &mut Criterion) {
5555
});
5656
c.bench_function("deku_write_byte", |b| {
5757
b.iter(|| {
58-
deku_write(black_box(&DekuBytes {
58+
deku_write(std::hint::black_box(&DekuBytes {
5959
data_00: 0x00,
6060
data_01: 0x02,
6161
data_02: 0x03,
@@ -74,7 +74,7 @@ fn criterion_benchmark(c: &mut Criterion) {
7474
#[cfg(feature = "bits")]
7575
c.bench_function("deku_write_bits", |b| {
7676
b.iter(|| {
77-
deku_write(black_box(&DekuBits {
77+
deku_write(std::hint::black_box(&DekuBits {
7878
data_01: 0x01,
7979
data_02: 0x03,
8080
data_03: 0x06,
@@ -91,7 +91,7 @@ fn criterion_benchmark(c: &mut Criterion) {
9191
)
9292
});
9393
c.bench_function("deku_write_enum", |b| {
94-
b.iter(|| deku_write(black_box(&DekuEnum::VariantA(0x02))))
94+
b.iter(|| deku_write(std::hint::black_box(&DekuEnum::VariantA(0x02))))
9595
});
9696

9797
let deku_write_vec_input = DekuVec {
@@ -107,7 +107,7 @@ fn criterion_benchmark(c: &mut Criterion) {
107107
)
108108
});
109109
c.bench_function("deku_write_vec", |b| {
110-
b.iter(|| deku_write(black_box(&deku_write_vec_input)))
110+
b.iter(|| deku_write(std::hint::black_box(&deku_write_vec_input)))
111111
});
112112
}
113113

@@ -138,38 +138,38 @@ pub fn read_all_vs_count_vs_read_exact(c: &mut Criterion) {
138138
}
139139

140140
c.bench_function("read_all_bytes", |b| {
141-
b.iter(|| AllWrapper::from_bytes(black_box((&[1; 1500], 0))))
141+
b.iter(|| AllWrapper::from_bytes(std::hint::black_box((&[1; 1500], 0))))
142142
});
143143

144144
c.bench_function("read_all", |b| {
145145
b.iter(|| {
146146
let mut cursor = Cursor::new([1u8; 1500].as_ref());
147147
let mut reader = Reader::new(&mut cursor);
148-
AllWrapper::from_reader_with_ctx(black_box(&mut reader), ())
148+
AllWrapper::from_reader_with_ctx(std::hint::black_box(&mut reader), ())
149149
})
150150
});
151151

152152
c.bench_function("count_specialize", |b| {
153153
b.iter(|| {
154154
let mut cursor = Cursor::new([1u8; 1500].as_ref());
155155
let mut reader = Reader::new(&mut cursor);
156-
CountWrapper::from_reader_with_ctx(black_box(&mut reader), ())
156+
CountWrapper::from_reader_with_ctx(std::hint::black_box(&mut reader), ())
157157
})
158158
});
159159

160160
c.bench_function("count_from_u8_specialize", |b| {
161161
b.iter(|| {
162162
let mut cursor = Cursor::new([1u8; 1500].as_ref());
163163
let mut reader = Reader::new(&mut cursor);
164-
CountWrapper::from_reader_with_ctx(black_box(&mut reader), ())
164+
CountWrapper::from_reader_with_ctx(std::hint::black_box(&mut reader), ())
165165
})
166166
});
167167

168168
c.bench_function("count_no_specialize", |b| {
169169
b.iter(|| {
170170
let mut cursor = Cursor::new([1u8; 1500].as_ref());
171171
let mut reader = Reader::new(&mut cursor);
172-
CountNonSpecialize::from_reader_with_ctx(black_box(&mut reader), ())
172+
CountNonSpecialize::from_reader_with_ctx(std::hint::black_box(&mut reader), ())
173173
})
174174
});
175175
}

examples/custom_reader_and_writer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ fn bit_flipper_read<R: std::io::Read + std::io::Seek>(
1111
bit_size: BitSize,
1212
) -> Result<u8, DekuError> {
1313
// Access to previously read fields
14-
println!("field_a = 0x{:X}", field_a);
14+
println!("field_a = 0x{field_a:X}");
1515

1616
// Size of the current field
17-
println!("bit_size: {:?}", bit_size);
17+
println!("bit_size: {bit_size:?}");
1818

1919
// read field_b, calling original func
2020
let value = u8::from_reader_with_ctx(reader, bit_size)?;
@@ -32,13 +32,13 @@ fn bit_flipper_write<W: Write + Seek>(
3232
bit_size: BitSize,
3333
) -> Result<(), DekuError> {
3434
// Access to previously written fields
35-
println!("field_a = 0x{:X}", field_a);
35+
println!("field_a = 0x{field_a:X}");
3636

3737
// value of field_b
38-
println!("field_b = 0x{:X}", field_b);
38+
println!("field_b = 0x{field_b:X}");
3939

4040
// Size of the current field
41-
println!("bit_size: {:?}", bit_size);
41+
println!("bit_size: {bit_size:?}");
4242

4343
// flip the bits on value if field_a is 0x01
4444
let value = if field_a == 0x01 { !field_b } else { field_b };

examples/many.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ fn main() {
2828
Limit::new_count(10_0000),
2929
);
3030

31-
println!("{:?}", ret);
31+
println!("{ret:?}");
3232
}

src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ let _ = value.to_writer(&mut writer, ()).unwrap();
448448
assert_eq!(buf, data);
449449
```
450450
451-
Top-Leve Example:
451+
Top-Level Example:
452452
453453
```rust
454454
# use deku::prelude::*;

src/impls/arc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ where
7373
}
7474

7575
#[cfg(test)]
76+
#[allow(clippy::too_many_arguments)]
7677
mod tests {
7778
use no_std_io::io::Cursor;
7879
use rstest::rstest;

src/impls/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ where
7373
}
7474

7575
#[cfg(test)]
76+
#[allow(clippy::too_many_arguments)]
7677
mod tests {
7778
use no_std_io::io::Cursor;
7879
use rstest::rstest;

src/impls/cstring.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,43 @@ mod tests {
6666

6767
#[rstest(input, len, expected, expected_rest,
6868
case(
69-
&[b't', b'e', b's', b't', b'\0'],
69+
b"test\0",
7070
Some(5),
7171
CString::new("test").unwrap(),
7272
&[],
7373
),
7474
case(
75-
&[b't', b'e', b's', b't', b'\0'],
75+
b"test\0",
7676
None,
7777
CString::new("test").unwrap(),
7878
&[],
7979
),
8080
case(
81-
&[b't', b'e', b's', b't', b'\0', b'a'],
81+
b"test\0a",
8282
Some(5),
8383
CString::new("test").unwrap(),
84-
&[b'a'],
84+
b"a",
8585
),
8686
case(
87-
&[b't', b'e', b's', b't', b'\0', b'a'],
87+
b"test\0a",
8888
None,
8989
CString::new("test").unwrap(),
90-
&[b'a'],
90+
b"a",
9191
),
9292
9393
#[should_panic(expected = "Parse(\"Failed to convert Vec to CString: data provided is not nul terminated\")")]
9494
case(
95-
&[b't', b'e', b's', b't'],
95+
b"test",
9696
Some(4),
9797
CString::new("test").unwrap(),
98-
&[b'a'],
98+
b"a",
9999
),
100100
101101
#[should_panic(expected = "Incomplete(NeedSize { bits: 8 })")]
102-
case(&[b't', b'e', b's', b't'], Some(5), CString::new("test").unwrap(), &[]),
102+
case(b"test", Some(5), CString::new("test").unwrap(), &[]),
103103
104104
#[should_panic(expected = "Incomplete(NeedSize { bits: 8 })")]
105-
case(&[b't', b'e', b's', b't'], None, CString::new("test").unwrap(), &[]),
105+
case(b"test", None, CString::new("test").unwrap(), &[]),
106106
)]
107107
fn test_cstring_count(
108108
input: &[u8],

src/impls/hashset.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ impl<T: DekuWriter<Ctx>, S, Ctx: Copy> DekuWriter<Ctx> for HashSet<T, S> {
211211
}
212212

213213
#[cfg(test)]
214+
#[allow(clippy::too_many_arguments)]
214215
mod tests {
215216
#[cfg(feature = "bits")]
216217
use crate::bitvec::{bits, BitSlice, Msb0};

0 commit comments

Comments
 (0)