Skip to content

Commit

Permalink
Bumped version number for const_eval_limit in active.rs
Browse files Browse the repository at this point in the history
and renamed 'recursion_limit' in limits.rs to simple 'limit' because it does handle other limits too.
  • Loading branch information
TheSamsa committed Mar 5, 2020
1 parent c94c74e commit 527456e
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 25 deletions.
14 changes: 6 additions & 8 deletions src/librustc/middle/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ fn update_limit(
return;
}
Err(e) => {
let mut err = sess.struct_span_err(
attr.span,
"`recursion_limit` must be a non-negative integer",
);
let mut err =
sess.struct_span_err(attr.span, "`limit` must be a non-negative integer");

let value_span = attr
.meta()
Expand All @@ -50,11 +48,11 @@ fn update_limit(
.unwrap_or(attr.span);

let error_str = match e.kind() {
IntErrorKind::Overflow => "`recursion_limit` is too large",
IntErrorKind::Empty => "`recursion_limit` must be a non-negative integer",
IntErrorKind::Overflow => "`limit` is too large",
IntErrorKind::Empty => "`limit` must be a non-negative integer",
IntErrorKind::InvalidDigit => "not a valid integer",
IntErrorKind::Underflow => bug!("`recursion_limit` should never underflow"),
IntErrorKind::Zero => bug!("zero is a valid `recursion_limit`"),
IntErrorKind::Underflow => bug!("`limit` should never underflow"),
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
};

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,6 @@ declare_features! (
/// Allows using `&mut` in constant functions.
(active, const_mut_refs, "1.41.0", Some(57349), None),

// Allows limiting the evaluation steps of const expressions
(active, const_eval_limit, "1.41.0", Some(67217), None),

/// Allows the use of `loop` and `while` in constants.
(active, const_loop, "1.41.0", Some(52000), None),

Expand All @@ -555,6 +552,9 @@ declare_features! (
/// Allows the use of `no_sanitize` attribute.
(active, no_sanitize, "1.42.0", Some(39699), None),

// Allows limiting the evaluation steps of const expressions
(active, const_eval_limit, "1.43.0", Some(67217), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-pass
#![feature(const_eval_limit)]
#![const_eval_limit="18_446_744_073_709_551_615"]
//~^ ERROR `limit` must be a non-negative integer

const CONSTANT: usize = limit();

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/consts/const_limit/const_eval_limit_overflow.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: `limit` must be a non-negative integer
--> $DIR/const_eval_limit_overflow.rs:2:1
|
LL | #![const_eval_limit="18_446_744_073_709_551_615"]
| ^^^^^^^^^^^^^^^^^^^^----------------------------^
| |
| not a valid integer

error: aborting due to previous error

6 changes: 5 additions & 1 deletion src/test/ui/consts/const_limit/const_eval_limit_reached.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// 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"]

Expand All @@ -10,7 +14,7 @@ fn main() {
assert_eq!(CONSTANT, 1764);
}

const fn limit() -> usize {
const fn limit() -> usize { //~ WARNING Constant evaluating a complex constant, this might take some time
let x = 42;

x * 42
Expand Down
12 changes: 11 additions & 1 deletion src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
warning: Constant evaluating a complex constant, this might take some time
--> $DIR/const_eval_limit_reached.rs:6:1
--> $DIR/const_eval_limit_reached.rs:17:1
|
LL | / const fn limit() -> usize {
LL | | let x = 42;
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 | const CONSTANT: usize = limit();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/recursion_limit/empty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test the parse error for an empty recursion_limit

#![recursion_limit = ""] //~ ERROR `recursion_limit` must be a non-negative integer
//~| `recursion_limit` must be a non-negative integer
#![recursion_limit = ""] //~ ERROR `limit` must be a non-negative integer
//~| `limit` must be a non-negative integer

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/recursion_limit/empty.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: `recursion_limit` must be a non-negative integer
error: `limit` must be a non-negative integer
--> $DIR/empty.rs:3:1
|
LL | #![recursion_limit = ""]
| ^^^^^^^^^^^^^^^^^^^^^--^
| |
| `recursion_limit` must be a non-negative integer
| `limit` must be a non-negative integer

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/recursion_limit/invalid_digit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test the parse error for an invalid digit in recursion_limit

#![recursion_limit = "-100"] //~ ERROR `recursion_limit` must be a non-negative integer
#![recursion_limit = "-100"] //~ ERROR `limit` must be a non-negative integer
//~| not a valid integer

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/recursion_limit/invalid_digit.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `recursion_limit` must be a non-negative integer
error: `limit` must be a non-negative integer
--> $DIR/invalid_digit.rs:3:1
|
LL | #![recursion_limit = "-100"]
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/recursion_limit/overflow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test the parse error for an overflowing recursion_limit

#![recursion_limit = "999999999999999999999999"]
//~^ ERROR `recursion_limit` must be a non-negative integer
//~| `recursion_limit` is too large
//~^ ERROR `limit` must be a non-negative integer
//~| `limit` is too large

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/recursion_limit/overflow.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: `recursion_limit` must be a non-negative integer
error: `limit` must be a non-negative integer
--> $DIR/overflow.rs:3:1
|
LL | #![recursion_limit = "999999999999999999999999"]
| ^^^^^^^^^^^^^^^^^^^^^--------------------------^
| |
| `recursion_limit` is too large
| `limit` is too large

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/recursion_limit/zero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Test that a `recursion_limit` of 0 is valid
// Test that a `limit` of 0 is valid

#![recursion_limit = "0"]

Expand Down

0 comments on commit 527456e

Please sign in to comment.