]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/ty.rs
rollup merge of #21438: taralx/kill-racycell
[rust.git] / src / librustc / middle / ty.rs
index 11b605e2e2fec57d354cb654926eab62af4f1047..fe6ecd9977494db1be5bf46d43a2255909b29fa9 100644 (file)
@@ -17,7 +17,6 @@
 pub use self::InferRegion::*;
 pub use self::ImplOrTraitItemId::*;
 pub use self::UnboxedClosureKind::*;
-pub use self::TraitStore::*;
 pub use self::ast_ty_to_ty_cache_entry::*;
 pub use self::Variance::*;
 pub use self::AutoAdjustment::*;
@@ -61,7 +60,7 @@
 use middle::ty_fold::{self, TypeFoldable, TypeFolder};
 use middle::ty_walk::TypeWalker;
 use util::ppaux::{note_and_explain_region, bound_region_ptr_to_string};
-use util::ppaux::{trait_store_to_string, ty_to_string};
+use util::ppaux::ty_to_string;
 use util::ppaux::{Repr, UserString};
 use util::common::{memoized, ErrorReported};
 use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
@@ -70,7 +69,7 @@
 use arena::TypedArena;
 use std::borrow::{BorrowFrom, Cow};
 use std::cell::{Cell, RefCell};
-use std::cmp::{self, Ordering};
+use std::cmp;
 use std::fmt::{self, Show};
 use std::hash::{Hash, Writer, SipHasher, Hasher};
 use std::mem;
@@ -247,14 +246,6 @@ pub struct mt<'tcx> {
     pub mutbl: ast::Mutability,
 }
 
