Skip to content

Commit b53fea6

Browse files
authored
Merge pull request #729 from xtqqczze/clippy/manual_assert
clippy: fix assert lints
2 parents eb1ed06 + 307b264 commit b53fea6

5 files changed

Lines changed: 19 additions & 29 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ must_use_candidate = "allow"
3636
option_if_let_else = "allow"
3737

3838
borrow_as_ptr = "warn"
39+
manual_assert = "warn"
40+
manual_assert_eq = "warn"
3941
manual_let_else = "warn"
4042
needless_continue = "warn"
4143
ptr_as_ptr = "warn"

src/map.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,7 +5615,7 @@ mod test_map {
56155615
m2.insert(1, 2);
56165616
m2.insert(2, 3);
56175617

5618-
assert!(m1 != m2);
5618+
assert_ne!(m1, m2);
56195619

56205620
m2.insert(3, 4);
56215621

@@ -6418,9 +6418,7 @@ mod test_map {
64186418
self.dropped = true;
64196419
panic!("panic in drop");
64206420
}
6421-
if self.dropped {
6422-
panic!("double drop");
6423-
}
6421+
assert!(!self.dropped, "double drop");
64246422
self.dropped = true;
64256423
}
64266424
}
@@ -6459,9 +6457,7 @@ mod test_map {
64596457
}
64606458
impl Clone for CheckedClone {
64616459
fn clone(&self) -> Self {
6462-
if self.panic_in_clone {
6463-
panic!("panic in clone")
6464-
}
6460+
assert!(!self.panic_in_clone, "panic in clone");
64656461
Self {
64666462
panic_in_clone: self.panic_in_clone,
64676463
need_drop: self.need_drop.clone(),
@@ -6571,9 +6567,7 @@ mod test_map {
65716567

65726568
impl<T: Clone> Clone for CheckedCloneDrop<T> {
65736569
fn clone(&self) -> Self {
6574-
if self.panic_in_clone {
6575-
panic!("panic in clone")
6576-
}
6570+
assert!(!self.panic_in_clone, "panic in clone");
65776571
Self {
65786572
panic_in_clone: self.panic_in_clone,
65796573
panic_in_drop: self.panic_in_drop,
@@ -6589,9 +6583,7 @@ mod test_map {
65896583
self.dropped = true;
65906584
panic!("panic in drop");
65916585
}
6592-
if self.dropped {
6593-
panic!("double drop");
6594-
}
6586+
assert!(!self.dropped, "double drop");
65956587
self.dropped = true;
65966588
}
65976589
}

src/raw.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,10 @@ impl<T, A: Allocator> RawTable<T, A> {
12851285
let ptrs = self.get_disjoint_mut_pointers(hashes, eq);
12861286

12871287
for (i, cur) in ptrs.iter().enumerate() {
1288-
if cur.is_some() && ptrs[..i].contains(cur) {
1289-
panic!("duplicate keys found");
1290-
}
1288+
assert!(
1289+
!(cur.is_some() && ptrs[..i].contains(cur)),
1290+
"duplicate keys found"
1291+
);
12911292
}
12921293
// All bucket are distinct from all previous buckets so we're clear to return the result
12931294
// of the lookup.
@@ -4530,9 +4531,7 @@ mod test_map {
45304531

45314532
impl Clone for CheckedCloneDrop {
45324533
fn clone(&self) -> Self {
4533-
if self.panic_in_clone {
4534-
panic!("panic in clone")
4535-
}
4534+
assert!(!self.panic_in_clone, "panic in clone");
45364535
Self {
45374536
panic_in_clone: self.panic_in_clone,
45384537
dropped: self.dropped,
@@ -4543,9 +4542,7 @@ mod test_map {
45434542

45444543
impl Drop for CheckedCloneDrop {
45454544
fn drop(&mut self) {
4546-
if self.dropped {
4547-
panic!("double drop");
4548-
}
4545+
assert!(!self.dropped, "double drop");
45494546
self.dropped = true;
45504547
}
45514548
}

src/set.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,7 @@ mod test_set {
28292829
s2.insert(1);
28302830
s2.insert(2);
28312831

2832-
assert!(s1 != s2);
2832+
assert_ne!(s1, s2);
28332833

28342834
s2.insert(3);
28352835

@@ -2880,9 +2880,7 @@ mod test_set {
28802880
assert_eq!(last_i, 49);
28812881
}
28822882

2883-
if !s.is_empty() {
2884-
panic!("s should be empty!");
2885-
}
2883+
assert!(s.is_empty(), "s should be empty!");
28862884

28872885
// reset to try again.
28882886
s.extend(1..100);

tests/hasher_unwind.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ impl BuildHasher for PanicBuildHasher {
4949
type Hasher = ZeroHasher;
5050

5151
fn build_hasher(&self) -> Self::Hasher {
52-
if PANIC_COUNTER.fetch_sub(1, Ordering::SeqCst) == 0 {
53-
panic!("panic in BuildHasher::build_hasher");
54-
}
52+
assert!(
53+
PANIC_COUNTER.fetch_sub(1, Ordering::SeqCst) != 0,
54+
"panic in BuildHasher::build_hasher"
55+
);
5556
ZeroHasher
5657
}
5758
}

0 commit comments

Comments
 (0)