Skip to content

Commit d513996

Browse files
authored
Merge pull request #1188 from spacejam/tyler_clippy
Run clippy on tests and other new parts of the codebase
2 parents 43efef5 + 3dfa254 commit d513996

File tree

14 files changed

+78
-102
lines changed

14 files changed

+78
-102
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ crossbeam-utils = "0.8.0"
4646
fxhash = "0.2.1"
4747
libc = "0.2.79"
4848
zstd = { version = "0.5.3", optional = true }
49-
crc32fast = "1.2.0"
49+
crc32fast = "1.2.1"
5050
log = "0.4.11"
5151
parking_lot = "0.11.0"
5252
color-backtrace = { version = "0.4.2", optional = true }

examples/playground.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ fn basic() -> Result<()> {
1313

1414
// set and get
1515
db.insert(k.clone(), v1.clone())?;
16-
assert_eq!(db.get(&k).unwrap().unwrap(), (v1.clone()));
16+
assert_eq!(db.get(&k).unwrap().unwrap(), (v1));
1717

1818
// compare and swap
19-
match db.compare_and_swap(k.clone(), Some(&v1.clone()), Some(v2.clone()))? {
19+
match db.compare_and_swap(k.clone(), Some(&v1), Some(v2.clone()))? {
2020
Ok(()) => println!("it worked!"),
2121
Err(sled::CompareAndSwapError { current: cur, proposed: _ }) => {
2222
println!("the actual current value is {:?}", cur)
@@ -26,8 +26,8 @@ fn basic() -> Result<()> {
2626
// scan forward
2727
let mut iter = db.range(k.as_slice()..);
2828
let (k1, v1) = iter.next().unwrap().unwrap();
29-
assert_eq!(v1, v2.clone());
30-
assert_eq!(k1, k.clone());
29+
assert_eq!(v1, v2);
30+
assert_eq!(k1, k);
3131
assert_eq!(iter.next(), None);
3232

3333
// deletion
@@ -43,7 +43,7 @@ fn merge_operator() -> Result<()> {
4343
merged_bytes: &[u8], // the new bytes being merged in
4444
) -> Option<Vec<u8>> {
4545
// set the new value, return None to delete
46-
let mut ret = old_value.map_or_else(|| vec![], |ov| ov.to_vec());
46+
let mut ret = old_value.map_or_else(Vec::new, |ov| ov.to_vec());
4747

4848
ret.extend_from_slice(merged_bytes);
4949

src/binary_search.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ use std::cmp::Ordering::{Equal, Greater, Less};
22

33
use crate::{fastcmp, IVec};
44

5-
pub(crate) fn binary_search_lub<'a>(
6-
key: &[u8],
7-
s: &'a [IVec],
8-
) -> Option<usize> {
5+
pub(crate) fn binary_search_lub(key: &[u8], s: &[IVec]) -> Option<usize> {
96
match binary_search(key, s) {
107
Ok(i) => Some(i),
118
Err(i) if i == 0 => None,
129
Err(i) => Some(i - 1),
1310
}
1411
}
1512

16-
pub fn binary_search<'a>(key: &[u8], s: &'a [IVec]) -> Result<usize, usize> {
13+
pub fn binary_search(key: &[u8], s: &[IVec]) -> Result<usize, usize> {
1714
let mut size = s.len();
1815
if size == 0 || *key < *s[0] {
1916
return Err(0);
@@ -35,7 +32,11 @@ pub fn binary_search<'a>(key: &[u8], s: &'a [IVec]) -> Result<usize, usize> {
3532
#[allow(unsafe_code)]
3633
let l = unsafe { s.get_unchecked(base).as_ref() };
3734
let cmp = fastcmp(l, key);
38-
if cmp == Equal { Ok(base) } else { Err(base + (cmp == Less) as usize) }
35+
if cmp == Equal {
36+
Ok(base)
37+
} else {
38+
Err(base + (cmp == Less) as usize)
39+
}
3940
}
4041

4142
#[test]

src/ivec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,20 @@ fn ivec_as_mut_identity() {
376376
mod qc {
377377
use super::IVec;
378378

379-
fn prop_identity(ivec: IVec) -> bool {
379+
fn prop_identity(ivec: &IVec) -> bool {
380380
let mut iv2 = ivec.clone();
381381

382382
if iv2 != ivec {
383383
println!("expected clone to equal original");
384384
return false;
385385
}
386386

387-
if &*ivec != &mut *iv2 {
387+
if *ivec != *iv2 {
388388
println!("expected AsMut to equal original");
389389
return false;
390390
}
391391

392-
if &*ivec != iv2.as_mut() {
392+
if *ivec != iv2.as_mut() {
393393
println!("expected AsMut to equal original");
394394
return false;
395395
}
@@ -400,7 +400,7 @@ mod qc {
400400
quickcheck::quickcheck! {
401401
#[cfg_attr(miri, ignore)]
402402
fn bool(item: IVec) -> bool {
403-
prop_identity(item)
403+
prop_identity(&item)
404404
}
405405
}
406406
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
// clippy::missing_const_for_fn,
130130
// clippy::missing_docs_in_private_items,
131131
clippy::module_name_repetitions,
132-
clippy::multiple_crate_versions,
133132
clippy::multiple_inherent_impl,
134133
clippy::mut_mut,
135134
clippy::needless_borrow,
@@ -155,6 +154,7 @@
155154
// clippy::wildcard_enum_match_arm,
156155
clippy::wrong_pub_self_convention,
157156
)]
157+
#![warn(clippy::multiple_crate_versions)]
158158
#![allow(clippy::mem_replace_with_default)] // Not using std::mem::take() due to MSRV of 1.37 (intro'd in 1.40)
159159
#![allow(clippy::match_like_matches_macro)] // Not using std::matches! due to MSRV of 1.37 (intro'd in 1.42)
160160

src/pagecache/iterator.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ fn scan_segment_headers_and_tail(
334334
);
335335

336336
// scatter
337-
let header_promises_res: Result<
338-
Vec<OneShot<Option<(LogOffset, SegmentHeader)>>>,
339-
> = (0..segments)
337+
let header_promises_res: Result<Vec<_>> = (0..segments)
340338
.map({
341339
// let config = config.clone();
342340
move |idx| {

src/serialization.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,91 +1020,91 @@ mod qc {
10201020
}
10211021
}
10221022

1023-
fn prop_serialize<T>(item: T) -> bool
1023+
fn prop_serialize<T>(item: &T) -> bool
10241024
where
10251025
T: Serialize + PartialEq + Clone + std::fmt::Debug,
10261026
{
1027-
let mut buf = vec![0; item.serialized_size() as usize];
1027+
let mut buf = vec![0; usize::try_from(item.serialized_size()).unwrap()];
10281028
let buf_ref = &mut buf.as_mut_slice();
10291029
item.serialize_into(buf_ref);
10301030
assert_eq!(
10311031
buf_ref.len(),
10321032
0,
10331033
"round-trip failed to consume produced bytes"
10341034
);
1035-
assert_eq!(buf.len(), item.serialized_size() as usize,);
1035+
assert_eq!(buf.len() as u64, item.serialized_size());
10361036
let deserialized = T::deserialize(&mut buf.as_slice()).unwrap();
1037-
if item != deserialized {
1037+
if *item == deserialized {
1038+
true
1039+
} else {
10381040
eprintln!(
10391041
"round-trip serialization failed. original:\n\n{:?}\n\n \
10401042
deserialized(serialized(original)):\n\n{:?}",
10411043
item, deserialized
10421044
);
10431045
false
1044-
} else {
1045-
true
10461046
}
10471047
}
10481048

10491049
quickcheck::quickcheck! {
10501050
#[cfg_attr(miri, ignore)]
10511051
fn bool(item: bool) -> bool {
1052-
prop_serialize(item)
1052+
prop_serialize(&item)
10531053
}
10541054

10551055
#[cfg_attr(miri, ignore)]
10561056
fn u8(item: u8) -> bool {
1057-
prop_serialize(item)
1057+
prop_serialize(&item)
10581058
}
10591059

10601060
#[cfg_attr(miri, ignore)]
10611061
fn i64(item: SpreadI64) -> bool {
1062-
prop_serialize(item.0)
1062+
prop_serialize(&item.0)
10631063
}
10641064

10651065
#[cfg_attr(miri, ignore)]
10661066
fn u64(item: SpreadU64) -> bool {
1067-
prop_serialize(item.0)
1067+
prop_serialize(&item.0)
10681068
}
10691069

10701070
#[cfg_attr(miri, ignore)]
10711071
fn disk_ptr(item: DiskPtr) -> bool {
1072-
prop_serialize(item)
1072+
prop_serialize(&item)
10731073
}
10741074

10751075
#[cfg_attr(miri, ignore)]
10761076
fn page_state(item: PageState) -> bool {
1077-
prop_serialize(item)
1077+
prop_serialize(&item)
10781078
}
10791079

10801080
#[cfg_attr(miri, ignore)]
10811081
fn meta(item: Meta) -> bool {
1082-
prop_serialize(item)
1082+
prop_serialize(&item)
10831083
}
10841084

10851085
#[cfg_attr(miri, ignore)]
10861086
fn snapshot(item: Snapshot) -> bool {
1087-
prop_serialize(item)
1087+
prop_serialize(&item)
10881088
}
10891089

10901090
#[cfg_attr(miri, ignore)]
10911091
fn node(item: Node) -> bool {
1092-
prop_serialize(item)
1092+
prop_serialize(&item)
10931093
}
10941094

10951095
#[cfg_attr(miri, ignore)]
10961096
fn data(item: Data) -> bool {
1097-
prop_serialize(item)
1097+
prop_serialize(&item)
10981098
}
10991099

11001100
#[cfg_attr(miri, ignore)]
11011101
fn link(item: Link) -> bool {
1102-
prop_serialize(item)
1102+
prop_serialize(&item)
11031103
}
11041104

11051105
#[cfg_attr(miri, ignore)]
11061106
fn msg_header(item: MessageHeader) -> bool {
1107-
prop_serialize(item)
1107+
prop_serialize(&item)
11081108
}
11091109
}
11101110

@@ -1122,6 +1122,6 @@ mod qc {
11221122
data: Data::Index(Index::default()),
11231123
};
11241124

1125-
prop_serialize(node);
1125+
prop_serialize(&node);
11261126
}
11271127
}

src/subscriber.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,28 +305,19 @@ fn basic_subscriber() {
305305

306306
let k2: IVec = vec![].into();
307307
let r2 = subs.reserve(&k2).unwrap();
308-
r2.complete(&Event::Insert {
309-
key: k2.clone(),
310-
value: IVec::from(k2.clone()),
311-
});
308+
r2.complete(&Event::Insert { key: k2.clone(), value: k2.clone() });
312309

313310
let k3: IVec = vec![0].into();
314311
let r3 = subs.reserve(&k3).unwrap();
315-
r3.complete(&Event::Insert {
316-
key: k3.clone(),
317-
value: IVec::from(k3.clone()),
318-
});
312+
r3.complete(&Event::Insert { key: k3.clone(), value: k3.clone() });
319313

320314
let k4: IVec = vec![0, 1].into();
321315
let r4 = subs.reserve(&k4).unwrap();
322316
r4.complete(&Event::Remove { key: k4.clone() });
323317

324318
let k5: IVec = vec![0, 1, 2].into();
325319
let r5 = subs.reserve(&k5).unwrap();
326-
r5.complete(&Event::Insert {
327-
key: k5.clone(),
328-
value: IVec::from(k5.clone()),
329-
});
320+
r5.complete(&Event::Insert { key: k5.clone(), value: k5.clone() });
330321

331322
let k6: IVec = vec![1, 1, 2].into();
332323
let r6 = subs.reserve(&k6).unwrap();
@@ -338,10 +329,7 @@ fn basic_subscriber() {
338329

339330
let k8: IVec = vec![1, 2, 2].into();
340331
let r8 = subs.reserve(&k8).unwrap();
341-
r8.complete(&Event::Insert {
342-
key: k8.clone(),
343-
value: IVec::from(k8.clone()),
344-
});
332+
r8.complete(&Event::Insert { key: k8.clone(), value: k8.clone() });
345333

346334
assert_eq!(s1.next().unwrap().key(), &*k2);
347335
assert_eq!(s1.next().unwrap().key(), &*k3);

src/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,12 +1517,12 @@ impl Tree {
15171517
Ok(())
15181518
}
15191519

1520-
fn root_hoist<'g>(
1520+
fn root_hoist(
15211521
&self,
15221522
from: PageId,
15231523
to: PageId,
15241524
at: IVec,
1525-
guard: &'g Guard,
1525+
guard: &Guard,
15261526
) -> Result<bool> {
15271527
M.tree_root_split_attempt();
15281528
// hoist new root, pointing to lhs & rhs

tests/test_crash_recovery.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn verify(tree: &sled::Tree) -> (u32, u32) {
7575
let mut lowest = 0;
7676
for res in iter {
7777
let (_k, v) = res.unwrap();
78-
if &v[..4] == &highest_vec[..4] {
78+
if v[..4] == highest_vec[..4] {
7979
contiguous += 1;
8080
} else {
8181
let expected = if highest == 0 {
@@ -238,12 +238,9 @@ fn run() {
238238
.path(RECOVERY_DIR.to_string())
239239
.segment_size(SEGMENT_SIZE);
240240

241-
match thread::spawn(|| run_inner(config)).join() {
242-
Err(e) => {
243-
println!("worker thread failed: {:?}", e);
244-
std::process::exit(15);
245-
}
246-
_ => {}
241+
if let Err(e) = thread::spawn(|| run_inner(config)).join() {
242+
println!("worker thread failed: {:?}", e);
243+
std::process::exit(15);
247244
}
248245
}
249246

@@ -270,12 +267,9 @@ fn run_batches() {
270267
spawn_killah();
271268
}
272269

273-
match t1.join().and_then(|_| t2.join()) {
274-
Err(e) => {
275-
println!("worker thread failed: {:?}", e);
276-
std::process::exit(15);
277-
}
278-
_ => {}
270+
if let Err(e) = t1.join().and_then(|_| t2.join()) {
271+
println!("worker thread failed: {:?}", e);
272+
std::process::exit(15);
279273
}
280274
}
281275

@@ -288,10 +282,9 @@ fn run_child_process(test_name: &str) -> Child {
288282
.env(TEST_ENV_VAR, test_name)
289283
.env("SLED_CRASH_CHANCE", CRASH_CHANCE.to_string())
290284
.spawn()
291-
.expect(&format!(
292-
"could not spawn child process for {} test",
293-
test_name
294-
))
285+
.unwrap_or_else(|_| {
286+
panic!("could not spawn child process for {} test", test_name)
287+
})
295288
}
296289

297290
fn handle_child_exit_status(dir: &str, status: ExitStatus) {
@@ -516,8 +509,6 @@ fn run_iter() {
516509
let deleter = thread::Builder::new()
517510
.name("deleter".into())
518511
.spawn({
519-
let t = t.clone();
520-
let barrier = barrier.clone();
521512
move || {
522513
barrier.wait();
523514

0 commit comments

Comments
 (0)