From 64914e3d7a9a13e62f8dd1dd3f8539d1dd585f25 Mon Sep 17 00:00:00 2001 From: limuy Date: Sat, 16 Mar 2024 19:04:26 +0800 Subject: [PATCH] fix clippy --- src/compiler.rs | 6 +++--- src/compiler/ast.rs | 4 ++-- src/compiler/token.rs | 2 +- src/tools/tshell.rs | 4 ++-- src/tools/update.rs | 6 ++++++ src/tvm/types/data_structure/ac.rs | 6 ------ src/tvm/types/data_structure/sam.rs | 2 +- src/tvm/types/trcstr.rs | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 2b4358aa..70155d00 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -197,7 +197,7 @@ impl ValuePool { ret.stringpool .resize(self.const_strings.len(), "".to_string()); for i in &self.const_strings { - ret.stringpool[*i.1] = i.0.clone(); + ret.stringpool[*i.1].clone_from(i.0); } ret } @@ -424,9 +424,9 @@ mod tests { #[test] fn test_file_read() { let test_file_path = "tests/testdata/compiler/compiler1.txt"; - let source = std::fs::read_to_string(test_file_path).expect("please run in root dir"); + let source = fs::read_to_string(test_file_path).expect("please run in root dir"); let mut t = - FileSource::new(std::fs::File::open(test_file_path).expect("please run in root dir")); + FileSource::new(fs::File::open(test_file_path).expect("please run in root dir")); let mut tmp: Vec = vec![t.read(), t.read()]; tmp.reverse(); for i in &tmp { diff --git a/src/compiler/ast.rs b/src/compiler/ast.rs index 1c9f84d3..d78baf0c 100644 --- a/src/compiler/ast.rs +++ b/src/compiler/ast.rs @@ -672,7 +672,7 @@ impl<'a> AstBuilder<'a> { loop { let t = self.token_lexer.next_token()?; function_body.push((t.clone(), self.token_lexer.compiler_data.context.get_line())); - if t.tp == TokenType::RightBigBrace { + if t.tp == RightBigBrace { break; } } @@ -943,7 +943,7 @@ impl<'a> AstBuilder<'a> { let mut is_pop = false; loop { let t = self.token_lexer.next_token()?; - if t.tp == TokenType::RightBigBrace { + if t.tp == RightBigBrace { break; } is_pop = false; diff --git a/src/compiler/token.rs b/src/compiler/token.rs index da9b6f4a..db57541a 100644 --- a/src/compiler/token.rs +++ b/src/compiler/token.rs @@ -293,7 +293,7 @@ enum NumValue { impl<'a> Iterator for TokenLex<'a> { type Item = Token; - fn next(&mut self) -> std::option::Option { + fn next(&mut self) -> Option { match self.next_token() { Ok(v) => { if v.tp == TokenType::EndOfFile { diff --git a/src/tools/tshell.rs b/src/tools/tshell.rs index 65a4d3bc..60508bfc 100644 --- a/src/tools/tshell.rs +++ b/src/tools/tshell.rs @@ -70,9 +70,9 @@ pub fn tshell() -> RunResult<()> { if i.tp == TokenType::EndOfFile { break; } - if i.tp == compiler::token::TokenType::LeftBigBrace { + if i.tp == TokenType::LeftBigBrace { cnt += 1; - } else if i.tp == compiler::token::TokenType::RightBigBrace { + } else if i.tp == TokenType::RightBigBrace { cnt -= 1; } } diff --git a/src/tools/update.rs b/src/tools/update.rs index 5b88e25c..9d566166 100644 --- a/src/tools/update.rs +++ b/src/tools/update.rs @@ -21,6 +21,12 @@ impl Display for UpdateError { } } +impl Default for UpdateError { + fn default() -> Self { + Self::new() + } +} + impl UpdateError { pub fn new() -> Self { Self {} diff --git a/src/tvm/types/data_structure/ac.rs b/src/tvm/types/data_structure/ac.rs index e00ddca9..761d18a1 100644 --- a/src/tvm/types/data_structure/ac.rs +++ b/src/tvm/types/data_structure/ac.rs @@ -66,12 +66,6 @@ impl AcAutomaton { } /// use search function to add your string - /// # Example - /// ``` - /// ac.search("hello", 1); - /// ac.search("world", 2); - /// let ans = ac.get_ans(); - /// ```` fn search(&self, _pattern: &str, _id: u32) {} fn get_ans(&self) -> HashMap { diff --git a/src/tvm/types/data_structure/sam.rs b/src/tvm/types/data_structure/sam.rs index 6b8d5f87..f6fe654e 100644 --- a/src/tvm/types/data_structure/sam.rs +++ b/src/tvm/types/data_structure/sam.rs @@ -73,7 +73,7 @@ impl Sam { s._states.push(u); } else { let mut clone = Node::new(s._states[last].len + 1); - clone.next = s._states[q].next.clone(); + clone.next.clone_from(&s._states[q].next); clone.link = s._states[q].link; let cloneid = id + 1; loop { diff --git a/src/tvm/types/trcstr.rs b/src/tvm/types/trcstr.rs index 250ced61..b122fc7b 100644 --- a/src/tvm/types/trcstr.rs +++ b/src/tvm/types/trcstr.rs @@ -34,7 +34,7 @@ impl TrcObj for TrcStr { return unsafe { match (*other).downcast_ref::() { Some(v) => { - let val = gc.alloc(cat_string(&*self._value, &*((*v)._value))); + let val = gc.alloc(cat_string(&*self._value, &*(v._value))); Ok(gc.alloc(TrcStr::new(val))) } None => Err(ErrorInfo::new(