blob: 374349732f9ef6bc0286139e61b65706967fb12d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//@ build-pass
// issue 122301 - currently the only way to supress
// const eval and codegen of code conditional on some other const
struct Foo<T, const N: usize>(T);
impl<T, const N: usize> Foo<T, N> {
const BAR: () = if N == 0 {
panic!()
};
}
struct Invoke<T, const N: usize>(T);
impl<T, const N: usize> Invoke<T, N> {
const FUN: fn() = if N != 0 {
|| Foo::<T, N>::BAR
} else {
|| {}
};
}
// without closures
struct S<T>(T);
impl<T> S<T> {
const C: () = panic!();
}
const fn bar<T>() { S::<T>::C }
struct ConstIf<T, const N: usize>(T);
impl<T, const N: usize> ConstIf<T, N> {
const VAL: () = if N != 0 {
bar::<T>() // not called for N == 0, and hence not monomorphized
} else {
()
};
}
fn main() {
let _val = Invoke::<(), 0>::FUN();
let _val = ConstIf::<(), 0>::VAL;
}
|