Fix clippy warnings
This commit is contained in:
puuuuh 2024-10-10 03:45:33 +03:00
parent 01d7aab603
commit de95f497ce
No known key found for this signature in database
GPG key ID: 171E3E1356CEE151
4 changed files with 21 additions and 21 deletions

View file

@ -85,6 +85,7 @@ macro_rules! setup_interned_struct {
($($zalsa::interned::Lookup::eq(&self.$field_index, &data.$field_index) && )* true)
}
#[allow(unused_unit)]
fn into_owned(self) -> StructData<$db_lt> {
($($zalsa::interned::Lookup::into_owned(self.$field_index),)*)
}

View file

@ -1,7 +1,3 @@
use std::fmt;
use std::hash::{BuildHasher, Hash, Hasher};
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use crate::durability::Durability;
use crate::id::AsId;
use crate::ingredient::fmt_index;
@ -13,6 +9,10 @@ use crate::table::Slot;
use crate::zalsa::IngredientIndex;
use crate::zalsa_local::QueryOrigin;
use crate::{Database, DatabaseKeyIndex, Id};
use std::fmt;
use std::hash::{BuildHasher, Hash, Hasher};
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use super::hash::FxDashMap;
use super::ingredient::Ingredient;
@ -307,10 +307,11 @@ where
}
/// The `Lookup` trait is a more flexible variant on [`std::borrow::Borrow`]
/// and [`std::borrow::ToOwned`]. It is implemented by "some type that can
/// be used as the lookup key for `O`". This means that `self`
/// can be hashed and compared for equality with values of type `O`
/// without actually creating an owned value. It `self` needs to be interned,
/// and [`std::borrow::ToOwned`].
///
/// It is implemented by "some type that can be used as the lookup key for `O`".
/// This means that `self` can be hashed and compared for equality with values
/// of type `O` without actually creating an owned value. It `self` needs to be interned,
/// it can be converted into an equivalent value of type `O`.
///
/// The canonical example is `&str: Lookup<String>`. However, this example
@ -319,8 +320,7 @@ where
/// where `struct ViewStruct<L1: Lookup<K1>...>(K1...)`. The `Borrow` trait
/// requires that `&(K1...)` be convertible to `&ViewStruct` which just isn't
/// possible. `Lookup` instead offers direct `hash` and `eq` methods.
pub trait Lookup<O>
{
pub trait Lookup<O> {
fn hash<H: Hasher>(&self, h: &mut H);
fn eq(&self, data: &O) -> bool;
fn into_owned(self) -> O;
@ -328,7 +328,7 @@ pub trait Lookup<O>
impl<T> Lookup<T> for T
where
T: Hash + Eq
T: Hash + Eq,
{
fn hash<H: Hasher>(&self, h: &mut H) {
Hash::hash(self, &mut *h);
@ -382,12 +382,11 @@ impl<A: Hash + Eq + PartialEq<T> + Clone + Lookup<T>, T> Lookup<Vec<T>> for &[A]
}
fn eq(&self, data: &Vec<T>) -> bool {
self.len() == data.len() &&
data.iter().enumerate().all(|(i, a)| &self[i] == a)
self.len() == data.len() && data.iter().enumerate().all(|(i, a)| &self[i] == a)
}
fn into_owned(self) -> Vec<T> {
self.into_iter().map(|a| Lookup::into_owned(a.clone())).collect()
self.iter().map(|a| Lookup::into_owned(a.clone())).collect()
}
}
@ -399,12 +398,13 @@ impl<const N: usize, A: Hash + Eq + PartialEq<T> + Clone + Lookup<T>, T> Lookup<
}
fn eq(&self, data: &Vec<T>) -> bool {
self.len() == data.len() &&
data.iter().enumerate().all(|(i, a)| &self[i] == a)
self.len() == data.len() && data.iter().enumerate().all(|(i, a)| &self[i] == a)
}
fn into_owned(self) -> Vec<T> {
self.into_iter().map(|a| Lookup::into_owned(a.clone())).collect()
self.into_iter()
.map(|a| Lookup::into_owned(a.clone()))
.collect()
}
}
@ -420,4 +420,4 @@ impl Lookup<PathBuf> for &Path {
fn into_owned(self) -> PathBuf {
self.to_owned()
}
}
}

View file

@ -132,8 +132,8 @@ pub mod plumbing {
pub use crate::interned::Configuration;
pub use crate::interned::IngredientImpl;
pub use crate::interned::JarImpl;
pub use crate::interned::Value;
pub use crate::interned::Lookup;
pub use crate::interned::Value;
}
pub mod function {

View file

@ -1,8 +1,8 @@
//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
use std::path::{Path, PathBuf};
use expect_test::expect;
use std::path::{Path, PathBuf};
use test_log::test;
#[salsa::interned]
@ -10,7 +10,6 @@ struct InternedString<'db> {
data: String,
}
#[salsa::interned]
struct InternedPair<'db> {
data: (InternedString<'db>, InternedString<'db>),