diff options
| author | Christoph Schmidler <c.schmidler@gmail.com> | 2019-12-13 09:38:07 +0100 |
|---|---|---|
| committer | Christoph Schmidler <c.schmidler@gmail.com> | 2020-03-05 08:09:52 +0100 |
| commit | ff38babc31a364e77d1d4d3702c91884b073af17 (patch) | |
| tree | 7fe623a4dd9265570d0bd9a60a375fc3999b51a5 | |
| parent | 337af5ef7a31855fd7f6d6b77c9e52d6d747c350 (diff) | |
Disable CTFE if const_limit was set to 0, otherwise use the value set, which defaults to 1_000_000
| -rw-r--r-- | src/librustc/middle/limits.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/consts/const_limit/const_limit_not_reached.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/consts/const_limit/const_limit_overflow.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/consts/const_limit/feature-gate-const_limit.rs | 4 |
4 files changed, 40 insertions, 8 deletions
diff --git a/src/librustc/middle/limits.rs b/src/librustc/middle/limits.rs index a831d99d4ed..6ed0a498c7d 100644 --- a/src/librustc/middle/limits.rs +++ b/src/librustc/middle/limits.rs @@ -1,9 +1,9 @@ -// Registering limits, recursion_limit, type_length_limit and const_limit -// -// There are various parts of the compiler that must impose arbitrary limits -// on how deeply they recurse to prevent stack overflow. Users can override -// this via an attribute on the crate like `#![recursion_limit="22"]`. This pass -// just peeks and looks for that attribute. +//! Registering limits, recursion_limit, type_length_limit and const_limit +//! +//! There are various parts of the compiler that must impose arbitrary limits +//! on how deeply they recurse to prevent stack overflow. Users can override +//! this via an attribute on the crate like `#![recursion_limit="22"]`. This pass +//! just peeks and looks for that attribute. use crate::session::Session; use core::num::IntErrorKind; @@ -16,7 +16,7 @@ use rustc_data_structures::sync::Once; pub fn update_limits(sess: &Session, krate: &ast::Crate) { update_limit(sess, krate, &sess.recursion_limit, sym::recursion_limit, 128); update_limit(sess, krate, &sess.type_length_limit, sym::type_length_limit, 1048576); - update_limit(sess, krate, &sess.const_limit, sym::const_limit, 128); + update_limit(sess, krate, &sess.const_limit, sym::const_limit, 1_000_000); } fn update_limit( diff --git a/src/test/ui/consts/const_limit/const_limit_not_reached.rs b/src/test/ui/consts/const_limit/const_limit_not_reached.rs new file mode 100644 index 00000000000..24c0f92af34 --- /dev/null +++ b/src/test/ui/consts/const_limit/const_limit_not_reached.rs @@ -0,0 +1,15 @@ +// run-pass +#![feature(const_limit)] +#![const_limit="1000"] + +const CONSTANT: usize = limit(); + +fn main() { + assert_eq!(CONSTANT, 1764); +} + +const fn limit() -> usize { + let x = 42; + + x * 42 +} diff --git a/src/test/ui/consts/const_limit/const_limit_overflow.rs b/src/test/ui/consts/const_limit/const_limit_overflow.rs new file mode 100644 index 00000000000..bea40e60261 --- /dev/null +++ b/src/test/ui/consts/const_limit/const_limit_overflow.rs @@ -0,0 +1,15 @@ +// run-pass +#![feature(const_limit)] +#![const_limit="18_446_744_073_709_551_615"] + +const CONSTANT: usize = limit(); + +fn main() { + assert_eq!(CONSTANT, 1764); +} + +const fn limit() -> usize { + let x = 42; + + x * 42 +} diff --git a/src/test/ui/consts/const_limit/feature-gate-const_limit.rs b/src/test/ui/consts/const_limit/feature-gate-const_limit.rs index 11d2b6af25d..761e80050a6 100644 --- a/src/test/ui/consts/const_limit/feature-gate-const_limit.rs +++ b/src/test/ui/consts/const_limit/feature-gate-const_limit.rs @@ -3,7 +3,9 @@ const CONSTANT: usize = limit(); -fn main() {} +fn main() { + assert_eq!(CONSTANT, 1764); +} const fn limit() -> usize { let x = 42; |
