Skip to content

Commit fefd06d

Browse files
committed
add test for rust-lang#122301 to cover behavior that's on stable
if this ought to be broken it should at least happen intentionally
1 parent 3cbb932 commit fefd06d

File tree

1 file changed

+46
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)