Skip to content

Commit cfbb200

Browse files
committed
tests
1 parent 40ace17 commit cfbb200

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

library/coretests/tests/array.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,17 @@ fn array_eq() {
724724
let not_true = [0u8] == [].as_slice();
725725
assert!(!not_true);
726726
}
727+
728+
#[test]
729+
fn const_array_ops() {
730+
const fn doubler(x: usize) -> usize {
731+
x * 2
732+
}
733+
const fn maybe_doubler(x: usize) -> Option<usize> {
734+
x.checked_mul(2)
735+
}
736+
assert_eq!(const { std::array::from_fn::<_, 5, _>(doubler) }, [0, 2, 4, 6, 8]);
737+
assert_eq!(const { [5, 6, 1, 2].map(doubler) }, [10, 12, 2, 4]);
738+
assert_eq!(const { [1, usize::MAX, 2, 8].try_map(maybe_doubler) }, None);
739+
assert_eq!(const { std::array::try_from_fn::<_, 5, _>(maybe_doubler) }, Some([0, 2, 4, 6, 8]));
740+
}

library/coretests/tests/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(alloc_layout_extra)]
55
#![feature(array_ptr_get)]
66
#![feature(array_try_from_fn)]
7+
#![feature(array_try_map)]
78
#![feature(array_windows)]
89
#![feature(ascii_char)]
910
#![feature(ascii_char_variants)]
@@ -16,6 +17,7 @@
1617
#![feature(char_internals)]
1718
#![feature(char_max_len)]
1819
#![feature(clone_to_uninit)]
20+
#![feature(const_array)]
1921
#![feature(const_cmp)]
2022
#![feature(const_convert)]
2123
#![feature(const_destruct)]

0 commit comments

Comments
 (0)