-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e15c486
commit 044dc6e
Showing
7 changed files
with
46 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
// check-pass | ||
|
||
#![feature(const_eval_limit)] | ||
#![const_eval_limit="1000"] | ||
#![feature(const_loop, const_if_match)] | ||
|
||
const CONSTANT: usize = limit(); | ||
// This needs to be higher than the number of loop iterations since each pass through the loop may | ||
// hit more than one terminator. | ||
#![const_eval_limit="4000"] | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
const X: usize = { | ||
let mut x = 0; | ||
while x != 1000 { | ||
x += 1; | ||
} | ||
|
||
const fn limit() -> usize { | ||
let x = 42; | ||
x | ||
}; | ||
|
||
x * 42 | ||
fn main() { | ||
assert_eq!(X, 1000); | ||
} |
27 changes: 12 additions & 15 deletions
27
src/test/ui/consts/const_limit/const_eval_limit_reached.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
// ignore-tidy-linelength | ||
// only-x86_64 | ||
// check-pass | ||
// NOTE: We always compile this test with -Copt-level=0 because higher opt-levels | ||
// optimize away the const function | ||
// compile-flags:-Copt-level=0 | ||
#![feature(const_eval_limit)] | ||
#![const_eval_limit="2"] | ||
#![feature(const_loop, const_if_match)] | ||
|
||
const CONSTANT: usize = limit(); | ||
//~^ WARNING Constant evaluating a complex constant, this might take some time | ||
#![const_eval_limit="500"] | ||
|
||
fn main() { | ||
assert_eq!(CONSTANT, 1764); | ||
} | ||
const X: usize = { | ||
let mut x = 0; | ||
while x != 1000 { | ||
//~^ ERROR any use of this value will cause an error | ||
x += 1; | ||
} | ||
|
||
const fn limit() -> usize { //~ WARNING Constant evaluating a complex constant, this might take some time | ||
let x = 42; | ||
x | ||
}; | ||
|
||
x * 42 | ||
fn main() { | ||
assert_eq!(X, 1000); | ||
} |
25 changes: 13 additions & 12 deletions
25
src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
warning: Constant evaluating a complex constant, this might take some time | ||
--> $DIR/const_eval_limit_reached.rs:17:1 | ||
error: any use of this value will cause an error | ||
--> $DIR/const_eval_limit_reached.rs:8:11 | ||
| | ||
LL | / const fn limit() -> usize { | ||
LL | | let x = 42; | ||
LL | / const X: usize = { | ||
LL | | let mut x = 0; | ||
LL | | while x != 1000 { | ||
| | ^^^^^^^^^ exceeded interpreter time limit | ||
LL | | | ||
LL | | x * 42 | ||
LL | | } | ||
| |_^ | ||
|
||
warning: Constant evaluating a complex constant, this might take some time | ||
--> $DIR/const_eval_limit_reached.rs:10:1 | ||
... | | ||
LL | | x | ||
LL | | }; | ||
| |__- | ||
| | ||
LL | const CONSTANT: usize = limit(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to previous error | ||
|