]> git.proxmox.com Git - rustc.git/blob - tests/ui/consts/const-eval/nrvo.rs
New upstream version 1.75.0+dfsg1
[rustc.git] / tests / ui / consts / const-eval / nrvo.rs
1 // run-pass
2
3 // When the NRVO is applied, the return place (`_0`) gets treated like a normal local. For example,
4 // its address may be taken and it may be written to indirectly. Ensure that the const-eval
5 // interpreter can handle this.
6
7 #![feature(const_mut_refs)]
8
9 #[inline(never)] // Try to ensure that MIR optimizations don't optimize this away.
10 const fn init(buf: &mut [u8; 1024]) {
11 buf[33] = 3;
12 buf[444] = 4;
13 }
14
15 const fn nrvo() -> [u8; 1024] {
16 let mut buf = [0; 1024];
17 init(&mut buf);
18 buf
19 }
20
21 const BUF: [u8; 1024] = nrvo();
22
23 fn main() {
24 assert_eq!(BUF[33], 3);
25 assert_eq!(BUF[19], 0);
26 assert_eq!(BUF[444], 4);
27 }