about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-13T23·51+0300
committertazjin <tazjin@tvl.su>2022-08-30T16·53+0000
commitab9407bded75d184ed694afe3564230fd09578ed (patch)
tree0492d451f8c8a78fb4c3dbf3f59ed2f6e763a57e /tvix/eval/src
parentc4f73eecdca23ea3adaed5584224046ffdd99b4c (diff)
fix(tvix/eval): address various clippy lints r/4537
Change-Id: I3ea0f51475e80948adfeb5d1620c1f2665cc39bc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6201
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/compiler.rs3
-rw-r--r--tvix/eval/src/eval.rs2
-rw-r--r--tvix/eval/src/main.rs4
-rw-r--r--tvix/eval/src/value/attrs.rs26
-rw-r--r--tvix/eval/src/value/mod.rs12
-rw-r--r--tvix/eval/src/vm.rs24
6 files changed, 30 insertions, 41 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 75ea99ea78..d4a34ba61d 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -14,7 +14,6 @@
 //! mistakes early during development.
 
 use path_clean::PathClean;
-use rnix;
 use rnix::types::{BinOpKind, EntryHolder, TokenWrapper, TypedNode, Wrapper};
 use std::path::{Path, PathBuf};
 
@@ -735,7 +734,7 @@ impl Compiler {
 
         // TL;DR - iterate from the back while things belonging to the
         // ended scope still exist.
-        while scope.locals.len() > 0
+        while !scope.locals.is_empty()
             && scope.locals[scope.locals.len() - 1].depth > scope.scope_depth
         {
             pops += 1;
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 456f2575ca..d8037ea143 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -12,7 +12,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         todo!()
     }
 
-    if let Ok(_) = std::env::var("TVIX_DISPLAY_AST") {
+    if std::env::var("TVIX_DISPLAY_AST").is_ok() {
         println!("{}", ast.root().dump());
     }
 
diff --git a/tvix/eval/src/main.rs b/tvix/eval/src/main.rs
index 3d0c29688e..55cc643dce 100644
--- a/tvix/eval/src/main.rs
+++ b/tvix/eval/src/main.rs
@@ -32,7 +32,9 @@ fn run_file(file: &str) {
 
 fn state_dir() -> Option<PathBuf> {
     let mut path = dirs::data_dir();
-    path.as_mut().map(|p| p.push("tvix"));
+    if let Some(p) = path.as_mut() {
+        p.push("tvix")
+    }
     path
 }
 
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs
index cc4c02df38..76a0fe3cf6 100644
--- a/tvix/eval/src/value/attrs.rs
+++ b/tvix/eval/src/value/attrs.rs
@@ -52,11 +52,11 @@ impl AttrsRep {
 
             AttrsRep::KV { name, value } => {
                 if key == "name" {
-                    return Some(&name);
+                    return Some(name);
                 }
 
                 if key == "value" {
-                    return Some(&value);
+                    return Some(value);
                 }
 
                 None
@@ -310,21 +310,16 @@ fn attempt_optimise_kv(slice: &mut [Value]) -> Option<NixAttrs> {
 // Set an attribute on an in-construction attribute set, while
 // checking against duplicate keys.
 fn set_attr(attrs: &mut NixAttrs, key: NixString, value: Value) -> EvalResult<()> {
-    let attrs = attrs.0.map_mut();
-    let entry = attrs.entry(key);
-
-    match entry {
-        std::collections::btree_map::Entry::Occupied(entry) => {
-            return Err(Error::DuplicateAttrsKey {
-                key: entry.key().as_str().to_string(),
-            })
-        }
+    match attrs.0.map_mut().entry(key) {
+        std::collections::btree_map::Entry::Occupied(entry) => Err(Error::DuplicateAttrsKey {
+            key: entry.key().as_str().to_string(),
+        }),
 
         std::collections::btree_map::Entry::Vacant(entry) => {
             entry.insert(value);
-            return Ok(());
+            Ok(())
         }
-    };
+    }
 }
 
 // Set a nested attribute inside of an attribute set, throwing a
@@ -345,16 +340,13 @@ fn set_nested_attr(
         return set_attr(attrs, key, value);
     }
 
-    let attrs = attrs.0.map_mut();
-    let entry = attrs.entry(key);
-
     // If there is not we go one step further down, in which case we
     // need to ensure that there either is no entry, or the existing
     // entry is a hashmap into which to insert the next value.
     //
     // If a value of a different type exists, the user specified a
     // duplicate key.
-    match entry {
+    match attrs.0.map_mut().entry(key) {
         // Vacant entry -> new attribute set is needed.
         std::collections::btree_map::Entry::Vacant(entry) => {
             let mut map = NixAttrs(AttrsRep::Map(BTreeMap::new()));
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index 2ba9ce9b50..46021a167b 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -33,11 +33,7 @@ pub enum Value {
 
 impl Value {
     pub fn is_number(&self) -> bool {
-        match self {
-            Value::Integer(_) => true,
-            Value::Float(_) => true,
-            _ => false,
-        }
+        matches!(self, Value::Integer(_) | Value::Float(_))
     }
 
     pub fn type_of(&self) -> &'static str {
@@ -66,7 +62,7 @@ impl Value {
         }
     }
 
-    pub fn as_string(self) -> EvalResult<NixString> {
+    pub fn to_string(self) -> EvalResult<NixString> {
         match self {
             Value::String(s) => Ok(s),
             other => Err(Error::TypeError {
@@ -76,7 +72,7 @@ impl Value {
         }
     }
 
-    pub fn as_attrs(self) -> EvalResult<Rc<NixAttrs>> {
+    pub fn to_attrs(self) -> EvalResult<Rc<NixAttrs>> {
         match self {
             Value::Attrs(s) => Ok(s),
             other => Err(Error::TypeError {
@@ -86,7 +82,7 @@ impl Value {
         }
     }
 
-    pub fn as_list(self) -> EvalResult<NixList> {
+    pub fn to_list(self) -> EvalResult<NixList> {
         match self {
             Value::List(l) => Ok(l),
             other => Err(Error::TypeError {
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index 0d0249e3f6..f96a5dcbdd 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -159,15 +159,15 @@ impl VM {
                 OpCode::OpAttrPath(count) => self.run_attr_path(count)?,
 
                 OpCode::OpAttrsUpdate => {
-                    let rhs = self.pop().as_attrs()?;
-                    let lhs = self.pop().as_attrs()?;
+                    let rhs = self.pop().to_attrs()?;
+                    let lhs = self.pop().to_attrs()?;
 
                     self.push(Value::Attrs(Rc::new(lhs.update(&rhs))))
                 }
 
                 OpCode::OpAttrsSelect => {
-                    let key = self.pop().as_string()?;
-                    let attrs = self.pop().as_attrs()?;
+                    let key = self.pop().to_string()?;
+                    let attrs = self.pop().to_attrs()?;
 
                     match attrs.select(key.as_str()) {
                         Some(value) => self.push(value.clone()),
@@ -181,8 +181,8 @@ impl VM {
                 }
 
                 OpCode::OpAttrOrNotFound => {
-                    let key = self.pop().as_string()?;
-                    let attrs = self.pop().as_attrs()?;
+                    let key = self.pop().to_string()?;
+                    let attrs = self.pop().to_attrs()?;
 
                     match attrs.select(key.as_str()) {
                         Some(value) => self.push(value.clone()),
@@ -191,8 +191,8 @@ impl VM {
                 }
 
                 OpCode::OpAttrsIsSet => {
-                    let key = self.pop().as_string()?;
-                    let attrs = self.pop().as_attrs()?;
+                    let key = self.pop().to_string()?;
+                    let attrs = self.pop().to_attrs()?;
                     let result = Value::Bool(attrs.select(key.as_str()).is_some());
                     self.push(result);
                 }
@@ -204,8 +204,8 @@ impl VM {
                 }
 
                 OpCode::OpConcat => {
-                    let rhs = self.pop().as_list()?;
-                    let lhs = self.pop().as_list()?;
+                    let rhs = self.pop().to_list()?;
+                    let lhs = self.pop().to_list()?;
                     self.push(Value::List(lhs.concat(&rhs)))
                 }
 
@@ -290,7 +290,7 @@ impl VM {
         let mut path = Vec::with_capacity(count);
 
         for _ in 0..count {
-            path.push(self.pop().as_string()?);
+            path.push(self.pop().to_string()?);
         }
 
         self.push(Value::AttrPath(path));
@@ -310,7 +310,7 @@ impl VM {
         let mut out = String::new();
 
         for _ in 0..count {
-            out.push_str(&self.pop().as_string()?.as_str());
+            out.push_str(self.pop().to_string()?.as_str());
         }
 
         self.push(Value::String(out.into()));