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 11#![ feature( const_if_match) ]
2+ #![ feature( const_loop) ]
23
34// `x` is *not* always moved into the final value may be dropped inside the initializer.
45const _: Option < Vec < i32 > > = {
@@ -32,4 +33,27 @@ const _: Vec<i32> = {
3233 }
3334} ;
3435
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+
3559fn main ( ) { }
Original file line number Diff line number Diff line change 11// run-pass
22
33#![ feature( const_if_match) ]
4+ #![ feature( const_loop) ]
45
56// `x` is always moved into the final value and is not dropped inside the initializer.
67const _: Option < Vec < i32 > > = {
@@ -21,4 +22,24 @@ const _: Option<Vec<i32>> = {
2122 }
2223} ;
2324
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+
2445fn main ( ) { }
Original file line number Diff line number Diff line change 22// disqualifies it from promotion.
33
44#![ feature( const_if_match) ]
5+ #![ feature( const_loop) ]
56
67use std:: cell:: Cell ;
78
@@ -21,7 +22,22 @@ const Y: Option<Cell<i32>> = {
2122 y
2223} ;
2324
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+
2439fn main ( ) {
2540 let x: & ' static _ = & X ; //~ ERROR temporary value dropped while borrowed
2641 let y: & ' static _ = & Y ; //~ ERROR temporary value dropped while borrowed
42+ let z: & ' static _ = & Z ; //~ ERROR temporary value dropped while borrowed
2743}
You can’t perform that action at this time.
0 commit comments