Skip to content

Commit 72d9737

Browse files
authored
Auto merge of #252 - notriddle:notriddle/clippy-fixes, r=jdm
Clippy fixes None
2 parents 8313ec7 + 7192515 commit 72d9737

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/atom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use crate::dynamic_set::{Entry, DYNAMIC_SET};
1111
use crate::static_sets::StaticAtomSet;
1212
use debug_unreachable::debug_unreachable;
13-
use phf_shared;
13+
1414
use std::borrow::Cow;
1515
use std::cmp::Ordering::{self, Equal};
1616
use std::fmt;

src/dynamic_set.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Set {
5656
let mut ptr: Option<&mut Box<Entry>> = self.buckets[bucket_index].as_mut();
5757

5858
while let Some(entry) = ptr.take() {
59-
if entry.hash == hash && &*entry.string == &*string {
59+
if entry.hash == hash && *entry.string == *string {
6060
if entry.ref_count.fetch_add(1, SeqCst) > 0 {
6161
return NonNull::from(&mut **entry);
6262
}
@@ -94,11 +94,8 @@ impl Set {
9494

9595
let mut current: &mut Option<Box<Entry>> = &mut self.buckets[bucket_index];
9696

97-
loop {
98-
let entry_ptr: *mut Entry = match current.as_mut() {
99-
Some(entry) => &mut **entry,
100-
None => break,
101-
};
97+
while let Some(entry_ptr) = current.as_mut() {
98+
let entry_ptr: *mut Entry = &mut **entry_ptr;
10299
if entry_ptr == ptr {
103100
mem::drop(mem::replace(current, unsafe {
104101
(*entry_ptr).next_in_bucket.take()

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@
103103
104104
#![cfg_attr(test, deny(warnings))]
105105

106+
// Types, such as Atom, that impl Hash must follow the hash invariant: if two objects match
107+
// with PartialEq, they must also have the same Hash. Clippy warns on types that derive one while
108+
// manually impl-ing the other, because it seems easy for the two to drift apart, causing the
109+
// invariant to be violated.
110+
//
111+
// But Atom is a newtype over NonZeroU64, and probably always will be, since cheap comparisons and
112+
// copying are this library's purpose. So we know what the PartialEq comparison is going to do.
113+
//
114+
// The `get_hash` function, seen in `atom.rs`, consults that number, plus the global string interner
115+
// tables. The only way for the resulting hash for two Atoms with the same inner 64-bit number to
116+
// differ would be if the table entry changed between invocations, and that would be really bad.
117+
#![allow(clippy::derive_hash_xor_eq)]
118+
106119
mod atom;
107120
mod dynamic_set;
108121
mod static_sets;

src/trivial_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<Static: StaticAtomSet> PartialEq<Atom<Static>> for str {
3939

4040
impl<Static: StaticAtomSet> PartialEq<String> for Atom<Static> {
4141
fn eq(&self, other: &String) -> bool {
42-
&self[..] == &other[..]
42+
self[..] == other[..]
4343
}
4444
}
4545

@@ -66,7 +66,7 @@ impl<Static: StaticAtomSet> fmt::Display for Atom<Static> {
6666

6767
impl<Static: StaticAtomSet> AsRef<str> for Atom<Static> {
6868
fn as_ref(&self) -> &str {
69-
&self
69+
self
7070
}
7171
}
7272

0 commit comments

Comments
 (0)