File tree 7 files changed +46
-70
lines changed
7 files changed +46
-70
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ fn main() {
2
2
// Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
3
3
// The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
4
4
let _ = [ ( ) ; {
5
- //~^ WARNING Constant evaluating a complex constant, this might take some time
6
5
let mut n = 113383 ; // #20 in https://oeis.org/A006884
7
6
while n != 0 {
8
7
//~^ ERROR `while` is not allowed in a `const`
Original file line number Diff line number Diff line change 1
1
error[E0658]: `while` is not allowed in a `const`
2
- --> $DIR/infinite_loop.rs:7 :9
2
+ --> $DIR/infinite_loop.rs:6 :9
3
3
|
4
4
LL | / while n != 0 {
5
5
LL | |
@@ -14,32 +14,19 @@ LL | | }
14
14
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
15
15
16
16
error[E0658]: `if` is not allowed in a `const`
17
- --> $DIR/infinite_loop.rs:9 :17
17
+ --> $DIR/infinite_loop.rs:8 :17
18
18
|
19
19
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
20
20
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21
21
|
22
22
= note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
23
23
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
24
24
25
- warning: Constant evaluating a complex constant, this might take some time
26
- --> $DIR/infinite_loop.rs:4:18
27
- |
28
- LL | let _ = [(); {
29
- | __________________^
30
- LL | |
31
- LL | | let mut n = 113383; // #20 in https://oeis.org/A006884
32
- LL | | while n != 0 {
33
- ... |
34
- LL | | n
35
- LL | | }];
36
- | |_____^
37
-
38
25
error[E0080]: evaluation of constant value failed
39
- --> $DIR/infinite_loop.rs:9 :20
26
+ --> $DIR/infinite_loop.rs:8 :20
40
27
|
41
28
LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
42
- | ^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
29
+ | ^^^^^^^^^^ exceeded interpreter time limit
43
30
44
31
error: aborting due to 3 previous errors
45
32
Original file line number Diff line number Diff line change 1
1
fn main ( ) {
2
2
let _ = [ ( ) ; {
3
- //~^ WARNING Constant evaluating a complex constant, this might take some time
4
3
let mut x = & 0 ;
5
4
let mut n = 0 ;
6
5
while n < 5 {
Original file line number Diff line number Diff line change 1
1
error[E0658]: `while` is not allowed in a `const`
2
- --> $DIR/issue-52475.rs:6 :9
2
+ --> $DIR/issue-52475.rs:5 :9
3
3
|
4
4
LL | / while n < 5 {
5
5
LL | |
@@ -12,24 +12,11 @@ LL | | }
12
12
= help: add `#![feature(const_loop)]` to the crate attributes to enable
13
13
= help: add `#![feature(const_if_match)]` to the crate attributes to enable
14
14
15
- warning: Constant evaluating a complex constant, this might take some time
16
- --> $DIR/issue-52475.rs:2:18
17
- |
18
- LL | let _ = [(); {
19
- | __________________^
20
- LL | |
21
- LL | | let mut x = &0;
22
- LL | | let mut n = 0;
23
- ... |
24
- LL | | 0
25
- LL | | }];
26
- | |_____^
27
-
28
15
error[E0080]: evaluation of constant value failed
29
- --> $DIR/issue-52475.rs:8 :17
16
+ --> $DIR/issue-52475.rs:7 :17
30
17
|
31
18
LL | n = (n + 1) % 5;
32
- | ^^^^^^^^^^^ duplicate interpreter state observed here, const evaluation will never terminate
19
+ | ^^^^^^^^^^^ exceeded interpreter time limit
33
20
34
21
error: aborting due to 2 previous errors
35
22
Original file line number Diff line number Diff line change 1
1
// check-pass
2
+
2
3
#![ feature( const_eval_limit) ]
3
- #![ const_eval_limit= "1000" ]
4
+ #![ feature ( const_loop , const_if_match ) ]
4
5
5
- const CONSTANT : usize = limit ( ) ;
6
+ // This needs to be higher than the number of loop iterations since each pass through the loop may
7
+ // hit more than one terminator.
8
+ #![ const_eval_limit="4000" ]
6
9
7
- fn main ( ) {
8
- assert_eq ! ( CONSTANT , 1764 ) ;
9
- }
10
+ const X : usize = {
11
+ let mut x = 0 ;
12
+ while x != 1000 {
13
+ x += 1 ;
14
+ }
10
15
11
- const fn limit ( ) -> usize {
12
- let x = 42 ;
16
+ x
17
+ } ;
13
18
14
- x * 42
19
+ fn main ( ) {
20
+ assert_eq ! ( X , 1000 ) ;
15
21
}
Original file line number Diff line number Diff line change 1
- // ignore-tidy-linelength
2
- // only-x86_64
3
- // check-pass
4
- // NOTE: We always compile this test with -Copt-level=0 because higher opt-levels
5
- // optimize away the const function
6
- // compile-flags:-Copt-level=0
7
1
#![ feature( const_eval_limit) ]
8
- #![ const_eval_limit= "2" ]
2
+ #![ feature ( const_loop , const_if_match ) ]
9
3
10
- const CONSTANT : usize = limit ( ) ;
11
- //~^ WARNING Constant evaluating a complex constant, this might take some time
4
+ #![ const_eval_limit="500" ]
12
5
13
- fn main ( ) {
14
- assert_eq ! ( CONSTANT , 1764 ) ;
15
- }
6
+ const X : usize = {
7
+ let mut x = 0 ;
8
+ while x != 1000 {
9
+ //~^ ERROR any use of this value will cause an error
10
+ x += 1 ;
11
+ }
16
12
17
- const fn limit ( ) -> usize { //~ WARNING Constant evaluating a complex constant, this might take some time
18
- let x = 42 ;
13
+ x
14
+ } ;
19
15
20
- x * 42
16
+ fn main ( ) {
17
+ assert_eq ! ( X , 1000 ) ;
21
18
}
Original file line number Diff line number Diff line change 1
- warning: Constant evaluating a complex constant, this might take some time
2
- --> $DIR/const_eval_limit_reached.rs:17:1
1
+ error: any use of this value will cause an error
2
+ --> $DIR/const_eval_limit_reached.rs:8:11
3
3
|
4
- LL | / const fn limit() -> usize {
5
- LL | | let x = 42;
4
+ LL | / const X: usize = {
5
+ LL | | let mut x = 0;
6
+ LL | | while x != 1000 {
7
+ | | ^^^^^^^^^ exceeded interpreter time limit
6
8
LL | |
7
- LL | | x * 42
8
- LL | | }
9
- | |_^
10
-
11
- warning: Constant evaluating a complex constant, this might take some time
12
- --> $DIR/const_eval_limit_reached.rs:10:1
9
+ ... |
10
+ LL | | x
11
+ LL | | };
12
+ | |__-
13
13
|
14
- LL | const CONSTANT: usize = limit();
15
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
+ = note: `#[deny(const_err)]` on by default
15
+
16
+ error: aborting due to previous error
16
17
You can’t perform that action at this time.
0 commit comments