]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/check_static.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / librustc / middle / check_static.rs
index e80c60ad015d834231628b35d5ea1c85456d9526..763c1abdc7394ec169a6538b2b4dd022035a76f0 100644 (file)
 // - For each *immutable* static item, it checks that its **value**:
 //       - doesn't own owned, managed pointers
 //       - doesn't contain a struct literal or a call to an enum variant / struct constructor where
-//           - the type of the struct/enum is not freeze
 //           - the type of the struct/enum has a dtor
+//
+// Rules Enforced Elsewhere:
+// - It's not possible to take the address of a static item with unsafe interior. This is enforced
+// by borrowck::gather_loans
 
 use middle::ty;
 
@@ -107,6 +110,10 @@ fn visit_expr(&mut self, e: &ast::Expr, is_const: bool) {
             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");
@@ -117,21 +124,6 @@ fn visit_expr(&mut self, e: &ast::Expr, is_const: bool) {
                 self.tcx.sess.span_err(e.span,
                                    "static items are not allowed to have owned pointers");
             }
-            ast::ExprProc(..) => {
-                self.report_error(e.span,
-                                  Some(~"immutable static items must be `Freeze`"));
-                return;
-            }
-            ast::ExprAddrOf(mutability, _) => {
-                match mutability {
-                    ast::MutMutable => {
-                        self.report_error(e.span,
-                                  Some(~"immutable static items must be `Freeze`"));
-                        return;
-                    }
-                    _ => {}
-                }
-            }
             _ => {
                 let node_ty = ty::node_id_to_type(self.tcx, e.id);
 
@@ -140,12 +132,7 @@ fn visit_expr(&mut self, e: &ast::Expr, is_const: bool) {
                     ty::ty_enum(did, _) => {
                         if ty::has_dtor(self.tcx, did) {
                             self.report_error(e.span,
-                                     Some(~"static items are not allowed to have destructors"));
-                            return;
-                        }
-                        if Some(did) == self.tcx.lang_items.no_freeze_bound() {
-                            self.report_error(e.span,
-                                              Some(~"immutable static items must be `Freeze`"));
+                             Some("static items are not allowed to have destructors".to_owned()));
                             return;
                         }
                     }