Skip to content

Commit ff38bab

Browse files
committed
Disable CTFE if const_limit was set to 0, otherwise use the value set, which defaults to 1_000_000
1 parent 337af5e commit ff38bab

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

src/librustc/middle/limits.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Registering limits, recursion_limit, type_length_limit and const_limit
2-
//
3-
// There are various parts of the compiler that must impose arbitrary limits
4-
// on how deeply they recurse to prevent stack overflow. Users can override
5-
// this via an attribute on the crate like `#![recursion_limit="22"]`. This pass
6-
// just peeks and looks for that attribute.
1+
//! Registering limits, recursion_limit, type_length_limit and const_limit
2+
//!
3+
//! There are various parts of the compiler that must impose arbitrary limits
4+
//! on how deeply they recurse to prevent stack overflow. Users can override
5+
//! this via an attribute on the crate like `#![recursion_limit="22"]`. This pass
6+
//! just peeks and looks for that attribute.
77
88
use crate::session::Session;
99
use core::num::IntErrorKind;
@@ -16,7 +16,7 @@ use rustc_data_structures::sync::Once;
1616
pub fn update_limits(sess: &Session, krate: &ast::Crate) {
1717
update_limit(sess, krate, &sess.recursion_limit, sym::recursion_limit, 128);
1818
update_limit(sess, krate, &sess.type_length_limit, sym::type_length_limit, 1048576);
19-
update_limit(sess, krate, &sess.const_limit, sym::const_limit, 128);
19+
update_limit(sess, krate, &sess.const_limit, sym::const_limit, 1_000_000);
2020
}
2121

2222
fn update_limit(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
#![feature(const_limit)]
3+
#![const_limit="1000"]
4+
5+
const CONSTANT: usize = limit();
6+
7+
fn main() {
8+
assert_eq!(CONSTANT, 1764);
9+
}
10+
11+
const fn limit() -> usize {
12+
let x = 42;
13+
14+
x * 42
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
#![feature(const_limit)]
3+
#![const_limit="18_446_744_073_709_551_615"]
4+
5+
const CONSTANT: usize = limit();
6+
7+
fn main() {
8+
assert_eq!(CONSTANT, 1764);
9+
}
10+
11+
const fn limit() -> usize {
12+
let x = 42;
13+
14+
x * 42
15+
}

src/test/ui/consts/const_limit/feature-gate-const_limit.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
const CONSTANT: usize = limit();
55

6-
fn main() {}
6+
fn main() {
7+
assert_eq!(CONSTANT, 1764);
8+
}
79

810
const fn limit() -> usize {
911
let x = 42;

0 commit comments

Comments
 (0)