From a90218f229f43f6a19ff816cc2c454b938b5ad97 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Mon, 10 Jul 2023 21:37:30 +0800 Subject: [PATCH] chore: fix all warnings --- crates/loro-internal/src/log_store.rs | 2 +- crates/loro-internal/src/log_store/import.rs | 1 + crates/loro-internal/src/op.rs | 2 +- crates/loro-internal/src/refactor/state.rs | 18 +++++++++--------- .../src/refactor/state/list_state.rs | 18 +++++++++--------- .../src/refactor/state/map_state.rs | 6 +++--- .../src/refactor/state/text_state.rs | 10 +++++----- crates/loro-internal/src/smstring.rs | 1 + crates/loro-internal/src/value.rs | 4 +--- crates/rle/src/rle_tree/node/internal_impl.rs | 2 ++ crates/rle/src/rle_tree/node/leaf_impl.rs | 3 +++ crates/rle/src/rle_vec.rs | 6 +++--- 12 files changed, 39 insertions(+), 34 deletions(-) diff --git a/crates/loro-internal/src/log_store.rs b/crates/loro-internal/src/log_store.rs index 56faca2c..6b11c2b7 100644 --- a/crates/loro-internal/src/log_store.rs +++ b/crates/loro-internal/src/log_store.rs @@ -200,7 +200,7 @@ impl LogStore { let mut container = container.try_lock().unwrap(); op.clone() .convert(&mut container, self.cfg.gc.gc) - .to_static() + .into_static() } pub(crate) fn create_container( diff --git a/crates/loro-internal/src/log_store/import.rs b/crates/loro-internal/src/log_store/import.rs index a320e320..ffbd3805 100644 --- a/crates/loro-internal/src/log_store/import.rs +++ b/crates/loro-internal/src/log_store/import.rs @@ -432,6 +432,7 @@ impl LogStore { } } + #[allow(dead_code)] fn tailor_changes(&mut self, changes: &mut RemoteClientChanges) { changes.retain(|_, v| !v.is_empty()); for (client_id, changes) in changes.iter_mut() { diff --git a/crates/loro-internal/src/op.rs b/crates/loro-internal/src/op.rs index 74e4135c..277256e9 100644 --- a/crates/loro-internal/src/op.rs +++ b/crates/loro-internal/src/op.rs @@ -100,7 +100,7 @@ impl<'a> RemoteOp<'a> { .collect() } - pub(crate) fn to_static(self) -> RemoteOp<'static> { + pub(crate) fn into_static(self) -> RemoteOp<'static> { RemoteOp { counter: self.counter, container: self.container, diff --git a/crates/loro-internal/src/refactor/state.rs b/crates/loro-internal/src/refactor/state.rs index 27538269..bc001610 100644 --- a/crates/loro-internal/src/refactor/state.rs +++ b/crates/loro-internal/src/refactor/state.rs @@ -17,9 +17,9 @@ mod list_state; mod map_state; mod text_state; -use list_state::ListState; -use map_state::MapState; -use text_state::TextState; +use list_state::List; +use map_state::Map; +use text_state::Text; use super::{arena::SharedArena, oplog::OpLog}; @@ -53,9 +53,9 @@ pub trait ContainerState: Clone { #[enum_dispatch(ContainerState)] #[derive(Clone)] pub enum State { - ListState, - MapState, - TextState, + List, + Map, + Text, } pub struct ContainerStateDiff { @@ -126,8 +126,8 @@ impl AppState { pub fn create_state(kind: ContainerType) -> State { match kind { - ContainerType::Text => State::TextState(TextState::new()), - ContainerType::Map => State::MapState(MapState::new()), - ContainerType::List => State::ListState(ListState::new()), + ContainerType::Text => State::Text(Text::new()), + ContainerType::Map => State::Map(Map::new()), + ContainerType::List => State::List(List::new()), } } diff --git a/crates/loro-internal/src/refactor/state/list_state.rs b/crates/loro-internal/src/refactor/state/list_state.rs index acc6b432..69e17897 100644 --- a/crates/loro-internal/src/refactor/state/list_state.rs +++ b/crates/loro-internal/src/refactor/state/list_state.rs @@ -18,14 +18,14 @@ use super::ContainerState; type ContainerMapping = Arc>>; -pub struct ListState { - list: BTree, +pub struct List { + list: BTree, in_txn: bool, undo_stack: Vec, child_container_to_leaf: Arc>>, } -impl Clone for ListState { +impl Clone for List { fn clone(&self) -> Self { Self { list: self.list.clone(), @@ -41,8 +41,8 @@ enum UndoItem { Delete { index: usize, value: LoroValue }, } -struct List; -impl BTreeTrait for List { +struct ListImpl; +impl BTreeTrait for ListImpl { type Elem = LoroValue; type Cache = isize; @@ -89,7 +89,7 @@ impl BTreeTrait for List { } } -impl UseLengthFinder for List { +impl UseLengthFinder for ListImpl { fn get_len(cache: &isize) -> usize { *cache as usize } @@ -103,7 +103,7 @@ impl UseLengthFinder for List { } } -impl ListState { +impl List { pub fn new() -> Self { let mut tree = BTree::new(); let mapping: ContainerMapping = Arc::new(Mutex::new(Default::default())); @@ -214,7 +214,7 @@ impl ListState { } } -impl ContainerState for ListState { +impl ContainerState for List { fn apply_diff(&mut self, diff: Diff) { if let Diff::List(delta) = diff { let mut index = 0; @@ -289,7 +289,7 @@ mod test { #[test] fn test() { - let mut list = ListState::new(); + let mut list = List::new(); fn id(name: &str) -> ContainerID { ContainerID::new_root(name, crate::ContainerType::List) } diff --git a/crates/loro-internal/src/refactor/state/map_state.rs b/crates/loro-internal/src/refactor/state/map_state.rs index fce54106..d8a9db41 100644 --- a/crates/loro-internal/src/refactor/state/map_state.rs +++ b/crates/loro-internal/src/refactor/state/map_state.rs @@ -12,13 +12,13 @@ use crate::{ use super::ContainerState; #[derive(Clone)] -pub struct MapState { +pub struct Map { map: FxHashMap, in_txn: bool, map_when_txn_start: FxHashMap>, } -impl ContainerState for MapState { +impl ContainerState for Map { fn apply_diff(&mut self, diff: Diff) { if let Diff::NewMap(delta) = diff { for (key, value) in delta.updated { @@ -64,7 +64,7 @@ impl ContainerState for MapState { } } -impl MapState { +impl Map { pub fn new() -> Self { Self { map: FxHashMap::default(), diff --git a/crates/loro-internal/src/refactor/state/text_state.rs b/crates/loro-internal/src/refactor/state/text_state.rs index 809ae51b..bf321137 100644 --- a/crates/loro-internal/src/refactor/state/text_state.rs +++ b/crates/loro-internal/src/refactor/state/text_state.rs @@ -11,14 +11,14 @@ use crate::{ use super::ContainerState; #[derive(Default)] -pub struct TextState { +pub struct Text { pub(crate) rope: JumpRope, in_txn: bool, deleted_bytes: Vec, undo_stack: Vec, } -impl Clone for TextState { +impl Clone for Text { fn clone(&self) -> Self { Self { rope: self.rope.clone(), @@ -41,7 +41,7 @@ enum UndoItem { }, } -impl ContainerState for TextState { +impl ContainerState for Text { fn apply_diff(&mut self, diff: Diff) { if let Diff::Text(delta) = diff { let mut index = 0; @@ -119,7 +119,7 @@ impl ContainerState for TextState { } } -impl TextState { +impl Text { pub fn new() -> Self { Self { rope: JumpRope::new(), @@ -175,7 +175,7 @@ mod test { #[test] fn abort_txn() { - let mut state = TextState::new(); + let mut state = Text::new(); state.insert(0, "haha"); state.start_txn(); state.insert(4, "1234"); diff --git a/crates/loro-internal/src/smstring.rs b/crates/loro-internal/src/smstring.rs index e42a5106..20191a0c 100644 --- a/crates/loro-internal/src/smstring.rs +++ b/crates/loro-internal/src/smstring.rs @@ -27,6 +27,7 @@ impl DerefMut for SmString { } impl SmString { + #[allow(dead_code)] pub fn new() -> Self { SmString(SmartString::new()) } diff --git a/crates/loro-internal/src/value.rs b/crates/loro-internal/src/value.rs index c7dc7b24..5dfece66 100644 --- a/crates/loro-internal/src/value.rs +++ b/crates/loro-internal/src/value.rs @@ -930,9 +930,7 @@ impl<'de> serde::de::Visitor<'de> for LoroValueEnumVisitor { } (LoroValueFields::List, v) => v.newtype_variant().map(|x| LoroValue::List(Arc::new(x))), (LoroValueFields::Map, v) => v.newtype_variant().map(|x| LoroValue::Map(Arc::new(x))), - (LoroValueFields::Unresolved, v) => { - v.newtype_variant().map(|x| LoroValue::Container(x)) - } + (LoroValueFields::Unresolved, v) => v.newtype_variant().map(LoroValue::Container), } } } diff --git a/crates/rle/src/rle_tree/node/internal_impl.rs b/crates/rle/src/rle_tree/node/internal_impl.rs index a520c592..190f1cfd 100644 --- a/crates/rle/src/rle_tree/node/internal_impl.rs +++ b/crates/rle/src/rle_tree/node/internal_impl.rs @@ -33,6 +33,7 @@ impl<'a, T: Rle, A: RleTreeTrait> InternalNode<'a, T, A> { /// return result need to update cache #[inline] + #[allow(clippy::type_complexity)] fn _split( &mut self, ) -> ( @@ -421,6 +422,7 @@ impl<'a, T: Rle, A: RleTreeTrait> InternalNode<'a, T, A> { -update } + #[allow(clippy::type_complexity)] pub(crate) fn apply_updates( &mut self, mut updates: Vec<(usize, A::CacheInParent, Vec>)>, diff --git a/crates/rle/src/rle_tree/node/leaf_impl.rs b/crates/rle/src/rle_tree/node/leaf_impl.rs index f44ab9fe..7c90c83b 100644 --- a/crates/rle/src/rle_tree/node/leaf_impl.rs +++ b/crates/rle/src/rle_tree/node/leaf_impl.rs @@ -185,6 +185,7 @@ impl<'bump, T: Rle, A: RleTreeTrait> LeafNode<'bump, T, A> { false } + #[allow(clippy::type_complexity)] pub fn insert( &mut self, raw_index: A::Int, @@ -478,6 +479,7 @@ impl<'bump, T: Rle, A: RleTreeTrait> LeafNode<'bump, T, A> { } // TODO: refactor + #[allow(clippy::type_complexity)] pub(crate) fn apply_updates( &mut self, mut updates: Vec<(usize, SmallVec<[T; 4]>)>, @@ -578,6 +580,7 @@ impl<'bump, T: Rle, A: RleTreeTrait> LeafNode<'bump, T, A> { } } + #[allow(clippy::type_complexity)] fn with_cache_updated( &mut self, result: Result<(), ::Boxed<'bump, Node<'bump, T, A>>>, diff --git a/crates/rle/src/rle_vec.rs b/crates/rle/src/rle_vec.rs index 827c981c..8ee2cf26 100644 --- a/crates/rle/src/rle_vec.rs +++ b/crates/rle/src/rle_vec.rs @@ -625,14 +625,14 @@ where let end = end - index(&vec[0]); let mut ans = Vec::new(); let mut index = 0; - for i in 0..vec.len() { + for item in vec.iter() { if index >= end { break; } - let len = vec[i].atom_len(); + let len = item.atom_len(); if start < index + len { - ans.push(vec[i].slice(start.saturating_sub(index), (end - index).min(len))) + ans.push(item.slice(start.saturating_sub(index), (end - index).min(len))) } index += len;