-#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show)]
-pub enum TraitStore {
-    /// Box<Trait>
-    UniqTraitStore,
-    /// &Trait and &mut Trait
-    RegionTraitStore(Region, ast::Mutability),
-}
-
 #[derive(Clone, Copy, Show)]
 pub struct field_ty {
     pub name: Name,
@@ -947,13 +938,6 @@ fn eq(&self, other: &TyS<'tcx>) -> bool {
 }
 impl<'tcx> Eq for TyS<'tcx> {}
 
-#[cfg(stage0)]
-impl<'tcx, S: Writer> Hash<S> for TyS<'tcx> {
-    fn hash(&self, s: &mut S) {
-        (self as *const _).hash(s)
-    }
-}
-#[cfg(not(stage0))]
 impl<'tcx, S: Writer + Hasher> Hash<S> for TyS<'tcx> {
     fn hash(&self, s: &mut S) {
         (self as *const _).hash(s)
@@ -1048,11 +1032,8 @@ pub struct BareFnTy<'tcx> {
 #[derive(Clone, PartialEq, Eq, Hash, Show)]
 pub struct ClosureTy<'tcx> {
     pub unsafety: ast::Unsafety,
-    pub onceness: ast::Onceness,
-    pub store: TraitStore,
-    pub bounds: ExistentialBounds<'tcx>,
-    pub sig: PolyFnSig<'tcx>,
     pub abi: abi::Abi,
+    pub sig: PolyFnSig<'tcx>,
 }
 
 #[derive(Clone, Copy, PartialEq, Eq, Hash, Show)]
@@ -1552,7 +1533,6 @@ pub enum type_err<'tcx> {
     terr_onceness_mismatch(expected_found<Onceness>),
     terr_abi_mismatch(expected_found<abi::Abi>),
     terr_mutability,
-    terr_sigil_mismatch(expected_found<TraitStore>),
     terr_box_mutability,
     terr_ptr_mutability,
     terr_ref_mutability,
@@ -1566,7 +1546,6 @@ pub enum type_err<'tcx> {
     terr_regions_no_overlap(Region, Region),
     terr_regions_insufficiently_polymorphic(BoundRegion, Region),
     terr_regions_overly_polymorphic(BoundRegion, Region),
-    terr_trait_stores_differ(terr_vstore_kind, expected_found<TraitStore>),
     terr_sorts(expected_found<Ty<'tcx>>),
     terr_integer_as_char,
     terr_int_mismatch(expected_found<IntVarValue>),
@@ -1891,7 +1870,7 @@ pub fn def_id(&self) -> ast::DefId {
 /// normal trait predicate (`T : TraitRef<...>`) and one of these
 /// predicates. Form #2 is a broader form in that it also permits
 /// equality between arbitrary types. Processing an instance of Form
-/// \#2 eventually yields one of these `ProjectionPredicate`
+/// #2 eventually yields one of these `ProjectionPredicate`
 /// instances to normalize the LHS.
 #[derive(Clone, PartialEq, Eq, Hash, Show)]
 pub struct ProjectionPredicate<'tcx> {
@@ -2369,71 +2348,71 @@ pub fn mk_ctxt<'tcx>(s: Session,
                      lang_items: middle::lang_items::LanguageItems,
                      stability: stability::Index) -> ctxt<'tcx>
 {
-    let mut interner = FnvHashMap::new();
+    let mut interner = FnvHashMap();
     let common_types = CommonTypes::new(&arenas.type_, &mut interner);
 
     ctxt {
         arenas: arenas,
         interner: RefCell::new(interner),
-        substs_interner: RefCell::new(FnvHashMap::new()),
-        bare_fn_interner: RefCell::new(FnvHashMap::new()),
-        region_interner: RefCell::new(FnvHashMap::new()),
+        substs_interner: RefCell::new(FnvHashMap()),
+        bare_fn_interner: RefCell::new(FnvHashMap()),
+        region_interner: RefCell::new(FnvHashMap()),
         types: common_types,
         named_region_map: named_region_map,
-        item_variance_map: RefCell::new(DefIdMap::new()),
+        item_variance_map: RefCell::new(DefIdMap()),
         variance_computed: Cell::new(false),
         sess: s,
         def_map: dm,
         region_maps: region_maps,
-        node_types: RefCell::new(FnvHashMap::new()),
-        item_substs: RefCell::new(NodeMap::new()),
-        trait_refs: RefCell::new(NodeMap::new()),
-        trait_defs: RefCell::new(DefIdMap::new()),
-        object_cast_map: RefCell::new(NodeMap::new()),
+        node_types: RefCell::new(FnvHashMap()),
+        item_substs: RefCell::new(NodeMap()),
+        trait_refs: RefCell::new(NodeMap()),
+        trait_defs: RefCell::new(DefIdMap()),
+        object_cast_map: RefCell::new(NodeMap()),
         map: map,
-        intrinsic_defs: RefCell::new(DefIdMap::new()),
+        intrinsic_defs: RefCell::new(DefIdMap()),
         freevars: freevars,
-        tcache: RefCell::new(DefIdMap::new()),
-        rcache: RefCell::new(FnvHashMap::new()),
-        short_names_cache: RefCell::new(FnvHashMap::new()),
-        tc_cache: RefCell::new(FnvHashMap::new()),
-        ast_ty_to_ty_cache: RefCell::new(NodeMap::new()),
-        enum_var_cache: RefCell::new(DefIdMap::new()),
-        impl_or_trait_items: RefCell::new(DefIdMap::new()),
-        trait_item_def_ids: RefCell::new(DefIdMap::new()),
-        trait_items_cache: RefCell::new(DefIdMap::new()),
-        impl_trait_cache: RefCell::new(DefIdMap::new()),
-        ty_param_defs: RefCell::new(NodeMap::new()),
-        adjustments: RefCell::new(NodeMap::new()),
-        normalized_cache: RefCell::new(FnvHashMap::new()),
+        tcache: RefCell::new(DefIdMap()),
+        rcache: RefCell::new(FnvHashMap()),
+        short_names_cache: RefCell::new(FnvHashMap()),
+        tc_cache: RefCell::new(FnvHashMap()),
+        ast_ty_to_ty_cache: RefCell::new(NodeMap()),
+        enum_var_cache: RefCell::new(DefIdMap()),
+        impl_or_trait_items: RefCell::new(DefIdMap()),
+        trait_item_def_ids: RefCell::new(DefIdMap()),
+        trait_items_cache: RefCell::new(DefIdMap()),
+        impl_trait_cache: RefCell::new(DefIdMap()),
+        ty_param_defs: RefCell::new(NodeMap()),
+        adjustments: RefCell::new(NodeMap()),
+        normalized_cache: RefCell::new(FnvHashMap()),
         lang_items: lang_items,
-        provided_method_sources: RefCell::new(DefIdMap::new()),
-        struct_fields: RefCell::new(DefIdMap::new()),
-        destructor_for_type: RefCell::new(DefIdMap::new()),
-        destructors: RefCell::new(DefIdSet::new()),
-        trait_impls: RefCell::new(DefIdMap::new()),
-        inherent_impls: RefCell::new(DefIdMap::new()),
-        impl_items: RefCell::new(DefIdMap::new()),
-        used_unsafe: RefCell::new(NodeSet::new()),
-        used_mut_nodes: RefCell::new(NodeSet::new()),
-        populated_external_types: RefCell::new(DefIdSet::new()),
-        populated_external_traits: RefCell::new(DefIdSet::new()),
-        upvar_borrow_map: RefCell::new(FnvHashMap::new()),
-        extern_const_statics: RefCell::new(DefIdMap::new()),
-        extern_const_variants: RefCell::new(DefIdMap::new()),
-        method_map: RefCell::new(FnvHashMap::new()),
-        dependency_formats: RefCell::new(FnvHashMap::new()),
-        unboxed_closures: RefCell::new(DefIdMap::new()),
-        node_lint_levels: RefCell::new(FnvHashMap::new()),
+        provided_method_sources: RefCell::new(DefIdMap()),
+        struct_fields: RefCell::new(DefIdMap()),
+        destructor_for_type: RefCell::new(DefIdMap()),
+        destructors: RefCell::new(DefIdSet()),
+        trait_impls: RefCell::new(DefIdMap()),
+        inherent_impls: RefCell::new(DefIdMap()),
+        impl_items: RefCell::new(DefIdMap()),
+        used_unsafe: RefCell::new(NodeSet()),
+        used_mut_nodes: RefCell::new(NodeSet()),
+        populated_external_types: RefCell::new(DefIdSet()),
+        populated_external_traits: RefCell::new(DefIdSet()),
+        upvar_borrow_map: RefCell::new(FnvHashMap()),
+        extern_const_statics: RefCell::new(DefIdMap()),
+        extern_const_variants: RefCell::new(DefIdMap()),
+        method_map: RefCell::new(FnvHashMap()),
+        dependency_formats: RefCell::new(FnvHashMap()),
+        unboxed_closures: RefCell::new(DefIdMap()),
+        node_lint_levels: RefCell::new(FnvHashMap()),
         transmute_restrictions: RefCell::new(Vec::new()),
         stability: RefCell::new(stability),
         capture_modes: capture_modes,
-        associated_types: RefCell::new(DefIdMap::new()),
+        associated_types: RefCell::new(DefIdMap()),
         selection_cache: traits::SelectionCache::new(),
-        repr_hint_cache: RefCell::new(DefIdMap::new()),
+        repr_hint_cache: RefCell::new(DefIdMap()),
         type_impls_copy_cache: RefCell::new(HashMap::new()),
         type_impls_sized_cache: RefCell::new(HashMap::new()),
-        object_safety_cache: RefCell::new(DefIdMap::new()),
+        object_safety_cache: RefCell::new(DefIdMap()),
    }
 }
 
@@ -3338,7 +3317,7 @@ pub fn type_interior_is_unsafe<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
 
 pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
     return memoized(&cx.tc_cache, ty, |ty| {
-        tc_ty(cx, ty, &mut FnvHashMap::new())
+        tc_ty(cx, ty, &mut FnvHashMap())
     });
 
     fn tc_ty<'tcx>(cx: &ctxt<'tcx>,
@@ -4201,19 +4180,6 @@ pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> ty::Binder<Vec<Ty<'tcx>>> {
     ty_fn_sig(fty).inputs()
 }
 
-pub fn ty_closure_store(fty: Ty) -> TraitStore {
-    match fty.sty {
-        ty_unboxed_closure(..) => {
-            // Close enough for the purposes of all the callers of this
-            // function (which is soon to be deprecated anyhow).
-            UniqTraitStore
-        }
-        ref s => {
-            panic!("ty_closure_store() called on non-closure type: {:?}", s)
-        }
-    }
-}
-
 pub fn ty_fn_ret<'tcx>(fty: Ty<'tcx>) -> Binder<FnOutput<'tcx>> {
     match fty.sty {
         ty_bare_fn(_, ref f) => f.sig.output(),
@@ -4758,13 +4724,6 @@ fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
 /// afterwards to present additional details, particularly when it comes to lifetime-related
 /// errors.
 pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
-    fn tstore_to_closure(s: &TraitStore) -> String {
-        match s {
-            &UniqTraitStore => "proc".to_string(),
-            &RegionTraitStore(..) => "closure".to_string()
-        }
-    }
-
     match *err {
         terr_cyclic_ty => "cyclic type of infinite size".to_string(),
         terr_mismatch => "types differ".to_string(),
@@ -4783,11 +4742,6 @@ fn tstore_to_closure(s: &TraitStore) -> String {
                     values.expected,
                     values.found)
         }
-        terr_sigil_mismatch(values) => {
-            format!("expected {}, found {}",
-                    tstore_to_closure(&values.expected),
-                    tstore_to_closure(&values.found))
-        }
         terr_mutability => "values differ in mutability".to_string(),
         terr_box_mutability => {
             "boxed values differ in mutability".to_string()
@@ -4835,11 +4789,6 @@ fn tstore_to_closure(s: &TraitStore) -> String {
                      found bound lifetime parameter {}",
                     bound_region_ptr_to_string(cx, br))
         }
-        terr_trait_stores_differ(_, ref values) => {
-            format!("trait storage differs: expected `{}`, found `{}`",
-                    trait_store_to_string(cx, (*values).expected),
-                    trait_store_to_string(cx, (*values).found))
-        }
         terr_sorts(values) => {
             // A naive approach to making sure that we're not reporting silly errors such as:
             // (expected closure, found closure).
@@ -5035,6 +4984,23 @@ pub fn trait_items<'tcx>(cx: &ctxt<'tcx>, trait_did: ast::DefId)
     }
 }
 
