about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2015-11-20 10:43:04 +0100
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2015-11-20 10:43:04 +0100
commit64051221b624ef35a449213bc54dc631ffa8a65b (patch)
treecb9f0c51f30ef28ef479407f52a708c4373e54cd
parent6683fa4d425d3ca2f2ba6b5a48dc073956ad0f13 (diff)
downloadrust-64051221b624ef35a449213bc54dc631ffa8a65b.tar.gz
rust-64051221b624ef35a449213bc54dc631ffa8a65b.zip
add feature gate `const_indexing`
tracking issue is #29947
-rw-r--r--src/librustc/middle/const_eval.rs11
-rw-r--r--src/libsyntax/feature_gate.rs6
-rw-r--r--src/test/compile-fail/const-array-oob-arith.rs2
-rw-r--r--src/test/compile-fail/const-array-oob.rs2
-rw-r--r--src/test/run-pass/array_const_index-1.rs1
5 files changed, 22 insertions, 0 deletions
diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs
index f90fdd1d4b3..90c1cfda262 100644
--- a/src/librustc/middle/const_eval.rs
+++ b/src/librustc/middle/const_eval.rs
@@ -1137,6 +1137,17 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
       hir::ExprTup(_) => Tuple(e.id),
       hir::ExprStruct(..) => Struct(e.id),
       hir::ExprIndex(ref arr, ref idx) => {
+        if !tcx.sess.features.borrow().const_indexing {
+            tcx.sess.span_err(
+                e.span,
+                "const indexing is an unstable feature");
+            fileline_help!(
+                tcx.sess,
+                e.span,
+                "in Nightly builds, add `#![feature(const_indexing)]` to the crate \
+                 attributes to enable");
+            signal!(e, NonConstPath)
+        }
         let arr_hint = if let ExprTypeChecked = ty_hint {
             ExprTypeChecked
         } else {
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 64429336562..0dbd69c0da6 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -179,6 +179,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
     // Allows the definition of `const fn` functions.
     ("const_fn", "1.2.0", Some(24111), Active),
 
+    // Allows indexing into constant arrays.
+    ("const_indexing", "1.4.0", Some(29947), Active),
+
     // Allows using #[prelude_import] on glob `use` items.
     //
     // rustc internal
@@ -494,6 +497,7 @@ pub struct Features {
     /// #![feature] attrs for non-language (library) features
     pub declared_lib_features: Vec<(InternedString, Span)>,
     pub const_fn: bool,
+    pub const_indexing: bool,
     pub static_recursion: bool,
     pub default_type_parameter_fallback: bool,
     pub type_macros: bool,
@@ -525,6 +529,7 @@ impl Features {
             declared_stable_lang_features: Vec::new(),
             declared_lib_features: Vec::new(),
             const_fn: false,
+            const_indexing: false,
             static_recursion: false,
             default_type_parameter_fallback: false,
             type_macros: false,
@@ -1097,6 +1102,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
         declared_stable_lang_features: accepted_features,
         declared_lib_features: unknown_features,
         const_fn: cx.has_feature("const_fn"),
+        const_indexing: cx.has_feature("const_indexing"),
         static_recursion: cx.has_feature("static_recursion"),
         default_type_parameter_fallback: cx.has_feature("default_type_parameter_fallback"),
         type_macros: cx.has_feature("type_macros"),
diff --git a/src/test/compile-fail/const-array-oob-arith.rs b/src/test/compile-fail/const-array-oob-arith.rs
index bca3cd74d24..9c07abdc36d 100644
--- a/src/test/compile-fail/const-array-oob-arith.rs
+++ b/src/test/compile-fail/const-array-oob-arith.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(const_indexing)]
+
 const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];
 const IDX: usize = 3;
 const VAL: i32 = ARR[IDX];
diff --git a/src/test/compile-fail/const-array-oob.rs b/src/test/compile-fail/const-array-oob.rs
index da9f6bd247e..15426febbcd 100644
--- a/src/test/compile-fail/const-array-oob.rs
+++ b/src/test/compile-fail/const-array-oob.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(const_indexing)]
+
 const FOO: [u32; 3] = [1, 2, 3];
 const BAR: u32 = FOO[5]; // no error, because the error below occurs before regular const eval
 
diff --git a/src/test/run-pass/array_const_index-1.rs b/src/test/run-pass/array_const_index-1.rs
index 63f0a844880..3e4504eb195 100644
--- a/src/test/run-pass/array_const_index-1.rs
+++ b/src/test/run-pass/array_const_index-1.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(const_indexing)]
 
 fn main() {
     const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];