impl Visitor<bool> for CheckCrateVisitor {
fn visit_item(&mut self, i: &Item, env: bool) {
- check_item(self, self.sess, self.def_map, self.method_map,
- self.tcx, i, env)
+ check_item(self, self.sess, self.def_map, i, env);
}
fn visit_pat(&mut self, p: &Pat, env: bool) {
check_pat(self, p, env);
}
fn visit_expr(&mut self, ex: &Expr, env: bool) {
check_expr(self, self.sess, self.def_map, self.method_map,
- self.tcx, ex, env, false);
+ self.tcx, ex, env);
}
}
pub fn check_item(v: &mut CheckCrateVisitor,
sess: Session,
def_map: resolve::DefMap,
- method_map: typeck::method_map,
- tcx: ty::ctxt,
it: &Item,
_is_const: bool) {
match it.node {
- ItemStatic(_, mut_, ex) => {
- check_expr(v, sess, def_map, method_map, tcx, ex, true, mut_ == MutMutable);
+ ItemStatic(_, _, ex) => {
+ v.visit_expr(ex, true);
check_item_recursion(sess, &v.tcx.map, def_map, it);
}
ItemEnum(ref enum_definition, _) => {
method_map: typeck::MethodMap,
tcx: ty::ctxt,
e: &Expr,
- is_const: bool,
- is_static_mut: bool) {
+ is_const: bool) {
if is_const {
match e.node {
ExprUnary(UnDeref, _) => { }
}
}
}
+ ExprVstore(_, ExprVstoreMutSlice) |
ExprVstore(_, ExprVstoreSlice) |
ExprVec(_, MutImmutable) |
ExprAddrOf(MutImmutable, _) |
e.span,
"references in constants may only refer to \
immutable values");
- }
- ExprVstore(_, ExprVstoreMutSlice) => {
- if !is_static_mut {
- sess.span_err(e.span, "mutable slice is not allowed in immutable constants")
- }
},
ExprVstore(_, ExprVstoreUniq) => {
sess.span_err(e.span, "cannot allocate vectors in constant expressions")
ast::ExprVstore(_, ast::ExprVstoreSlice) => {
visit::walk_expr(self, e, is_const);
}
+ ast::ExprVstore(_, ast::ExprVstoreMutSlice) => {
+ self.tcx.sess.span_err(e.span,
+ "static items are not allowed to have mutable slices");
+ },
ast::ExprUnary(ast::UnBox, _) => {
self.tcx.sess.span_err(e.span,
"static items are not allowed to have managed pointers");
(v, inlineable)
}
ast::ExprVstore(sub, store @ ast::ExprVstoreSlice) |
- ast::ExprVstore(sub, store @ ast::ExprVstoreMutSlice) => {
+ ast::ExprVstore(sub, store @ ast::ExprVstoreMutSlice) => {
match sub.node {
ast::ExprLit(ref lit) => {
match lit.node {
--- /dev/null
+// Copyright 2014 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.
+
+// Checks that immutable static items can't have mutable slices
+
+static TEST: &'static mut [int] = &mut [];
+//~^ ERROR static items are not allowed to have mutable slices
+
+pub fn main() { }
+++ /dev/null
-// Copyright 2014 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.
-
-static TEST: &'static mut [int] = &mut []; //~ ERROR mutable slice is not allowed
-
-fn main() { }
--- /dev/null
+// Copyright 2014 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.
+
+// Checks that mutable static items can have mutable slices
+
+static mut TEST: &'static mut [int] = &mut [1];
+
+pub fn main() {
+ unsafe {
+ TEST[0] += 1;
+ assert_eq!(TEST[0], 2);
+ }
+}
+++ /dev/null
-// Copyright 2014 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.
-
-
-static mut TEST: &'static mut [int] = &mut [1];
-
-pub fn main() {
- unsafe {
- TEST[0] += 1;
- }
-}