Skip to content

Commit 3dc083d

Browse files
committed
test(std): Add codegen test for array::from_fn optimization
This commit adds a new test file 'array-from_fn.rs' to the codegen test suite. The test checks the behavior of std::array::from_fn under different optimization levels: 1. At opt-level=0 (debug build), it verifies that the core::array::Guard is present in the generated code. 2. At opt-level=s (size optimization), it ensures that the Guard is optimized out. This test helps ensure that the compiler correctly optimizes array::from_fn calls in release builds while maintaining safety checks in debug builds.
1 parent bca0c5f commit 3dc083d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/codegen/array-from_fn.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ revisions: NORMAL OPT
2+
//@ [NORMAL] compile-flags: -C opt-level=0 -C debuginfo=2
3+
//@ [OPT] compile-flags: -C opt-level=s -C debuginfo=0
4+
5+
#![crate_type = "lib"]
6+
#![feature(array_from_fn)]
7+
8+
#[no_mangle]
9+
pub fn iota() -> [u8; 16] {
10+
// OPT-NOT: core..array..Guard
11+
// NORMAL: core..array..Guard
12+
std::array::from_fn(|i| i as _)
13+
}

0 commit comments

Comments
 (0)