Skip to content

Commit 8197346

Browse files
Gankraalexcrichton
authored andcommitted
---
yaml --- r: 212650 b: refs/heads/beta c: 1c0b2f4 h: refs/heads/master v: v3
1 parent 4843f51 commit 8197346

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 2cc6e8fb538d5a629501e2a55e439cf4c8f98b2c
32+
refs/heads/beta: 1c0b2f42c86a12dd49b164ee0df97208a9cee20e
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: a224db5e630715d9f46938fe07b58eb644e3c27d

branches/beta/src/libcollections/linked_list.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,13 @@ impl<T> LinkedList<T> {
616616
length: len - at
617617
};
618618

619+
// Swap split_node.next with list_head (which is None), nulling out split_node.next,
620+
// as it is the new tail.
619621
mem::swap(&mut split_node.resolve().unwrap().next, &mut splitted_list.list_head);
622+
// Null out list_head.prev. Note this `unwrap` won't fail because if at == len
623+
// we already branched out at the top of the fn to return the empty list.
624+
splitted_list.list_head.as_mut().unwrap().prev = Rawlink::none();
625+
// Fix the tail ptr
620626
self.list_tail = split_node;
621627
self.length = at;
622628

@@ -1082,6 +1088,26 @@ mod tests {
10821088
}
10831089
}
10841090

1091+
#[test]
1092+
fn test_26021() {
1093+
use std::iter::ExactSizeIterator;
1094+
// There was a bug in split_off that failed to null out the RHS's head's prev ptr.
1095+
// This caused the RHS's dtor to walk up into the LHS at drop and delete all of
1096+
// its nodes.
1097+
//
1098+
// https://github.com/rust-lang/rust/issues/26021
1099+
let mut v1 = LinkedList::new();
1100+
v1.push_front(1u8);
1101+
v1.push_front(1u8);
1102+
v1.push_front(1u8);
1103+
v1.push_front(1u8);
1104+
let _ = v1.split_off(3); // Dropping this now should not cause laundry consumption
1105+
assert_eq!(v1.len(), 3);
1106+
1107+
assert_eq!(v1.iter().len(), 3);
1108+
assert_eq!(v1.iter().collect::<Vec<_>>().len(), 3);
1109+
}
1110+
10851111
#[cfg(test)]
10861112
fn fuzz_test(sz: i32) {
10871113
let mut m: LinkedList<_> = LinkedList::new();

0 commit comments

Comments
 (0)