Skip to content

Commit f7381fa

Browse files
committed
TEST: Add test for extending array of ZST
This demonstrates a bug in current extend.
1 parent e68c0c7 commit f7381fa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,23 @@ fn test_newish_stable_uses_maybe_uninit() {
640640
assert!(cfg!(has_stable_maybe_uninit));
641641
}
642642
}
643+
644+
#[test]
645+
fn test_extend_zst() {
646+
let mut range = 0..10;
647+
#[derive(Copy, Clone, PartialEq, Debug)]
648+
struct Z; // Zero sized type
649+
650+
let mut array: ArrayVec<[_; 5]> = range.by_ref().map(|_| Z).collect();
651+
assert_eq!(&array[..], &[Z; 5]);
652+
assert_eq!(range.next(), Some(5));
653+
654+
array.extend(range.by_ref().map(|_| Z));
655+
assert_eq!(range.next(), Some(6));
656+
657+
let mut array: ArrayVec<[_; 10]> = (0..3).map(|_| Z).collect();
658+
assert_eq!(&array[..], &[Z; 3]);
659+
array.extend((3..5).map(|_| Z));
660+
assert_eq!(&array[..], &[Z; 5]);
661+
assert_eq!(array.len(), 5);
662+
}

0 commit comments

Comments
 (0)