]> git.lizzy.rs Git - rust.git/commitdiff
add LinkedList test and mention the bug Miri found there
authorRalf Jung <post@ralfj.de>
Thu, 18 Apr 2019 09:54:21 +0000 (11:54 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 19 Apr 2019 21:08:24 +0000 (23:08 +0200)
README.md
tests/run-pass/linked-list.rs [new file with mode: 0644]

index 716c26c03a735070b180a8ac21a5b65e386617a7..464c1c33c2d3338f95ae44e60dac6ed2665c3b1b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -297,6 +297,7 @@ Miri has already found a number of bugs in the Rust standard library, which we c
 * [Futures turning a shared reference into a mutable one](https://github.com/rust-lang/rust/pull/56319)
 * [`str` turning a shared reference into a mutable one](https://github.com/rust-lang/rust/pull/58200)
 * [`BTreeMap` creating mutable references that overlap with shared references](https://github.com/rust-lang/rust/pull/58431)
+* [`LinkedList` creating overlapping mutable references](https://github.com/rust-lang/rust/pull/60072)
 
 ## License
 
diff --git a/tests/run-pass/linked-list.rs b/tests/run-pass/linked-list.rs
new file mode 100644 (file)
index 0000000..f1d2172
--- /dev/null
@@ -0,0 +1,33 @@
+#![feature(linked_list_extras)]
+use std::collections::LinkedList;
+
+fn list_from<T: Clone>(v: &[T]) -> LinkedList<T> {
+    v.iter().cloned().collect()
+}
+    
+fn main() {
+    let mut m = list_from(&[0, 2, 4, 6, 8]);
+    let len = m.len();
+    {
+        let mut it = m.iter_mut();
+        it.insert_next(-2);
+        loop {
+            match it.next() {
+                None => break,
+                Some(elt) => {
+                    it.insert_next(*elt + 1);
+                    match it.peek_next() {
+                        Some(x) => assert_eq!(*x, *elt + 2),
+                        None => assert_eq!(8, *elt),
+                    }
+                }
+            }
+        }
+        it.insert_next(0);
+        it.insert_next(1);
+    }
+
+    assert_eq!(m.len(), 3 + len * 2);
+    assert_eq!(m.into_iter().collect::<Vec<_>>(),
+               [-2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1]);
+}