about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonrad Borowski <konrad@borowski.pw>2018-12-05 17:53:34 +0100
committerKonrad Borowski <konrad@borowski.pw>2018-12-05 17:53:34 +0100
commita96430799987541b02aa9605f091dfc8368fa668 (patch)
treeaa2cf4b7424b70c1d4711d31c245a23f7775cf6b
parent3eddc743f2ca3dbd5a5a41e3c2477ca9fbc7b97c (diff)
downloadrust-a96430799987541b02aa9605f091dfc8368fa668.tar.gz
rust-a96430799987541b02aa9605f091dfc8368fa668.zip
Add a test for cloned side effects
-rw-r--r--src/libcore/tests/iter.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index 495483db555..19be1a07c5b 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -1250,6 +1250,23 @@ fn test_cloned() {
 }
 
 #[test]
+fn test_cloned_side_effects() {
+    let mut count = 0;
+    {
+        let iter = [1, 2, 3]
+            .iter()
+            .map(|x| {
+                count += 1;
+                x
+            })
+            .cloned()
+            .zip(&[1]);
+        for _ in iter {}
+    }
+    assert_eq!(count, 2);
+}
+
+#[test]
 fn test_double_ended_map() {
     let xs = [1, 2, 3, 4, 5, 6];
     let mut it = xs.iter().map(|&x| x * -1);