// 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;
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,
MiscBinaryOp,
MiscCatchAll,
+
+ IndexOpFeatureGated,
}
impl ConstEvalErr {
MiscBinaryOp => "bad operands for binary".into_cow(),
MiscCatchAll => "unsupported constant expr".into_cow(),
+ IndexOpFeatureGated => "the index operation on const values is unstable".into_cow(),
}
}
}
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
--- /dev/null
+// 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() {
+}
#![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;
let n = 1i8<<(1isize+-1);
+
+ let n = 1i64 >> [63][0];
+ let n = 1i64 >> [64][0]; //~ ERROR: bitshift exceeds the type's number of bits
}
--- /dev/null
+// 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];
+}