]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/typeck/coherence.rs
Doc says to avoid mixing allocator instead of forbiding it
[rust.git] / src / librustc / middle / typeck / coherence.rs
index 3dee787b6c9064edea7f3507a25dd933427dcf7e..8de17627e28253be2921a28607c2b3fbeb40cfbc 100644 (file)
@@ -23,7 +23,7 @@
 use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId};
 use middle::ty::{lookup_item_type};
 use middle::ty::{t, ty_bool, ty_char, ty_bot, ty_box, ty_enum, ty_err};
-use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_nil};
+use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_nil, ty_open};
 use middle::ty::{ty_param, Polytype, ty_ptr};
 use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup};
 use middle::ty::{ty_uint, ty_unboxed_closure, ty_uniq, ty_bare_fn};
@@ -86,7 +86,7 @@ fn get_base_type(inference_context: &InferCtxt,
 
         ty_nil | ty_bot | ty_bool | ty_char | ty_int(..) | ty_uint(..) | ty_float(..) |
         ty_str(..) | ty_vec(..) | ty_bare_fn(..) | ty_closure(..) | ty_tup(..) |
-        ty_infer(..) | ty_param(..) | ty_err |
+        ty_infer(..) | ty_param(..) | ty_err | ty_open(..) |
         ty_box(_) | ty_uniq(_) | ty_ptr(_) | ty_rptr(_, _) => {
             debug!("(getting base type) no base type; found {:?}",
                    get(original_type).sty);
@@ -157,15 +157,22 @@ fn get_base_type_def_id(inference_context: &InferCtxt,
                 ty_unboxed_closure(def_id, _) => {
                     Some(def_id)
                 }
-                ty_rptr(_, ty::mt {ty, ..}) | ty_uniq(ty) => match ty::get(ty).sty {
-                    ty_trait(box ty::TyTrait { def_id, .. }) => {
-                        Some(def_id)
-                    }
-                    _ => {
-                        fail!("get_base_type() returned a type that wasn't an \
-                               enum, struct, or trait");
+                ty_ptr(ty::mt {ty, ..}) |
+                ty_rptr(_, ty::mt {ty, ..}) |
+                ty_uniq(ty) => {
+                    match ty::get(ty).sty {
+                        ty_trait(box ty::TyTrait { def_id, .. }) => {
+                            Some(def_id)
+                        }
+                        _ => {
+                            fail!("get_base_type() returned a type that wasn't an \
+                                   enum, struct, or trait");
+                        }
                     }
-                },
+                }
+                ty_trait(box ty::TyTrait { def_id, .. }) => {
+                    Some(def_id)
+                }
                 _ => {
                     fail!("get_base_type() returned a type that wasn't an \
                            enum, struct, or trait");
@@ -175,17 +182,17 @@ fn get_base_type_def_id(inference_context: &InferCtxt,
     }
 }
 
-struct CoherenceChecker<'a> {
-    crate_context: &'a CrateCtxt<'a>,
-    inference_context: InferCtxt<'a>,
+struct CoherenceChecker<'a, 'tcx: 'a> {
+    crate_context: &'a CrateCtxt<'a, 'tcx>,
+    inference_context: InferCtxt<'a, 'tcx>,
 }
 
-struct CoherenceCheckVisitor<'a> {
-    cc: &'a CoherenceChecker<'a>
+struct CoherenceCheckVisitor<'a, 'tcx: 'a> {
+    cc: &'a CoherenceChecker<'a, 'tcx>
 }
 
-impl<'a> visit::Visitor<()> for CoherenceCheckVisitor<'a> {
-    fn visit_item(&mut self, item: &Item, _: ()) {
+impl<'a, 'tcx, 'v> visit::Visitor<'v> for CoherenceCheckVisitor<'a, 'tcx> {
+    fn visit_item(&mut self, item: &Item) {
 
         //debug!("(checking coherence) item '{}'", token::get_ident(item.ident));
 
@@ -203,19 +210,21 @@ fn visit_item(&mut self, item: &Item, _: ()) {
             }
         };
 
-        visit::walk_item(self, item, ());
+        visit::walk_item(self, item);
     }
 }
 
-struct PrivilegedScopeVisitor<'a> { cc: &'a CoherenceChecker<'a> }
+struct PrivilegedScopeVisitor<'a, 'tcx: 'a> {
+    cc: &'a CoherenceChecker<'a, 'tcx>
+}
 
-impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> {
-    fn visit_item(&mut self, item: &Item, _: ()) {
+impl<'a, 'tcx, 'v> visit::Visitor<'v> for PrivilegedScopeVisitor<'a, 'tcx> {
+    fn visit_item(&mut self, item: &Item) {
 
         match item.node {
             ItemMod(ref module_) => {
                 // Then visit the module items.
-                visit::walk_mod(self, module_, ());
+                visit::walk_mod(self, module_);
             }
             ItemImpl(_, None, ref ast_ty, _) => {
                 if !self.cc.ast_type_is_defined_in_local_crate(&**ast_ty) {
@@ -247,22 +256,22 @@ fn visit_item(&mut self, item: &Item, _: ()) {
                     }
                 }
 
-                visit::walk_item(self, item, ());
+                visit::walk_item(self, item);
             }
             _ => {
-                visit::walk_item(self, item, ());
+                visit::walk_item(self, item);
             }
         }
     }
 }
 
-impl<'a> CoherenceChecker<'a> {
+impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
     fn check(&self, krate: &Crate) {
         // Check implementations and traits. This populates the tables
         // containing the inherent methods and extension methods. It also
         // builds up the trait inheritance table.
         let mut visitor = CoherenceCheckVisitor { cc: self };
-        visit::walk_crate(&mut visitor, krate, ());
+        visit::walk_crate(&mut visitor, krate);
 
         // Check that there are no overlapping trait instances
         self.check_implementation_coherence();
@@ -534,7 +543,7 @@ fn get_self_type_for_implementation(&self, impl_did: DefId)
     // Privileged scope checking
     fn check_privileged_scopes(&self, krate: &Crate) {
         let mut visitor = PrivilegedScopeVisitor{ cc: self };
-        visit::walk_crate(&mut visitor, krate, ());
+        visit::walk_crate(&mut visitor, krate);
     }
 
     fn trait_ref_to_trait_def_id(&self, trait_ref: &TraitRef) -> DefId {
@@ -588,7 +597,7 @@ fn create_impl_from_item(&self, item: &Item) -> Vec<ImplOrTraitItemId> {
                         ast_items.iter()
                                  .map(|ast_item| {
                             match *ast_item {
-                                ast::MethodImplItem(ast_method) => {
+                                ast::MethodImplItem(ref ast_method) => {
                                     MethodTraitItemId(
                                         local_def(ast_method.id))
                                 }
@@ -811,9 +820,9 @@ fn subst_receiver_types_in_method_ty(tcx: &ty::ctxt,
     )
 }
 
-pub fn check_coherence(crate_context: &CrateCtxt, krate: &Crate) {
+pub fn check_coherence(crate_context: &CrateCtxt) {
     CoherenceChecker {
         crate_context: crate_context,
         inference_context: new_infer_ctxt(crate_context.tcx),
-    }.check(krate);
+    }.check(crate_context.tcx.map.krate());
 }