Commit fefd06d 1 parent 3cbb932 commit fefd06d Copy full SHA for fefd06d
File tree 1 file changed +46
-0
lines changed
tests/ui/consts/control-flow
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments