]> git.lizzy.rs Git - rust.git/commitdiff
fix const index feature-gate regression
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 4 Dec 2015 14:35:07 +0000 (15:35 +0100)
committerOliver 'ker' Schneider <rust19446194516@oli-obk.de>
Sat, 5 Dec 2015 15:52:33 +0000 (16:52 +0100)
src/librustc/middle/check_const.rs
src/librustc/middle/const_eval.rs
src/test/compile-fail/const-index-feature-gate.rs [new file with mode: 0644]
src/test/compile-fail/lint-exceeding-bitshifts.rs
src/test/run-pass/check_const-feature-gated.rs [new file with mode: 0644]

index e29cc04e65a1b3caf83165047a7588fcfc4d9906..69d8dfc361328e10440e8c8e93212e2cedec3e7f 100644 (file)
@@ -25,7 +25,8 @@
 // by borrowck::gather_loans
 
 use middle::ty::cast::{CastKind};
-use middle::const_eval;
+use middle::const_eval::{self, ConstEvalErr};
+use middle::const_eval::ErrKind::IndexOpFeatureGated;
 use middle::const_eval::EvalHint::ExprTypeChecked;
 use middle::def;
 use middle::def_id::DefId;
@@ -477,6 +478,7 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
                             match const_eval::eval_const_expr_partial(
                                     self.tcx, ex, ExprTypeChecked, None) {
                                 Ok(_) => {}
+                                Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
                                 Err(msg) => {
                                     self.tcx.sess.add_lint(::lint::builtin::CONST_ERR, ex.id,
                                                            msg.span,
index 7b1c38d86d2d2a8b0d9f3ed11a23866c3fc95700..ed412463b99e12c613bfbad38ed3732f73fbd468 100644 (file)
@@ -434,6 +434,8 @@ pub enum ErrKind {
 
     MiscBinaryOp,
     MiscCatchAll,
+
+    IndexOpFeatureGated,
 }
 
 impl ConstEvalErr {
@@ -483,6 +485,7 @@ pub fn description(&self) -> Cow<str> {
 
             MiscBinaryOp => "bad operands for binary".into_cow(),
             MiscCatchAll => "unsupported constant expr".into_cow(),
+            IndexOpFeatureGated => "the index operation on const values is unstable".into_cow(),
         }
     }
 }
@@ -1119,15 +1122,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
       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)
+            signal!(e, IndexOpFeatureGated);
         }
         let arr_hint = if let ExprTypeChecked = ty_hint {
             ExprTypeChecked
diff --git a/src/test/compile-fail/const-index-feature-gate.rs b/src/test/compile-fail/const-index-feature-gate.rs
new file mode 100644 (file)
index 0000000..09822e4
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+const ARR: [usize; 1] = [2];
+const ARR2: [i32; ARR[0]] = [5, 6]; //~ ERROR unstable
+
+fn main() {
+}
index 160551b81cb2edfdbaa819424ad7bd07805df760..ce1406e80100ba104b3bde74cae3ba635964a176 100644 (file)
@@ -11,7 +11,7 @@
 #![deny(exceeding_bitshifts)]
 #![allow(unused_variables)]
 #![allow(dead_code)]
-#![feature(num_bits_bytes)]
+#![feature(num_bits_bytes, const_indexing)]
 
 fn main() {
       let n = 1u8 << 7;
@@ -62,4 +62,7 @@ fn main() {
 
 
       let n = 1i8<<(1isize+-1);
+
+      let n = 1i64 >> [63][0];
+      let n = 1i64 >> [64][0]; //~ ERROR: bitshift exceeds the type's number of bits
 }
diff --git a/src/test/run-pass/check_const-feature-gated.rs b/src/test/run-pass/check_const-feature-gated.rs
new file mode 100644 (file)
index 0000000..ae27b76
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+const ARR: [usize; 1] = [2];
+
+fn main() {
+    let _ = 5 << ARR[0];
+}