From f5a21cac8ab44bce966dd079f0bcd3ce92f35fd7 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Fri, 22 Mar 2024 21:01:47 +0900 Subject: [PATCH] chore: fix warnings --- crates/erg_common/cache.rs | 27 +++++++++++++++++++++++++-- crates/erg_compiler/ty/value.rs | 8 ++------ crates/erg_parser/desugar.rs | 4 +--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/erg_common/cache.rs b/crates/erg_common/cache.rs index b4544097b..3aac8e53d 100644 --- a/crates/erg_common/cache.rs +++ b/crates/erg_common/cache.rs @@ -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 CacheSet { } } +#[derive(Debug, Clone)] pub struct CacheDict(Shared>>); -pub struct GlobalCacheDict(LocalKey>>); +impl Default for CacheDict { + fn default() -> Self { + Self::new() + } +} + +impl CacheDict { + pub fn new() -> Self { + Self(Shared::new(Dict::new())) + } +} + +impl CacheDict { + pub fn get(&self, k: &Q) -> Option> + where + K: Borrow, + { + self.0.borrow().get(k).cloned() + } + + pub fn insert(&self, k: K, v: V) { + self.0.borrow_mut().insert(k, Arc::new(v)); + } +} diff --git a/crates/erg_compiler/ty/value.rs b/crates/erg_compiler/ty/value.rs index 5af3b776d..ae793fa25 100644 --- a/crates/erg_compiler/ty/value.rs +++ b/crates/erg_compiler/ty/value.rs @@ -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) -> Option { 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() } } diff --git a/crates/erg_parser/desugar.rs b/crates/erg_parser/desugar.rs index fedae939c..2b8b9ac55 100644 --- a/crates/erg_parser/desugar.rs +++ b/crates/erg_parser/desugar.rs @@ -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),