Disable CTFE if const_limit was set to 0, otherwise use the value set, which defaults to 1_000_000
This commit is contained in:
parent
337af5ef7a
commit
ff38babc31
@ -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(
|
||||
|
15
src/test/ui/consts/const_limit/const_limit_not_reached.rs
Normal file
15
src/test/ui/consts/const_limit/const_limit_not_reached.rs
Normal file
@ -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
|
||||
}
|
15
src/test/ui/consts/const_limit/const_limit_overflow.rs
Normal file
15
src/test/ui/consts/const_limit/const_limit_overflow.rs
Normal file
@ -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
|
||||
}
|
@ -3,7 +3,9 @@
|
||||
|
||||
const CONSTANT: usize = limit();
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
assert_eq!(CONSTANT, 1764);
|
||||
}
|
||||
|
||||
const fn limit() -> usize {
|
||||
let x = 42;
|
||||
|
Loading…
x
Reference in New Issue
Block a user