Add a new test to reach const_limit setting, although with wrong WARNINGs yet

rename feature to const_eval_limit
This commit is contained in:
Christoph Schmidler 2019-12-14 18:51:56 +01:00
parent ff38babc31
commit 288e142737
15 changed files with 52 additions and 37 deletions

View file

@ -0,0 +1,7 @@
# `const_eval_limit`
The tracking issue for this feature is: [#67217]
[#57563]: https://github.com/rust-lang/rust/issues/67217
The `const_eval_limit` allows someone to limit the evaluation steps the CTFE undertakes to evaluate a `const fn`.

View file

@ -1,7 +0,0 @@
# `const_limit`
The tracking issue for this feature is: [#67217]
[#57563]: https://github.com/rust-lang/rust/issues/67217
The `const_limit` allows someone to limit the evaluation steps the CTFE undertakes to evaluate a `const fn`.

View file

@ -1,4 +1,4 @@
//! Registering limits, recursion_limit, type_length_limit and const_limit
//! Registering limits, recursion_limit, type_length_limit and const_eval_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
@ -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, 1_000_000);
update_limit(sess, krate, &sess.const_eval_limit, sym::const_eval_limit, 1_000_000);
}
fn update_limit(

View file

@ -28,8 +28,8 @@ pub mod lib_features {
}
}
}
pub mod limits;
pub mod privacy;
pub mod recursion_limit;
pub mod region;
pub mod resolve_lifetime;
pub mod stability;

View file

@ -533,7 +533,7 @@ declare_features! (
(active, const_mut_refs, "1.41.0", Some(57349), None),
// Allows limiting the evaluation steps of const expressions
(active, const_limit, "1.41.0", Some(67217), None),
(active, const_eval_limit, "1.41.0", Some(67217), None),
/// Allows the use of `loop` and `while` in constants.
(active, const_loop, "1.41.0", Some(52000), None),

View file

@ -240,8 +240,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")),
gated!(
const_limit, CrateLevel, template!(NameValueStr: "N"), const_limit,
experimental!(const_limit)
const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit,
experimental!(const_eval_limit)
),
// Entry point:

View file

@ -189,7 +189,7 @@ pub fn register_plugins<'a>(
}
sess.time("recursion_limit", || {
middle::recursion_limit::update_limits(sess, &krate);
middle::limits::update_limits(sess, &krate);
});
let mut lint_store = rustc_lint::new_lint_store(

View file

@ -89,7 +89,7 @@ pub struct Session {
pub type_length_limit: Once<usize>,
/// The maximum blocks a const expression can evaluate.
pub const_limit: Once<usize>,
pub const_eval_limit: Once<usize>,
/// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the
@ -1056,7 +1056,7 @@ fn build_session_(
features: Once::new(),
recursion_limit: Once::new(),
type_length_limit: Once::new(),
const_limit: Once::new(),
const_eval_limit: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
cgu_reuse_tracker,

View file

@ -208,7 +208,7 @@ symbols! {
console,
const_compare_raw_pointers,
const_constructor,
const_limit,
const_eval_limit,
const_extern_fn,
const_fn,
const_fn_union,

View file

@ -1,6 +1,6 @@
// run-pass
#![feature(const_limit)]
#![const_limit="18_446_744_073_709_551_615"]
// check-pass
#![feature(const_eval_limit)]
#![const_eval_limit="1000"]
const CONSTANT: usize = limit();

View file

@ -1,5 +1,6 @@
#![const_limit="1"]
//~^ ERROR the `#[const_limit]` attribute is an experimental feature [E0658]
// check-pass
#![feature(const_eval_limit)]
#![const_eval_limit="18_446_744_073_709_551_615"]
const CONSTANT: usize = limit();

View file

@ -1,6 +1,6 @@
// run-pass
#![feature(const_limit)]
#![const_limit="1000"]
// check-pass
#![feature(const_eval_limit)]
#![const_eval_limit="2"]
const CONSTANT: usize = limit();

View file

@ -0,0 +1,14 @@
#![const_eval_limit="42"]
//~^ ERROR the `#[const_eval_limit]` attribute is an experimental feature [E0658]
const CONSTANT: usize = limit();
fn main() {
assert_eq!(CONSTANT, 1764);
}
const fn limit() -> usize {
let x = 42;
x * 42
}

View file

@ -0,0 +1,12 @@
error[E0658]: the `#[const_eval_limit]` attribute is an experimental feature
--> $DIR/feature-gate-const_eval_limit.rs:1:1
|
LL | #![const_eval_limit="42"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/67217
= help: add `#![feature(const_eval_limit)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,12 +0,0 @@
error[E0658]: the `#[const_limit]` attribute is an experimental feature
--> $DIR/feature-gate-const_limit.rs:1:1
|
LL | #![const_limit="1"]
| ^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/67217
= help: add `#![feature(const_limit)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.