Skip to content

Commit 0d04650

Browse files
committed
run clippy --fix
1 parent 33e7bea commit 0d04650

14 files changed

+80
-96
lines changed

lain/src/buffer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
let size = self
2121
.iter()
2222
.map(SerializedSize::serialized_size)
23-
.fold(0, |sum, i| sum + i);
23+
.sum::<usize>();
2424

2525
size
2626
}
@@ -167,23 +167,23 @@ impl BinarySerialize for bool {
167167
impl BinarySerialize for i8 {
168168
#[inline(always)]
169169
fn binary_serialize<W: Write, E: ByteOrder>(&self, buffer: &mut W) -> usize {
170-
buffer.write_i8(*self as i8).unwrap();
170+
buffer.write_i8(*self).unwrap();
171171
std::mem::size_of::<i8>()
172172
}
173173
}
174174

175175
impl BinarySerialize for u8 {
176176
#[inline(always)]
177177
fn binary_serialize<W: Write, E: ByteOrder>(&self, buffer: &mut W) -> usize {
178-
buffer.write_u8(*self as u8).unwrap();
178+
buffer.write_u8(*self).unwrap();
179179
std::mem::size_of::<u8>()
180180
}
181181
}
182182

183183
impl BinarySerialize for [u8] {
184184
#[inline(always)]
185185
fn binary_serialize<W: Write, E: ByteOrder>(&self, buffer: &mut W) -> usize {
186-
buffer.write(&self).unwrap()
186+
buffer.write(self).unwrap()
187187
}
188188
}
189189

lain/src/dangerous_numbers.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::rand::Rng;
22
use crate::traits::*;
33

4-
static DANGEROUS_NUMBERS_U8: &'static [u8] = &[
4+
static DANGEROUS_NUMBERS_U8: &[u8] = &[
55
std::u8::MIN, // 0x00
66
std::u8::MAX, // 0xff
77
std::i8::MAX as u8, // 0x7f
88
(std::i8::MAX as u8) + 1, // 0x80
99
];
1010

11-
static DANGEROUS_NUMBERS_U16: &'static [u16] = &[
11+
static DANGEROUS_NUMBERS_U16: &[u16] = &[
1212
// big-endian variants
1313
std::u16::MIN, // 0x0000
1414
std::u16::MAX, // 0xffff
@@ -19,7 +19,7 @@ static DANGEROUS_NUMBERS_U16: &'static [u16] = &[
1919
0x0080,
2020
];
2121

22-
static DANGEROUS_NUMBERS_U32: &'static [u32] = &[
22+
static DANGEROUS_NUMBERS_U32: &[u32] = &[
2323
// big-endian variants
2424
std::u32::MIN,
2525
std::u32::MAX,
@@ -30,7 +30,7 @@ static DANGEROUS_NUMBERS_U32: &'static [u32] = &[
3030
0x0000_0080,
3131
];
3232

33-
static DANGEROUS_NUMBERS_U64: &'static [u64] = &[
33+
static DANGEROUS_NUMBERS_U64: &[u64] = &[
3434
// big-endian variants
3535
std::u64::MIN,
3636
std::u64::MAX,
@@ -41,7 +41,7 @@ static DANGEROUS_NUMBERS_U64: &'static [u64] = &[
4141
0x0000_0000_0000_0080,
4242
];
4343

44-
static DANGEROUS_NUMBERS_F32: &'static [f32] = &[
44+
static DANGEROUS_NUMBERS_F32: &[f32] = &[
4545
std::f32::INFINITY,
4646
std::f32::MAX,
4747
std::f32::MIN,
@@ -50,7 +50,7 @@ static DANGEROUS_NUMBERS_F32: &'static [f32] = &[
5050
std::f32::NEG_INFINITY,
5151
];
5252

53-
static DANGEROUS_NUMBERS_F64: &'static [f64] = &[
53+
static DANGEROUS_NUMBERS_F64: &[f64] = &[
5454
std::f64::INFINITY,
5555
std::f64::MAX,
5656
std::f64::MIN,

lain/src/driver.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<T: 'static + Send + Sync> FuzzerDriver<T> {
9999
}
100100

101101
pub fn global_context(&self) -> Option<Arc<RwLock<T>>> {
102-
self.global_context.as_ref().map(|c| Arc::clone(c))
102+
self.global_context.as_ref().map(Arc::clone)
103103
}
104104

105105
/// Sets the root seed
@@ -243,8 +243,7 @@ pub fn start_fuzzer<F: 'static, C: 'static, T: 'static + Send + Sync>(
243243

244244
mutator.random_flags();
245245

246-
if let Err(_) =
247-
(callback)(&mut mutator, &mut context, thread_driver.global_context())
246+
if (callback)(&mut mutator, &mut context, thread_driver.global_context()).is_err()
248247
{
249248
thread_driver
250249
.num_failed_iterations

lain/src/mutatable.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn grow_vec<T: NewFuzzed + SerializedSize, R: Rng>(
5454
};
5555

5656
// If we were given a size constraint, we need to respect it
57-
if let Some(max_size) = max_size.clone() {
57+
if let Some(max_size) = max_size {
5858
num_elements = min(num_elements, max_size / T::max_default_object_size());
5959
}
6060

@@ -327,7 +327,7 @@ where
327327
});
328328

329329
// Check if we can even mutate this item
330-
if let Some(max_size) = constraints.as_ref().map(|c| c.max_size).flatten().clone() {
330+
if let Some(max_size) = constraints.as_ref().and_then(|c| c.max_size) {
331331
if T::min_nonzero_elements_size() < max_size || T::max_default_object_size() > max_size
332332
{
333333
return;
@@ -367,7 +367,7 @@ where
367367
});
368368

369369
// Check if we can even mutate this item
370-
if let Some(max_size) = constraints.as_ref().map(|c| c.max_size).flatten().clone() {
370+
if let Some(max_size) = constraints.as_ref().and_then(|c| c.max_size) {
371371
if T::min_nonzero_elements_size() < max_size {
372372
return;
373373
}

lain/src/mutator.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,11 @@ struct MutatorFlags {
3838
/// Represents the state of the current corpus item being fuzzed.
3939
#[derive(Debug, Clone)]
4040
#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
41+
#[derive(Default)]
4142
pub struct CorpusFuzzingState {
4243
fields_fuzzed: usize,
4344
}
4445

45-
impl Default for CorpusFuzzingState {
46-
fn default() -> Self {
47-
CorpusFuzzingState { fields_fuzzed: 0 }
48-
}
49-
}
5046

5147
impl CorpusFuzzingState {
5248
pub fn reset(&mut self) {
@@ -104,7 +100,7 @@ impl<R: Rng> Mutator<R> {
104100
+ std::fmt::Debug,
105101
{
106102
// dirty but needs to be done so we can call self.gen_chance_ignore_flags
107-
if let Some(count) = self.flags.field_count.clone() {
103+
if let Some(count) = self.flags.field_count {
108104
if self.corpus_state.fields_fuzzed == count {
109105
return;
110106
}
@@ -258,9 +254,9 @@ impl<R: Rng> Mutator<R> {
258254
let zero = B1::from(0u8).unwrap();
259255

260256
let mut slices = [
261-
((zero.clone(), zero.clone()), 0u8),
262-
((zero.clone(), zero.clone()), 0u8),
263-
((zero.clone(), zero.clone()), 0u8),
257+
((zero, zero), 0u8),
258+
((zero, zero), 0u8),
259+
((zero, zero), 0u8),
264260
];
265261

266262
for i in 0..3 {
@@ -307,7 +303,6 @@ impl<R: Rng> Mutator<R> {
307303
pub fn should_early_bail_mutation(&self) -> bool {
308304
self.flags
309305
.field_count
310-
.clone()
311306
.map(|count| count >= self.corpus_state.fields_fuzzed)
312307
.unwrap_or(false)
313308
}

lain/src/new_fuzzed.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ where
7272

7373
// if no min/max were supplied, we'll take a conservative approach of 64 elements
7474
match constraints {
75-
Some(ref constraints) => {
75+
Some(constraints) => {
7676
min = constraints.min.unwrap_or(0);
7777
max = constraints.max.unwrap_or(MAX_NUM_ELEMENTS);
7878

@@ -127,7 +127,7 @@ where
127127
T::new_fuzzed(
128128
mutator,
129129
Some(
130-
&Constraints::new()
130+
Constraints::new()
131131
.max_size(max_size - used_size)
132132
.set_base_size_accounted_for(),
133133
),
@@ -239,7 +239,7 @@ where
239239
T::new_fuzzed(
240240
mutator,
241241
Some(
242-
&Constraints::new()
242+
Constraints::new()
243243
.max_size(max_size - used_size)
244244
.set_base_size_accounted_for(),
245245
),
@@ -267,7 +267,7 @@ where
267267
T::new_fuzzed(
268268
mutator,
269269
Some(
270-
&Constraints::new()
270+
Constraints::new()
271271
.max_size(max_size - used_size)
272272
.set_base_size_accounted_for(),
273273
),
@@ -380,7 +380,7 @@ impl NewFuzzed for Utf8String {
380380

381381
// if no min/max were supplied, we'll take a conservative approach
382382
match constraints {
383-
Some(ref constraints) => {
383+
Some(constraints) => {
384384
min = constraints.min.unwrap_or(0);
385385
max = constraints.max.unwrap_or(256);
386386
weight = constraints.weighted;
@@ -444,7 +444,7 @@ impl NewFuzzed for AsciiString {
444444

445445
// if no min/max were supplied, we'll take a conservative approach
446446
match constraints {
447-
Some(ref constraints) => {
447+
Some(constraints) => {
448448
min = constraints.min.unwrap_or(0);
449449
max = constraints.max.unwrap_or(256);
450450
weight = constraints.weighted;
@@ -617,7 +617,7 @@ impl NewFuzzed for AsciiChar {
617617

618618
// if no min/max were supplied, we'll take a conservative approach of 64 elements
619619
match constraints {
620-
Some(ref constraints) => {
620+
Some(constraints) => {
621621
min = constraints.min.unwrap_or(0);
622622
max = constraints.max.unwrap_or(0x80);
623623
weight = constraints.weighted;

lain/src/types.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct Utf8String {
8181
impl Utf8String {
8282
pub fn new(s: &str) -> Self {
8383
Utf8String {
84-
inner: s.chars().map(|c| Utf8Char(c)).collect(),
84+
inner: s.chars().map(Utf8Char).collect(),
8585
}
8686
}
8787
}
@@ -95,7 +95,7 @@ pub struct AsciiString {
9595
impl AsciiString {
9696
pub fn new(s: &str) -> Self {
9797
AsciiString {
98-
inner: s.chars().map(|c| AsciiChar(c)).collect(),
98+
inner: s.chars().map(AsciiChar).collect(),
9999
}
100100
}
101101
}
@@ -134,29 +134,29 @@ impl<T: Bounded + Debug> Constraints<T> {
134134
}
135135
}
136136

137-
pub fn min<'a>(&'a mut self, min: T) -> &'a mut Constraints<T> {
137+
pub fn min(&mut self, min: T) -> &mut Constraints<T> {
138138
self.min = Some(min);
139139
self
140140
}
141141

142-
pub fn max<'a>(&'a mut self, max: T) -> &'a mut Constraints<T> {
142+
pub fn max(&mut self, max: T) -> &mut Constraints<T> {
143143
self.max = Some(max);
144144
self
145145
}
146146

147-
pub fn weighted<'a>(&'a mut self, weighted: Weighted) -> &'a mut Constraints<T> {
147+
pub fn weighted(&mut self, weighted: Weighted) -> &mut Constraints<T> {
148148
self.weighted = weighted;
149149
self
150150
}
151151

152-
pub fn max_size<'a>(&'a mut self, max_size: usize) -> &'a mut Constraints<T> {
152+
pub fn max_size(&mut self, max_size: usize) -> &mut Constraints<T> {
153153
self.max_size = Some(max_size);
154154
self
155155
}
156156

157-
pub fn account_for_base_object_size<'a, U: crate::traits::SerializedSize>(
158-
&'a mut self,
159-
) -> &'a mut Constraints<T> {
157+
pub fn account_for_base_object_size<U: crate::traits::SerializedSize>(
158+
&mut self,
159+
) -> &mut Constraints<T> {
160160
if !self.base_object_size_accounted_for {
161161
if let Some(ref mut max_size) = self.max_size {
162162
if U::max_default_object_size() > *max_size {
@@ -172,22 +172,19 @@ impl<T: Bounded + Debug> Constraints<T> {
172172
self
173173
}
174174

175-
pub fn set_base_size_accounted_for<'a>(&'a mut self) -> &'a mut Constraints<T> {
175+
pub fn set_base_size_accounted_for(&mut self) -> &mut Constraints<T> {
176176
self.base_object_size_accounted_for = true;
177177
self
178178
}
179179
}
180180

181181
/// Which direction to weigh ranges towards (min bound, upper bound, or none).
182182
#[derive(Debug, PartialEq, Clone, Copy)]
183+
#[derive(Default)]
183184
pub enum Weighted {
185+
#[default]
184186
None,
185187
Min,
186188
Max,
187189
}
188190

189-
impl Default for Weighted {
190-
fn default() -> Self {
191-
Weighted::None
192-
}
193-
}

lain_derive/src/internals/ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn fields_from_ast<'a>(cx: &Ctxt, fields: &'a Punctuated<syn::Field, Token![,]>)
138138

139139
let bits_in_type: usize;
140140

141-
let bitfield_type = field.attrs.bitfield_type().unwrap_or(&field.ty);
141+
let bitfield_type = field.attrs.bitfield_type().unwrap_or(field.ty);
142142
if is_primitive_type(bitfield_type, "u8") {
143143
bits_in_type = 8
144144
} else if is_primitive_type(bitfield_type, "u16") {
@@ -148,22 +148,22 @@ fn fields_from_ast<'a>(cx: &Ctxt, fields: &'a Punctuated<syn::Field, Token![,]>)
148148
} else if is_primitive_type(bitfield_type, "u64") {
149149
bits_in_type = 64
150150
} else {
151-
cx.error_spanned_by(&field.ty, "Unsupported bitfield datatype. Did you forget to specify `#[lain(bitfield_type = \"...\")]`?");
151+
cx.error_spanned_by(field.ty, "Unsupported bitfield datatype. Did you forget to specify `#[lain(bitfield_type = \"...\")]`?");
152152
return field;
153153
}
154154

155155
if bitfield_bits == bits_in_type {
156156
bitfield_bits = 0;
157157
} else if bitfield_bits > bits_in_type {
158-
cx.error_spanned_by(&field.ty, "Number of bits specified overflows bitfield type");
158+
cx.error_spanned_by(field.ty, "Number of bits specified overflows bitfield type");
159159
}
160160
}
161161

162162
field
163163
})
164164
.collect();
165165

166-
if fields.len() == 0 {
166+
if fields.is_empty() {
167167
return fields;
168168
}
169169

0 commit comments

Comments
 (0)