]> git.proxmox.com Git - rustc.git/blob - tests/ui/consts/min_const_fn/promotion.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / consts / min_const_fn / promotion.rs
1 use std::cell::Cell;
2
3 const fn foo1() {}
4 const fn foo2(x: i32) -> i32 { x }
5 const fn foo3() -> i32 { 42 }
6 const fn foo4() -> Cell<i32> { Cell::new(42) }
7 const fn foo5() -> Option<Cell<i32>> { Some(Cell::new(42)) }
8 const fn foo6() -> Option<Cell<i32>> { None }
9
10 fn main() {
11 let x: &'static () = &foo1(); //~ ERROR temporary value dropped while borrowed
12 let y: &'static i32 = &foo2(42); //~ ERROR temporary value dropped while borrowed
13 let z: &'static i32 = &foo3(); //~ ERROR temporary value dropped while borrowed
14 let a: &'static Cell<i32> = &foo4(); //~ ERROR temporary value dropped while borrowed
15 let a: &'static Option<Cell<i32>> = &foo5(); //~ ERROR temporary value dropped while borrowed
16 let a: &'static Option<Cell<i32>> = &foo6(); //~ ERROR temporary value dropped while borrowed
17 }