chore: fix warnings

This commit is contained in:
Shunsuke Shibayama 2024-03-22 21:01:47 +09:00
parent ccb2cceea1
commit f5a21cac8a
3 changed files with 28 additions and 11 deletions

View file

@ -1,7 +1,6 @@
use std::borrow::{Borrow, ToOwned};
use std::hash::Hash;
use std::sync::Arc;
use std::thread::LocalKey;
use crate::dict::Dict;
use crate::set::Set;
@ -72,6 +71,30 @@ impl<T: Hash + Eq> CacheSet<T> {
}
}
#[derive(Debug, Clone)]
pub struct CacheDict<K, V: ?Sized>(Shared<Dict<K, Arc<V>>>);
pub struct GlobalCacheDict<K: 'static, V: ?Sized + 'static>(LocalKey<Shared<CacheDict<K, V>>>);
impl<K: Hash + Eq, V: ?Sized> Default for CacheDict<K, V> {
fn default() -> Self {
Self::new()
}
}
impl<K: Hash + Eq, V: ?Sized> CacheDict<K, V> {
pub fn new() -> Self {
Self(Shared::new(Dict::new()))
}
}
impl<K: Hash + Eq, V> CacheDict<K, V> {
pub fn get<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> Option<Arc<V>>
where
K: Borrow<Q>,
{
self.0.borrow().get(k).cloned()
}
pub fn insert(&self, k: K, v: V) {
self.0.borrow_mut().insert(k, Arc::new(v));
}
}

View file

@ -1611,17 +1611,13 @@ pub mod value_set {
if !is_homogeneous(set) {
return None;
}
set.iter()
.max_by(|x, y| x.try_cmp(y).unwrap())
.map(Clone::clone)
set.iter().max_by(|x, y| x.try_cmp(y).unwrap()).cloned()
}
pub fn min(set: &Set<ValueObj>) -> Option<ValueObj> {
if !is_homogeneous(set) {
return None;
}
set.iter()
.min_by(|x, y| x.try_cmp(y).unwrap())
.map(Clone::clone)
set.iter().min_by(|x, y| x.try_cmp(y).unwrap()).cloned()
}
}

View file

@ -1121,9 +1121,7 @@ impl Desugarer {
loc.col_end().unwrap_or(0),
));
let name = Expr::from(Identifier::private_from_varname(name));
let Some(key) = keys.next() else {
return None;
};
let key = keys.next()?;
let attr_name = Expr::from(Literal::str(
format!("\"{}\"", key.inspect().clone()),
key.ln_begin().unwrap_or(0),