Skip to content

Instantly share code, notes, and snippets.

@zwarich
Last active August 29, 2015 14:04
Show Gist options
  • Save zwarich/348d5726d1ef42f109ee to your computer and use it in GitHub Desktop.
Save zwarich/348d5726d1ef42f109ee to your computer and use it in GitHub Desktop.
diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs
index 5658d07..3a67972 100644
--- a/src/libcollections/treemap.rs
+++ b/src/libcollections/treemap.rs
@@ -1048,7 +1048,8 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
save.level -= 1;
if right_level > save.level {
- for x in save.right.mut_iter() { x.level = save.level }
+ let save_level = save.level;
+ for x in save.right.mut_iter() { x.level = save_level }
}
skew(save);
diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs
index 5c17dd9..e64af25 100644
--- a/src/libcollections/trie.rs
+++ b/src/libcollections/trie.rs
@@ -713,7 +713,7 @@ fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
*child = External(key, value);
return None;
}
- Internal(ref mut x) => {
+ Internal(box ref mut x) => {
return insert(&mut x.count, &mut x.children[chunk(key, idx)], key, value, idx + 1);
}
External(stored_key, ref mut stored_value) if stored_key == key => {
@@ -729,11 +729,17 @@ fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
match mem::replace(child, Nothing) {
External(stored_key, stored_value) => {
let mut new = box TrieNode::new();
- insert(&mut new.count,
- &mut new.children[chunk(stored_key, idx)],
- stored_key, stored_value, idx + 1);
- let ret = insert(&mut new.count, &mut new.children[chunk(key, idx)],
- key, value, idx + 1);
+
+ let ret = {
+ let new_interior = &mut *new;
+ insert(&mut new_interior.count,
+ &mut new_interior.children[chunk(stored_key, idx)],
+ stored_key, stored_value, idx + 1);
+ insert(&mut new_interior.count,
+ &mut new_interior.children[chunk(key, idx)],
+ key, value, idx + 1)
+ };
+
*child = Internal(new);
return ret;
}
@@ -751,7 +757,7 @@ fn remove<T>(count: &mut uint, child: &mut Child<T>, key: uint,
}
}
External(..) => (None, false),
- Internal(ref mut x) => {
+ Internal(box ref mut x) => {
let ret = remove(&mut x.count, &mut x.children[chunk(key, idx)],
key, idx + 1);
(ret, x.count == 0)
diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs
index 4530173..9d03168 100644
--- a/src/libstd/collections/lru_cache.rs
+++ b/src/libstd/collections/lru_cache.rs
@@ -246,7 +246,8 @@ impl<K, V> Drop for LruCache<K, V> {
unsafe {
let node: Box<LruEntry<K, V>> = mem::transmute(self.head);
// Prevent compiler from trying to drop the un-initialized field in the sigil node.
- let box LruEntry { key: k, value: v, .. } = node;
+ let box internal_node = node;
+ let LruEntry { next: _, prev: _, key: k, value: v } = internal_node;
mem::forget(k);
mem::forget(v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment