]> 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 62f9f512b5dd6d7e0507b43591d94e14fa2e895e..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;
 
@@ -30,7 +33,7 @@
 use syntax::print::pprust;
 
 
-fn safe_type_for_static_mut(cx: ty::ctxt, e: &ast::Expr) -> Option<~str> {
+fn safe_type_for_static_mut(cx: &ty::ctxt, e: &ast::Expr) -> Option<~str> {
     let node_ty = ty::node_id_to_type(cx, e.id);
     let tcontents = ty::type_contents(cx, node_ty);
     debug!("safe_type_for_static_mut(dtor={}, managed={}, owned={})",
@@ -49,16 +52,15 @@ fn safe_type_for_static_mut(cx: ty::ctxt, e: &ast::Expr) -> Option<~str> {
     Some(format!("mutable static items are not allowed to have {}", suffix))
 }
 
-struct CheckStaticVisitor {
-    tcx: ty::ctxt,
+struct CheckStaticVisitor<'a> {
+    tcx: &'a ty::ctxt,
 }
 
-pub fn check_crate(tcx: ty::ctxt, krate: &ast::Crate) {
+pub fn check_crate(tcx: &ty::ctxt, krate: &ast::Crate) {
     visit::walk_crate(&mut CheckStaticVisitor { tcx: tcx }, krate, false)
 }
 
-impl CheckStaticVisitor {
-
+impl<'a> CheckStaticVisitor<'a> {
     fn report_error(&self, span: Span, result: Option<~str>) -> bool {
         match result {
             None => { false }
@@ -70,7 +72,7 @@ fn report_error(&self, span: Span, result: Option<~str>) -> bool {
     }
 }
 
-impl Visitor<bool> for CheckStaticVisitor {
+impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
 
     fn visit_item(&mut self, i: &ast::Item, _is_const: bool) {
         debug!("visit_item(item={})", pprust::item_to_str(i));
@@ -122,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);
 
@@ -145,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;
                         }
                     }