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:
Christoph Schmidler 2019-12-13 09:38:07 +01:00
parent 337af5ef7a
commit ff38babc31
4 changed files with 40 additions and 8 deletions

View File

@ -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(

View 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
}

View 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
}

View File

@ -3,7 +3,9 @@
const CONSTANT: usize = limit();
fn main() {}
fn main() {
assert_eq!(CONSTANT, 1764);
}
const fn limit() -> usize {
let x = 42;