]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/control-flow/short-circuit-let.rs
4b20a2124c356aa516a4400281f93f462a0f8e56
[rust.git] / src / test / ui / consts / control-flow / short-circuit-let.rs
1 // `&&` and `||` were previously forbidden in constants alongside let bindings.
2
3 // run-pass
4
5 #![feature(const_if_match)]
6 #![feature(const_panic)]
7 #![feature(const_fn)]
8
9 const X: i32 = {
10     let mut x = 0;
11     let _ = true && { x = 1; false };
12     x
13 };
14
15 const Y: bool = {
16     let x = true && false || true;
17     x
18 };
19
20 const fn truthy() -> bool {
21     let x = true || return false;
22     x
23 }
24
25 const fn falsy() -> bool {
26     let x = true && return false;
27     x
28 }
29
30 fn main() {
31     const _: () = assert!(Y);
32     assert!(Y);
33
34     const _: () = assert!(X == 1);
35     assert_eq!(X, 1);
36
37     const _: () = assert!(truthy());
38     const _: () = assert!(!falsy());
39     assert!(truthy() && !falsy());
40 }