Skip to content

Commit 288e142

Browse files
committed
Add a new test to reach const_limit setting, although with wrong WARNINGs yet
rename feature to const_eval_limit
1 parent ff38bab commit 288e142

File tree

15 files changed

+52
-37
lines changed

15 files changed

+52
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `const_eval_limit`
2+
3+
The tracking issue for this feature is: [#67217]
4+
5+
[#57563]: https://github.com/rust-lang/rust/issues/67217
6+
7+
The `const_eval_limit` allows someone to limit the evaluation steps the CTFE undertakes to evaluate a `const fn`.

src/doc/unstable-book/src/language-features/const-limit.md

-7
This file was deleted.

src/librustc/middle/limits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Registering limits, recursion_limit, type_length_limit and const_limit
1+
//! Registering limits, recursion_limit, type_length_limit and const_eval_limit
22
//!
33
//! There are various parts of the compiler that must impose arbitrary limits
44
//! on how deeply they recurse to prevent stack overflow. Users can override
@@ -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, 1_000_000);
19+
update_limit(sess, krate, &sess.const_eval_limit, sym::const_eval_limit, 1_000_000);
2020
}
2121

2222
fn update_limit(

src/librustc/middle/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub mod lib_features {
2828
}
2929
}
3030
}
31+
pub mod limits;
3132
pub mod privacy;
32-
pub mod recursion_limit;
3333
pub mod region;
3434
pub mod resolve_lifetime;
3535
pub mod stability;

src/librustc_feature/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ declare_features! (
533533
(active, const_mut_refs, "1.41.0", Some(57349), None),
534534

535535
// Allows limiting the evaluation steps of const expressions
536-
(active, const_limit, "1.41.0", Some(67217), None),
536+
(active, const_eval_limit, "1.41.0", Some(67217), None),
537537

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

src/librustc_feature/builtin_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
240240
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
241241
ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")),
242242
gated!(
243-
const_limit, CrateLevel, template!(NameValueStr: "N"), const_limit,
244-
experimental!(const_limit)
243+
const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit,
244+
experimental!(const_eval_limit)
245245
),
246246

247247
// Entry point:

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub fn register_plugins<'a>(
189189
}
190190

191191
sess.time("recursion_limit", || {
192-
middle::recursion_limit::update_limits(sess, &krate);
192+
middle::limits::update_limits(sess, &krate);
193193
});
194194

195195
let mut lint_store = rustc_lint::new_lint_store(

src/librustc_session/session.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub struct Session {
8989
pub type_length_limit: Once<usize>,
9090

9191
/// The maximum blocks a const expression can evaluate.
92-
pub const_limit: Once<usize>,
92+
pub const_eval_limit: Once<usize>,
9393

9494
/// Map from imported macro spans (which consist of
9595
/// the localized span for the macro body) to the
@@ -1056,7 +1056,7 @@ fn build_session_(
10561056
features: Once::new(),
10571057
recursion_limit: Once::new(),
10581058
type_length_limit: Once::new(),
1059-
const_limit: Once::new(),
1059+
const_eval_limit: Once::new(),
10601060
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
10611061
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
10621062
cgu_reuse_tracker,

src/librustc_span/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ symbols! {
208208
console,
209209
const_compare_raw_pointers,
210210
const_constructor,
211-
const_limit,
211+
const_eval_limit,
212212
const_extern_fn,
213213
const_fn,
214214
const_fn_union,

src/test/ui/consts/const_limit/const_limit_overflow.rs renamed to src/test/ui/consts/const_limit/const_eval_limit_not_reached.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// run-pass
2-
#![feature(const_limit)]
3-
#![const_limit="18_446_744_073_709_551_615"]
1+
// check-pass
2+
#![feature(const_eval_limit)]
3+
#![const_eval_limit="1000"]
44

55
const CONSTANT: usize = limit();
66

src/test/ui/consts/const_limit/feature-gate-const_limit.rs renamed to src/test/ui/consts/const_limit/const_eval_limit_overflow.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![const_limit="1"]
2-
//~^ ERROR the `#[const_limit]` attribute is an experimental feature [E0658]
1+
// check-pass
2+
#![feature(const_eval_limit)]
3+
#![const_eval_limit="18_446_744_073_709_551_615"]
34

45
const CONSTANT: usize = limit();
56

src/test/ui/consts/const_limit/const_limit_not_reached.rs renamed to src/test/ui/consts/const_limit/const_eval_limit_reached.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// run-pass
2-
#![feature(const_limit)]
3-
#![const_limit="1000"]
1+
// check-pass
2+
#![feature(const_eval_limit)]
3+
#![const_eval_limit="2"]
44

55
const CONSTANT: usize = limit();
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![const_eval_limit="42"]
2+
//~^ ERROR the `#[const_eval_limit]` attribute is an experimental feature [E0658]
3+
4+
const CONSTANT: usize = limit();
5+
6+
fn main() {
7+
assert_eq!(CONSTANT, 1764);
8+
}
9+
10+
const fn limit() -> usize {
11+
let x = 42;
12+
13+
x * 42
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: the `#[const_eval_limit]` attribute is an experimental feature
2+
--> $DIR/feature-gate-const_eval_limit.rs:1:1
3+
|
4+
LL | #![const_eval_limit="42"]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/67217
8+
= help: add `#![feature(const_eval_limit)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

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

-12
This file was deleted.

0 commit comments

Comments
 (0)