about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-14T00·06+0300
committertazjin <tazjin@tvl.su>2022-08-30T17·13+0000
commit11ea7b82d87f47027e7ff030ca797f71a13cc9ac (patch)
treea85281a9035a9af7169394c7295feb39c553a3fb
parentde268948149b570cd01b994f8b2cd3738b60cc7a (diff)
chore(tvix/eval): minor readability improvement in attrs r/4539
Change-Id: If9d9eaf60934e96ec4b41c57818afe0c2a99c862
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6206
Reviewed-by: grfn <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
-rw-r--r--tvix/eval/src/value/attrs.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs
index 03c12a6617cf..86d963bd3a00 100644
--- a/tvix/eval/src/value/attrs.rs
+++ b/tvix/eval/src/value/attrs.rs
@@ -5,6 +5,7 @@
 ///
 /// Due to this, construction and management of attribute sets has
 /// some peculiarities that are encapsulated within this module.
+use std::collections::btree_map;
 use std::collections::BTreeMap;
 use std::fmt::Display;
 use std::rc::Rc;
@@ -168,23 +169,19 @@ impl NixAttrs {
                 let mut m = m.clone();
 
                 match m.entry(NixString::NAME) {
-                    std::collections::btree_map::Entry::Vacant(e) => {
+                    btree_map::Entry::Vacant(e) => {
                         e.insert(name.clone());
                     }
 
-                    std::collections::btree_map::Entry::Occupied(_) => {
-                        /* name from `m` has precedence */
-                    }
+                    btree_map::Entry::Occupied(_) => { /* name from `m` has precedence */ }
                 };
 
                 match m.entry(NixString::VALUE) {
-                    std::collections::btree_map::Entry::Vacant(e) => {
+                    btree_map::Entry::Vacant(e) => {
                         e.insert(value.clone());
                     }
 
-                    std::collections::btree_map::Entry::Occupied(_) => {
-                        /* value from `m` has precedence */
-                    }
+                    btree_map::Entry::Occupied(_) => { /* value from `m` has precedence */ }
                 };
 
                 NixAttrs(AttrsRep::Map(m))
@@ -307,11 +304,11 @@ fn attempt_optimise_kv(slice: &mut [Value]) -> Option<NixAttrs> {
 // checking against duplicate keys.
 fn set_attr(attrs: &mut NixAttrs, key: NixString, value: Value) -> EvalResult<()> {
     match attrs.0.map_mut().entry(key) {
-        std::collections::btree_map::Entry::Occupied(entry) => Err(Error::DuplicateAttrsKey {
+        btree_map::Entry::Occupied(entry) => Err(Error::DuplicateAttrsKey {
             key: entry.key().as_str().to_string(),
         }),
 
-        std::collections::btree_map::Entry::Vacant(entry) => {
+        btree_map::Entry::Vacant(entry) => {
             entry.insert(value);
             Ok(())
         }
@@ -344,7 +341,7 @@ fn set_nested_attr(
     // duplicate key.
     match attrs.0.map_mut().entry(key) {
         // Vacant entry -> new attribute set is needed.
-        std::collections::btree_map::Entry::Vacant(entry) => {
+        btree_map::Entry::Vacant(entry) => {
             let mut map = NixAttrs(AttrsRep::Map(BTreeMap::new()));
 
             // TODO(tazjin): technically recursing further is not
@@ -357,7 +354,7 @@ fn set_nested_attr(
 
         // Occupied entry: Either error out if there is something
         // other than attrs, or insert the next value.
-        std::collections::btree_map::Entry::Occupied(mut entry) => match entry.get_mut() {
+        btree_map::Entry::Occupied(mut entry) => match entry.get_mut() {
             Value::Attrs(attrs) => {
                 set_nested_attr(
                     Rc::make_mut(attrs),