diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-13T23·51+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-30T16·53+0000 |
commit | ab9407bded75d184ed694afe3564230fd09578ed (patch) | |
tree | 0492d451f8c8a78fb4c3dbf3f59ed2f6e763a57e /tvix/eval/src/value | |
parent | c4f73eecdca23ea3adaed5584224046ffdd99b4c (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/value')
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 26 | ||||
-rw-r--r-- | tvix/eval/src/value/mod.rs | 12 |
2 files changed, 13 insertions, 25 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index cc4c02df3841..76a0fe3cf646 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 2ba9ce9b50e6..46021a167b27 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 { |