+pub fn trait_impl_polarity<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
+                            -> Option<ast::ImplPolarity> {
+     if id.krate == ast::LOCAL_CRATE {
+         match cx.map.find(id.node) {
+             Some(ast_map::NodeItem(item)) => {
+                 match item.node {
+                     ast::ItemImpl(_, polarity, _, _, _, _) => Some(polarity),
+                     _ => None
+                 }
+             }
+             _ => None
+         }
+     } else {
+         csearch::get_impl_polarity(cx, id)
+     }
+}
+
 pub fn impl_or_trait_item<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
                                 -> ImplOrTraitItem<'tcx> {
     lookup_locally_or_in_crate_store("impl_or_trait_items",
@@ -5079,25 +5045,6 @@ pub fn associated_type_parameter_index(cx: &ctxt,
     cx.sess.bug("couldn't find associated type parameter index")
 }
 
-#[derive(Copy, PartialEq, Eq)]
-pub struct AssociatedTypeInfo {
-    pub def_id: ast::DefId,
-    pub index: uint,
-    pub name: ast::Name,
-}
-
-impl PartialOrd for AssociatedTypeInfo {
-    fn partial_cmp(&self, other: &AssociatedTypeInfo) -> Option<Ordering> {
-        Some(self.index.cmp(&other.index))
-    }
-}
-
-impl Ord for AssociatedTypeInfo {
-    fn cmp(&self, other: &AssociatedTypeInfo) -> Ordering {
-        self.index.cmp(&other.index)
-    }
-}
-
 pub fn trait_item_def_ids(cx: &ctxt, id: ast::DefId)
                           -> Rc<Vec<ImplOrTraitItemId>> {
     lookup_locally_or_in_crate_store("trait_item_def_ids",
@@ -5359,15 +5306,13 @@ pub fn enum_variants<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
                                                 discriminant = val as Disr
                                             }
                                             Ok(_) => {
-                                                cx.sess
-                                                  .span_err(e.span,
+                                                span_err!(cx.sess, e.span, E0304,
                                                             "expected signed integer constant");
                                             }
                                             Err(ref err) => {
-                                                cx.sess
-                                                  .span_err(e.span,
-                                                            &format!("expected constant: {}",
-                                                                    *err)[]);
+                                                span_err!(cx.sess, e.span, E0305,
+                                                            "expected constant: {}",
+                                                                    *err);
                                             }
                                         },
                                     None => {}
@@ -5841,9 +5786,9 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
                 const_eval::const_binary(_) =>
                     "binary array"
             };
-            tcx.sess.span_err(count_expr.span, &format!(
+            span_err!(tcx.sess, count_expr.span, E0306,
                 "expected positive integer for repeat count, found {}",
-                found)[]);
+                found);
         }
         Err(_) => {
             let found = match count_expr.node {
@@ -5856,9 +5801,9 @@ pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint {
                 _ =>
                     "non-constant expression"
             };
-            tcx.sess.span_err(count_expr.span, &format!(
+            span_err!(tcx.sess, count_expr.span, E0307,
                 "expected constant integer for repeat count, found {}",
-                found)[]);
+                found);
         }
     }
     0
