Skip to content

Commit d36302d

Browse files
Add a UI test for rust-lang#50637
This test relies on the fact that restrictions on expressions in `const fn` do not apply when computing array lengths. It is more difficult to statically analyze than the simple `loop{}` mentioned in rust-lang#50637. This test should be updated to ignore the warning after rust-lang#49980 is resolved.
1 parent 10f2171 commit d36302d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(const_let)]
12+
13+
fn main() {
14+
// Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
15+
// The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
16+
let _ = [(); {
17+
//~^ WARNING Constant evaluating a complex constant, this might take some time
18+
//~| ERROR could not evaluate repeat length
19+
let mut n = 113383; // #20 in A006884
20+
while n != 0 { //~ ERROR constant contains unimplemented expression type
21+
n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
22+
}
23+
n
24+
}];
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0019]: constant contains unimplemented expression type
2+
--> $DIR/infinite_loop.rs:20:9
3+
|
4+
LL | / while n != 0 { //~ ERROR constant contains unimplemented expression type
5+
LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
6+
LL | | }
7+
| |_________^
8+
9+
warning: Constant evaluating a complex constant, this might take some time
10+
--> $DIR/infinite_loop.rs:16:18
11+
|
12+
LL | let _ = [(); {
13+
| __________________^
14+
LL | | //~^ WARNING Constant evaluating a complex constant, this might take some time
15+
LL | | //~| ERROR could not evaluate repeat length
16+
LL | | let mut n = 113383; // #20 in A006884
17+
... |
18+
LL | | n
19+
LL | | }];
20+
| |_____^
21+
22+
error[E0080]: could not evaluate repeat length
23+
--> $DIR/infinite_loop.rs:16:18
24+
|
25+
LL | let _ = [(); {
26+
| __________________^
27+
LL | | //~^ WARNING Constant evaluating a complex constant, this might take some time
28+
LL | | //~| ERROR could not evaluate repeat length
29+
LL | | let mut n = 113383; // #20 in A006884
30+
LL | | while n != 0 { //~ ERROR constant contains unimplemented expression type
31+
LL | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
32+
| | ---------- program will never terminate
33+
LL | | }
34+
LL | | n
35+
LL | | }];
36+
| |_____^
37+
38+
error: aborting due to 2 previous errors
39+
40+
Some errors occurred: E0019, E0080.
41+
For more information about an error, try `rustc --explain E0019`.

0 commit comments

Comments
 (0)