File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
src/test/ui/consts/control-flow Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1
1
#![ feature( const_if_match) ]
2
+ #![ feature( const_loop) ]
2
3
3
4
// `x` is *not* always moved into the final value may be dropped inside the initializer.
4
5
const _: Option < Vec < i32 > > = {
@@ -32,4 +33,27 @@ const _: Vec<i32> = {
32
33
}
33
34
} ;
34
35
36
+ const _: Option < Vec < i32 > > = {
37
+ let mut some = Some ( Vec :: new ( ) ) ;
38
+ let mut tmp = None ;
39
+ //~^ ERROR destructors cannot be evaluated at compile-time
40
+
41
+ let mut i = 0 ;
42
+ while i < 10 {
43
+ tmp = some;
44
+ some = None ;
45
+
46
+ if i > 100 {
47
+ break ;
48
+ }
49
+
50
+ some = tmp;
51
+ tmp = None ;
52
+
53
+ i += 1 ;
54
+ }
55
+
56
+ some
57
+ } ;
58
+
35
59
fn main ( ) { }
Original file line number Diff line number Diff line change 1
1
// run-pass
2
2
3
3
#![ feature( const_if_match) ]
4
+ #![ feature( const_loop) ]
4
5
5
6
// `x` is always moved into the final value and is not dropped inside the initializer.
6
7
const _: Option < Vec < i32 > > = {
@@ -21,4 +22,24 @@ const _: Option<Vec<i32>> = {
21
22
}
22
23
} ;
23
24
25
+ const _: Option < Vec < i32 > > = {
26
+ let mut some = Some ( Vec :: new ( ) ) ;
27
+ let mut tmp = None ;
28
+
29
+ let mut i = 0 ;
30
+ while i < 10 {
31
+ tmp = some;
32
+ some = None ;
33
+
34
+ // We can never exit the loop with `Some` in `tmp`.
35
+
36
+ some = tmp;
37
+ tmp = None ;
38
+
39
+ i += 1 ;
40
+ }
41
+
42
+ some
43
+ } ;
44
+
24
45
fn main ( ) { }
Original file line number Diff line number Diff line change 2
2
// disqualifies it from promotion.
3
3
4
4
#![ feature( const_if_match) ]
5
+ #![ feature( const_loop) ]
5
6
6
7
use std:: cell:: Cell ;
7
8
@@ -21,7 +22,22 @@ const Y: Option<Cell<i32>> = {
21
22
y
22
23
} ;
23
24
25
+ const Z : Option < Cell < i32 > > = {
26
+ let mut z = None ;
27
+ let mut i = 0 ;
28
+ while i < 10 {
29
+ if i == 8 {
30
+ z = Some ( Cell :: new ( 4 ) ) ;
31
+ }
32
+
33
+ i += 1 ;
34
+ }
35
+ z
36
+ } ;
37
+
38
+
24
39
fn main ( ) {
25
40
let x: & ' static _ = & X ; //~ ERROR temporary value dropped while borrowed
26
41
let y: & ' static _ = & Y ; //~ ERROR temporary value dropped while borrowed
42
+ let z: & ' static _ = & Z ; //~ ERROR temporary value dropped while borrowed
27
43
}
You can’t perform that action at this time.
0 commit comments