@@ -5984,6 +5929,7 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
 pub fn record_trait_implementation(tcx: &ctxt,
                                    trait_def_id: DefId,
                                    impl_def_id: DefId) {
+
     match tcx.trait_impls.borrow().get(&trait_def_id) {
         Some(impls_for_trait) => {
             impls_for_trait.borrow_mut().push(impl_def_id);
@@ -5991,6 +5937,7 @@ pub fn record_trait_implementation(tcx: &ctxt,
         }
         None => {}
     }
+
     tcx.trait_impls.borrow_mut().insert(trait_def_id, Rc::new(RefCell::new(vec!(impl_def_id))));
 }
 
@@ -6748,7 +6695,7 @@ pub fn replace_late_bound_regions<'tcx, T, F>(
 {
     debug!("replace_late_bound_regions({})", binder.repr(tcx));
 
-    let mut map = FnvHashMap::new();
+    let mut map = FnvHashMap();
 
     // Note: fold the field `0`, not the binder, so that late-bound
     // regions bound by `binder` are considered free.
@@ -7326,11 +7273,8 @@ fn references_error(&self) -> bool {
 
 impl<'tcx> Repr<'tcx> for ClosureTy<'tcx> {
     fn repr(&self, tcx: &ctxt<'tcx>) -> String {
-        format!("ClosureTy({},{},{:?},{},{},{})",
+        format!("ClosureTy({},{},{})",
                 self.unsafety,
-                self.onceness,
-                self.store,
-                self.bounds.repr(tcx),
                 self.sig.repr(tcx),
                 self.abi)
     }
@@ -7361,5 +7305,5 @@ fn repr(&self, tcx: &ctxt<'tcx>) -> String {
             self.free_substs.repr(tcx),
             self.implicit_region_bound.repr(tcx),
             self.caller_bounds.repr(tcx))
-        }
     }
+}