From da14afd74e1659af6ce4553360ac5dd0ce933db8 Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 23 Oct 2021 00:49:54 +0200 Subject: Fix clippy warnings --- src/interpret/scope.rs | 8 ++++---- src/lex/lexer.rs | 22 ++++++++-------------- src/main.rs | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/interpret/scope.rs b/src/interpret/scope.rs index de32692..d8b8f43 100644 --- a/src/interpret/scope.rs +++ b/src/interpret/scope.rs @@ -19,10 +19,10 @@ impl Scope { self.scopes.pop(); } - pub fn set_var(&mut self, ident: &Identifier, value: Value) { + pub fn set_var(&mut self, ident: &str, value: Value) { for scope in self.scopes.iter_mut() { if scope.contains_key(ident) { - scope.insert(ident.clone(), value); + scope.insert(ident.to_string(), value); return; } } @@ -31,10 +31,10 @@ impl Scope { .scopes .last_mut() .expect("Tried accessing scope after last frame is gone."); - inner_scope.insert(ident.clone(), value); + inner_scope.insert(ident.to_string(), value); } - pub fn get_var(&self, ident: &Identifier) -> Option { + pub fn get_var(&self, ident: &str) -> Option { for scope in self.scopes.iter().rev() { if let Some(value) = scope.get(ident) { return Some(value.clone()); diff --git a/src/lex/lexer.rs b/src/lex/lexer.rs index c8c1a2f..4d980d6 100644 --- a/src/lex/lexer.rs +++ b/src/lex/lexer.rs @@ -136,23 +136,17 @@ impl<'s> Lexer<'s> { fn skip_non_code(&mut self) { let mut is_in_comment = false; - loop { - if let Some(c) = self.peek() { - if is_in_comment { - if c == '\n' { - is_in_comment = false; - } - } else { - if c == '#' { - is_in_comment = true; - } else if !c.is_whitespace() && c != '\n' { - break; - } + while let Some(c) = self.peek() { + if is_in_comment { + if c == '\n' { + is_in_comment = false; } - self.advance(); - } else { + } else if c == '#' { + is_in_comment = true; + } else if !c.is_whitespace() && c != '\n' { break; } + self.advance(); } } diff --git a/src/main.rs b/src/main.rs index e4dfc4f..9128cdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ fn file(filename: impl AsRef) { } fn repl() { - const PROMPT: &'static str = "🐇: "; + const PROMPT: &str = "🐇: "; let mut walker = Walker::new(); -- cgit 1.4.1