Skip to content

Commit a964307

Browse files
committed
Add a test for cloned side effects
1 parent 3eddc74 commit a964307

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libcore/tests/iter.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,23 @@ fn test_cloned() {
12491249
assert_eq!(it.next_back(), None);
12501250
}
12511251

1252+
#[test]
1253+
fn test_cloned_side_effects() {
1254+
let mut count = 0;
1255+
{
1256+
let iter = [1, 2, 3]
1257+
.iter()
1258+
.map(|x| {
1259+
count += 1;
1260+
x
1261+
})
1262+
.cloned()
1263+
.zip(&[1]);
1264+
for _ in iter {}
1265+
}
1266+
assert_eq!(count, 2);
1267+
}
1268+
12521269
#[test]
12531270
fn test_double_ended_map() {
12541271
let xs = [1, 2, 3, 4, 5, 6];

0 commit comments

Comments
 (0)