Skip to content

Fix clippy warnings #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//! details.

#![cfg_attr(feature = "bench", feature(test))]
// This would add is_empty() functions to public traits
#![allow(clippy::len_without_is_empty)]

#[macro_use]
extern crate log;
Expand Down
6 changes: 3 additions & 3 deletions src/snapshot_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ impl<D: SnapshotVecDelegate, V: VecLike<D> + Default, L: Default> SnapshotVec<D,

impl<D: SnapshotVecDelegate> SnapshotVecStorage<D> {
/// Creates a `SnapshotVec` using the `undo_log`, allowing mutating methods to be called
pub fn with_log<'a, L>(
&'a mut self,
pub fn with_log<L>(
&mut self,
undo_log: L,
) -> SnapshotVec<D, &'a mut Vec<<D as SnapshotVecDelegate>::Value>, L>
) -> SnapshotVec<D, &mut Vec<<D as SnapshotVecDelegate>::Value>, L>
where
L: UndoLogs<UndoLog<D>>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/undo_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait UndoLogs<T> {
}
}

impl<'a, T, U> UndoLogs<T> for &'a mut U
impl<T, U> UndoLogs<T> for &mut U
where
U: UndoLogs<T>,
{
Expand Down
26 changes: 13 additions & 13 deletions src/unify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ impl<K: UnifyKey> VarValue<K> {

fn new(parent: K, value: K::Value, rank: u32) -> VarValue<K> {
VarValue {
parent: parent, // this is a root
value: value,
rank: rank,
parent, // this is a root
value,
rank,
}
}

Expand All @@ -233,10 +233,10 @@ where
{
/// Creates a `UnificationTable` using an external `undo_log`, allowing mutating methods to be
/// called if `L` does not implement `UndoLogs`
pub fn with_log<'a, L>(
&'a mut self,
pub fn with_log<L>(
&mut self,
undo_log: L,
) -> UnificationTable<InPlace<K, &'a mut UnificationStorage<K>, L>>
) -> UnificationTable<InPlace<K, &mut UnificationStorage<K>, L>>
where
L: UndoLogs<sv::UndoLog<Delegate<K>>>,
{
Expand Down Expand Up @@ -324,7 +324,7 @@ impl<S: UnificationStoreMut> UnificationTable<S> {
/// the closure.
pub fn reset_unifications(&mut self, mut value: impl FnMut(S::Key) -> S::Value) {
self.values.reset_unifications(|i| {
let key = UnifyKey::from_index(i as u32);
let key = UnifyKey::from_index(i);
let value = value(key);
VarValue::new_var(key, value)
});
Expand Down Expand Up @@ -443,8 +443,7 @@ impl<S: UnificationStoreMut> UnificationTable<S> {
}
}

/// ////////////////////////////////////////////////////////////////////////
/// Public API
// Public API

impl<S, K, V> UnificationTable<S>
where
Expand Down Expand Up @@ -535,7 +534,8 @@ where

let combined = V::unify_values(&self.value(root_a).value, &self.value(root_b).value)?;

Ok(self.unify_roots(root_a, root_b, combined))
self.unify_roots(root_a, root_b, combined);
Ok(())
}

/// Sets the value of the key `a_id` to `b`, attempting to merge
Expand Down Expand Up @@ -587,9 +587,9 @@ impl<V: UnifyValue> UnifyValue for Option<V> {

fn unify_values(a: &Option<V>, b: &Option<V>) -> Result<Self, V::Error> {
match (a, b) {
(&None, &None) => Ok(None),
(&Some(ref v), &None) | (&None, &Some(ref v)) => Ok(Some(v.clone())),
(&Some(ref a), &Some(ref b)) => match V::unify_values(a, b) {
(None, None) => Ok(None),
(Some(v), None) | (None, Some(v)) => Ok(Some(v.clone())),
(Some(a), Some(b)) => match V::unify_values(a, b) {
Ok(v) => Ok(Some(v)),
Err(err) => Err(err),
},
Expand Down
20 changes: 10 additions & 10 deletions src/unify/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ impl UnifyKey for UnitKey {

macro_rules! all_modes {
($name:ident for $t:ty => $body:tt) => {
// The $name field is only needed by some callers
#[allow(clippy::extra_unused_type_parameters)]
fn test_body<
$name: Clone + Default + UnificationStore<Key = $t, Value = <$t as UnifyKey>::Value>,
>() {
Expand All @@ -60,9 +62,9 @@ fn basic() {
let mut ut: UnificationTable<S> = UnificationTable::new();
let k1 = ut.new_key(());
let k2 = ut.new_key(());
assert_eq!(ut.unioned(k1, k2), false);
assert!(!ut.unioned(k1, k2));
ut.union(k1, k2);
assert_eq!(ut.unioned(k1, k2), true);
assert!(ut.unioned(k1, k2));
}
}
}
Expand Down Expand Up @@ -386,12 +388,10 @@ impl UnifyKey for OrderedKey {
b_rank: &OrderedRank,
) -> Option<(OrderedKey, OrderedKey)> {
println!("{:?} vs {:?}", a_rank, b_rank);
if a_rank > b_rank {
Some((a, b))
} else if b_rank > a_rank {
Some((b, a))
} else {
None
match a_rank.cmp(b_rank) {
cmp::Ordering::Greater => Some((a, b)),
cmp::Ordering::Less => Some((b, a)),
cmp::Ordering::Equal => None,
}
}
}
Expand Down Expand Up @@ -424,7 +424,7 @@ fn ordered_key() {
ut.union(k0_5, k0_6); // rank of new root now 1

ut.union(k0_1, k0_5); // new root rank 2, should not be k0_5 or k0_6
assert!(vec![k0_1, k0_2, k0_3, k0_4].contains(&ut.find(k0_1)));
assert!([k0_1, k0_2, k0_3, k0_4].contains(&ut.find(k0_1)));
}
}
}
Expand All @@ -450,7 +450,7 @@ fn ordered_key_k1() {

ut.union(k0_1, k1_5); // even though k1 has lower rank, it wins
assert!(
vec![k1_5, k1_6].contains(&ut.find(k0_1)),
[k1_5, k1_6].contains(&ut.find(k0_1)),
"unexpected choice for root: {:?}",
ut.find(k0_1)
);
Expand Down
16 changes: 4 additions & 12 deletions tests/external_undo_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct TypeVariableTable<'a> {
}

impl TypeVariableTable<'_> {
fn new(&mut self, i: i32) -> IntKey {
fn new_key(&mut self, i: i32) -> IntKey {
self.storage.values.with_log(&mut self.undo_log).push(i);
self.storage
.eq_relations
Expand All @@ -93,20 +93,12 @@ struct Snapshot {
undo_len: usize,
}

#[derive(Default)]
struct TypeVariableUndoLogs {
logs: Vec<UndoLog>,
num_open_snapshots: usize,
}

impl Default for TypeVariableUndoLogs {
fn default() -> Self {
Self {
logs: Default::default(),
num_open_snapshots: Default::default(),
}
}
}

impl<T> UndoLogs<T> for TypeVariableUndoLogs
where
UndoLog: From<T>,
Expand Down Expand Up @@ -193,8 +185,8 @@ fn external_undo_log() {
let mut undo_log = TypeVariableUndoLogs::default();

let snapshot = undo_log.start_snapshot();
storage.with_log(&mut undo_log).new(1);
storage.with_log(&mut undo_log).new(2);
storage.with_log(&mut undo_log).new_key(1);
storage.with_log(&mut undo_log).new_key(2);
assert_eq!(storage.len(), 2);

undo_log.rollback_to(|| &mut storage, snapshot);
Expand Down