2020-05-21 14:49:38 -05:00
|
|
|
// check-pass
|
2019-11-17 23:11:42 -06:00
|
|
|
|
2020-05-21 14:49:38 -05:00
|
|
|
const _: i32 = if true { 5 } else { 6 };
|
2019-11-17 23:11:42 -06:00
|
|
|
|
2020-05-21 14:49:38 -05:00
|
|
|
const _: i32 = if let Some(true) = Some(false) { 0 } else { 1 };
|
2019-11-17 23:11:42 -06:00
|
|
|
|
2020-05-21 14:49:38 -05:00
|
|
|
const _: i32 = match 1 {
|
2019-11-17 23:11:42 -06:00
|
|
|
2 => 3,
|
|
|
|
4 => 5,
|
|
|
|
_ => 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static FOO: i32 = {
|
|
|
|
let x = if true { 0 } else { 1 };
|
2020-05-21 14:49:38 -05:00
|
|
|
let x = match x {
|
|
|
|
0 => 1,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
if let Some(x) = Some(x) { x } else { 1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static mut BAR: i32 = {
|
|
|
|
let x = if true { 0 } else { 1 };
|
2020-05-21 14:49:38 -05:00
|
|
|
let x = match x {
|
|
|
|
0 => 1,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
if let Some(x) = Some(x) { x } else { 1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const fn if_() -> i32 {
|
2020-05-21 14:49:38 -05:00
|
|
|
if true { 5 } else { 6 }
|
2019-11-17 23:11:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const fn if_let(a: Option<bool>) -> i32 {
|
2020-05-21 14:49:38 -05:00
|
|
|
if let Some(true) = a { 0 } else { 1 }
|
2019-11-17 23:11:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const fn match_(i: i32) -> i32 {
|
2020-05-21 14:49:38 -05:00
|
|
|
match i {
|
2019-11-17 23:11:42 -06:00
|
|
|
i if i > 10 => i,
|
|
|
|
1 => 2,
|
2020-05-21 14:49:38 -05:00
|
|
|
_ => 0,
|
2019-11-17 23:11:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Foo {
|
|
|
|
const IF: i32 = if true { 5 } else { 6 };
|
|
|
|
const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
|
2020-05-21 14:49:38 -05:00
|
|
|
const MATCH: i32 = match 0 {
|
|
|
|
1 => 2,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for () {
|
|
|
|
const IF: i32 = if true { 5 } else { 6 };
|
|
|
|
const IF_LET: i32 = if let Some(true) = None { 5 } else { 6 };
|
2020-05-21 14:49:38 -05:00
|
|
|
const MATCH: i32 = match 0 {
|
|
|
|
1 => 2,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn non_const_outside() {
|
|
|
|
const fn const_inside(y: bool) -> i32 {
|
|
|
|
let x = if y { 0 } else { 1 };
|
2020-05-21 14:49:38 -05:00
|
|
|
let x = match x {
|
|
|
|
0 => 1,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
if let Some(x) = Some(x) { x } else { 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const fn const_outside() {
|
|
|
|
fn non_const_inside(y: bool) -> i32 {
|
|
|
|
let x = if y { 0 } else { 1 };
|
2020-05-21 14:49:38 -05:00
|
|
|
let x = match x {
|
|
|
|
0 => 1,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
if let Some(x) = Some(x) { x } else { 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 14:49:38 -05:00
|
|
|
fn main() {
|
2019-11-17 23:11:42 -06:00
|
|
|
let _ = [0; {
|
|
|
|
let x = if false { 0 } else { 1 };
|
2020-05-21 14:49:38 -05:00
|
|
|
let x = match x {
|
|
|
|
0 => 1,
|
|
|
|
_ => 0,
|
|
|
|
};
|
2019-11-17 23:11:42 -06:00
|
|
|
if let Some(x) = Some(x) { x } else { 1 }
|
|
|
|
}];
|
|
|
|
}
|