about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2016-05-03 04:02:41 +0300
committerEduard Burtescu <edy.burt@gmail.com>2016-05-11 04:14:58 +0300
commitb5122d5c4ca8eeed25008ff908df4dfb75b23ea5 (patch)
treee5c1718d0099d99112236774d4f2f675a47b61fc
parent6dbb0e86aec11050480beb76eade6fb805010ba7 (diff)
rustc: Always refer to TyCtxt as tcx.
-rw-r--r--src/librustc/middle/liveness.rs4
-rw-r--r--src/librustc/ty/adjustment.rs22
-rw-r--r--src/librustc/ty/contents.rs30
-rw-r--r--src/librustc/ty/error.rs8
-rw-r--r--src/librustc/ty/mod.rs158
-rw-r--r--src/librustc/ty/sty.rs8
-rw-r--r--src/librustc/ty/util.rs48
-rw-r--r--src/librustc_trans/common.rs4
-rw-r--r--src/librustc_typeck/check/mod.rs4
9 files changed, 143 insertions, 143 deletions
diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs
index b9b182fd4d0..1247c156a09 100644
--- a/src/librustc/middle/liveness.rs
+++ b/src/librustc/middle/liveness.rs
@@ -169,8 +169,8 @@ enum LiveNodeKind {
     ExitNode
 }
 
-fn live_node_kind_to_string(lnk: LiveNodeKind, cx: &TyCtxt) -> String {
-    let cm = cx.sess.codemap();
+fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: &TyCtxt) -> String {
+    let cm = tcx.sess.codemap();
     match lnk {
         FreeVarNode(s) => {
             format!("Free var node [{}]", cm.span_to_string(s))
diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs
index 41008823c85..7510bd07251 100644
--- a/src/librustc/ty/adjustment.rs
+++ b/src/librustc/ty/adjustment.rs
@@ -138,7 +138,7 @@ pub enum CustomCoerceUnsized {
 
 impl<'tcx> ty::TyS<'tcx> {
     /// See `expr_ty_adjusted`
-    pub fn adjust<F>(&'tcx self, cx: &TyCtxt<'tcx>,
+    pub fn adjust<F>(&'tcx self, tcx: &TyCtxt<'tcx>,
                      span: Span,
                      expr_id: ast::NodeId,
                      adjustment: Option<&AutoAdjustment<'tcx>>,
@@ -156,7 +156,7 @@ impl<'tcx> ty::TyS<'tcx> {
                     AdjustReifyFnPointer => {
                         match self.sty {
                             ty::TyFnDef(_, _, b) => {
-                                cx.mk_ty(ty::TyFnPtr(b))
+                                tcx.mk_ty(ty::TyFnPtr(b))
                             }
                             _ => {
                                 bug!("AdjustReifyFnPointer adjustment on non-fn-item: {:?}",
@@ -167,7 +167,7 @@ impl<'tcx> ty::TyS<'tcx> {
 
                     AdjustUnsafeFnPointer => {
                         match self.sty {
-                            ty::TyFnPtr(b) => cx.safe_to_unsafe_fn_ty(b),
+                            ty::TyFnPtr(b) => tcx.safe_to_unsafe_fn_ty(b),
                             ref b => {
                                 bug!("AdjustUnsafeFnPointer adjustment on non-fn-ptr: {:?}",
                                      b);
@@ -177,7 +177,7 @@ impl<'tcx> ty::TyS<'tcx> {
 
                     AdjustMutToConstPointer => {
                         match self.sty {
-                            ty::TyRawPtr(mt) => cx.mk_ptr(ty::TypeAndMut {
+                            ty::TyRawPtr(mt) => tcx.mk_ptr(ty::TypeAndMut {
                                 ty: mt.ty,
                                 mutbl: hir::MutImmutable
                             }),
@@ -194,7 +194,7 @@ impl<'tcx> ty::TyS<'tcx> {
                         if !adjusted_ty.references_error() {
                             for i in 0..adj.autoderefs {
                                 adjusted_ty =
-                                    adjusted_ty.adjust_for_autoderef(cx,
+                                    adjusted_ty.adjust_for_autoderef(tcx,
                                                                      expr_id,
                                                                      span,
                                                                      i as u32,
@@ -205,7 +205,7 @@ impl<'tcx> ty::TyS<'tcx> {
                         if let Some(target) = adj.unsize {
                             target
                         } else {
-                            adjusted_ty.adjust_for_autoref(cx, adj.autoref)
+                            adjusted_ty.adjust_for_autoref(tcx, adj.autoref)
                         }
                     }
                 }
@@ -215,7 +215,7 @@ impl<'tcx> ty::TyS<'tcx> {
     }
 
     pub fn adjust_for_autoderef<F>(&'tcx self,
-                                   cx: &TyCtxt<'tcx>,
+                                   tcx: &TyCtxt<'tcx>,
                                    expr_id: ast::NodeId,
                                    expr_span: Span,
                                    autoderef: u32, // how many autoderefs so far?
@@ -228,7 +228,7 @@ impl<'tcx> ty::TyS<'tcx> {
         if let Some(method_ty) = method_type(method_call) {
             // Method calls always have all late-bound regions
             // fully instantiated.
-            let fn_ret = cx.no_late_bound_regions(&method_ty.fn_ret()).unwrap();
+            let fn_ret = tcx.no_late_bound_regions(&method_ty.fn_ret()).unwrap();
             adjusted_ty = fn_ret.unwrap();
         }
         match adjusted_ty.builtin_deref(true, NoPreference) {
@@ -243,16 +243,16 @@ impl<'tcx> ty::TyS<'tcx> {
         }
     }
 
-    pub fn adjust_for_autoref(&'tcx self, cx: &TyCtxt<'tcx>,
+    pub fn adjust_for_autoref(&'tcx self, tcx: &TyCtxt<'tcx>,
                               autoref: Option<AutoRef<'tcx>>)
                               -> Ty<'tcx> {
         match autoref {
             None => self,
             Some(AutoPtr(r, m)) => {
-                cx.mk_ref(r, TypeAndMut { ty: self, mutbl: m })
+                tcx.mk_ref(r, TypeAndMut { ty: self, mutbl: m })
             }
             Some(AutoUnsafe(m)) => {
-                cx.mk_ptr(TypeAndMut { ty: self, mutbl: m })
+                tcx.mk_ptr(TypeAndMut { ty: self, mutbl: m })
             }
         }
     }
diff --git a/src/librustc/ty/contents.rs b/src/librustc/ty/contents.rs
index f5dedb13248..cae7f4d6444 100644
--- a/src/librustc/ty/contents.rs
+++ b/src/librustc/ty/contents.rs
@@ -140,14 +140,14 @@ impl fmt::Debug for TypeContents {
 }
 
 impl<'tcx> ty::TyS<'tcx> {
-    pub fn type_contents(&'tcx self, cx: &TyCtxt<'tcx>) -> TypeContents {
-        return cx.tc_cache.memoize(self, || tc_ty(cx, self, &mut FnvHashMap()));
+    pub fn type_contents(&'tcx self, tcx: &TyCtxt<'tcx>) -> TypeContents {
+        return tcx.tc_cache.memoize(self, || tc_ty(tcx, self, &mut FnvHashMap()));
 
-        fn tc_ty<'tcx>(cx: &TyCtxt<'tcx>,
+        fn tc_ty<'tcx>(tcx: &TyCtxt<'tcx>,
                        ty: Ty<'tcx>,
                        cache: &mut FnvHashMap<Ty<'tcx>, TypeContents>) -> TypeContents
         {
-            // Subtle: Note that we are *not* using cx.tc_cache here but rather a
+            // Subtle: Note that we are *not* using tcx.tc_cache here but rather a
             // private cache for this walk.  This is needed in the case of cyclic
             // types like:
             //
@@ -163,7 +163,7 @@ impl<'tcx> ty::TyS<'tcx> {
             // The problem is, as we are doing the computation, we will also
             // compute an *intermediate* contents for, e.g., Option<List> of
             // TC::None.  This is ok during the computation of List itself, but if
-            // we stored this intermediate value into cx.tc_cache, then later
+            // we stored this intermediate value into tcx.tc_cache, then later
             // requests for the contents of Option<List> would also yield TC::None
             // which is incorrect.  This value was computed based on the crutch
             // value for the type contents of list.  The correct value is
@@ -172,7 +172,7 @@ impl<'tcx> ty::TyS<'tcx> {
                 Some(tc) => { return *tc; }
                 None => {}
             }
-            match cx.tc_cache.borrow().get(&ty) {    // Must check both caches!
+            match tcx.tc_cache.borrow().get(&ty) {    // Must check both caches!
                 Some(tc) => { return *tc; }
                 None => {}
             }
@@ -192,7 +192,7 @@ impl<'tcx> ty::TyS<'tcx> {
                 }
 
                 ty::TyBox(typ) => {
-                    tc_ty(cx, typ, cache).owned_pointer()
+                    tc_ty(tcx, typ, cache).owned_pointer()
                 }
 
                 ty::TyTrait(_) => {
@@ -208,28 +208,28 @@ impl<'tcx> ty::TyS<'tcx> {
                 }
 
                 ty::TyArray(ty, _) => {
-                    tc_ty(cx, ty, cache)
+                    tc_ty(tcx, ty, cache)
                 }
 
                 ty::TySlice(ty) => {
-                    tc_ty(cx, ty, cache)
+                    tc_ty(tcx, ty, cache)
                 }
                 ty::TyStr => TC::None,
 
                 ty::TyClosure(_, ref substs) => {
-                    TypeContents::union(&substs.upvar_tys, |ty| tc_ty(cx, &ty, cache))
+                    TypeContents::union(&substs.upvar_tys, |ty| tc_ty(tcx, &ty, cache))
                 }
 
                 ty::TyTuple(ref tys) => {
                     TypeContents::union(&tys[..],
-                                        |ty| tc_ty(cx, *ty, cache))
+                                        |ty| tc_ty(tcx, *ty, cache))
                 }
 
                 ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
                     let mut res =
                         TypeContents::union(&def.variants, |v| {
                             TypeContents::union(&v.fields, |f| {
-                                tc_ty(cx, f.ty(cx, substs), cache)
+                                tc_ty(tcx, f.ty(tcx, substs), cache)
                             })
                         });
 
@@ -237,7 +237,7 @@ impl<'tcx> ty::TyS<'tcx> {
                         res = res | TC::OwnsDtor;
                     }
 
-                    apply_lang_items(cx, def.did, res)
+                    apply_lang_items(tcx, def.did, res)
                 }
 
                 ty::TyProjection(..) |
@@ -255,9 +255,9 @@ impl<'tcx> ty::TyS<'tcx> {
             result
         }
 
-        fn apply_lang_items(cx: &TyCtxt, did: DefId, tc: TypeContents)
+        fn apply_lang_items(tcx: &TyCtxt, did: DefId, tc: TypeContents)
                             -> TypeContents {
-            if Some(did) == cx.lang_items.unsafe_cell_type() {
+            if Some(did) == tcx.lang_items.unsafe_cell_type() {
                 tc | TC::InteriorUnsafe
             } else {
                 tc
diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs
index 73bafc5e850..9dc61e513b5 100644
--- a/src/librustc/ty/error.rs
+++ b/src/librustc/ty/error.rs
@@ -211,13 +211,13 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
 }
 
 impl<'tcx> ty::TyS<'tcx> {
-    fn sort_string(&self, cx: &TyCtxt) -> String {
+    fn sort_string(&self, tcx: &TyCtxt) -> String {
         match self.sty {
             ty::TyBool | ty::TyChar | ty::TyInt(_) |
             ty::TyUint(_) | ty::TyFloat(_) | ty::TyStr => self.to_string(),
             ty::TyTuple(ref tys) if tys.is_empty() => self.to_string(),
 
-            ty::TyEnum(def, _) => format!("enum `{}`", cx.item_path_str(def.did)),
+            ty::TyEnum(def, _) => format!("enum `{}`", tcx.item_path_str(def.did)),
             ty::TyBox(_) => "box".to_string(),
             ty::TyArray(_, n) => format!("array of {} elements", n),
             ty::TySlice(_) => "slice".to_string(),
@@ -226,10 +226,10 @@ impl<'tcx> ty::TyS<'tcx> {
             ty::TyFnDef(..) => format!("fn item"),
             ty::TyFnPtr(_) => "fn pointer".to_string(),
             ty::TyTrait(ref inner) => {
-                format!("trait {}", cx.item_path_str(inner.principal_def_id()))
+                format!("trait {}", tcx.item_path_str(inner.principal_def_id()))
             }
             ty::TyStruct(def, _) => {
-                format!("struct `{}`", cx.item_path_str(def.did))
+                format!("struct `{}`", tcx.item_path_str(def.did))
             }
             ty::TyClosure(..) => "closure".to_string(),
             ty::TyTuple(_) => "tuple".to_string(),
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 700ed62f216..59fd6263c85 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -1262,42 +1262,42 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
     }
 
     /// Construct a parameter environment given an item, impl item, or trait item
-    pub fn for_item(cx: &'a TyCtxt<'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
-        match cx.map.find(id) {
+    pub fn for_item(tcx: &'a TyCtxt<'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
+        match tcx.map.find(id) {
             Some(ast_map::NodeImplItem(ref impl_item)) => {
                 match impl_item.node {
                     hir::ImplItemKind::Type(_) => {
                         // associated types don't have their own entry (for some reason),
                         // so for now just grab environment for the impl
-                        let impl_id = cx.map.get_parent(id);
-                        let impl_def_id = cx.map.local_def_id(impl_id);
-                        let scheme = cx.lookup_item_type(impl_def_id);
-                        let predicates = cx.lookup_predicates(impl_def_id);
-                        cx.construct_parameter_environment(impl_item.span,
-                                                           &scheme.generics,
-                                                           &predicates,
-                                                           cx.region_maps.item_extent(id))
+                        let impl_id = tcx.map.get_parent(id);
+                        let impl_def_id = tcx.map.local_def_id(impl_id);
+                        let scheme = tcx.lookup_item_type(impl_def_id);
+                        let predicates = tcx.lookup_predicates(impl_def_id);
+                        tcx.construct_parameter_environment(impl_item.span,
+                                                            &scheme.generics,
+                                                            &predicates,
+                                                            tcx.region_maps.item_extent(id))
                     }
                     hir::ImplItemKind::Const(_, _) => {
-                        let def_id = cx.map.local_def_id(id);
-                        let scheme = cx.lookup_item_type(def_id);
-                        let predicates = cx.lookup_predicates(def_id);
-                        cx.construct_parameter_environment(impl_item.span,
-                                                           &scheme.generics,
-                                                           &predicates,
-                                                           cx.region_maps.item_extent(id))
+                        let def_id = tcx.map.local_def_id(id);
+                        let scheme = tcx.lookup_item_type(def_id);
+                        let predicates = tcx.lookup_predicates(def_id);
+                        tcx.construct_parameter_environment(impl_item.span,
+                                                            &scheme.generics,
+                                                            &predicates,
+                                                            tcx.region_maps.item_extent(id))
                     }
                     hir::ImplItemKind::Method(_, ref body) => {
-                        let method_def_id = cx.map.local_def_id(id);
-                        match cx.impl_or_trait_item(method_def_id) {
+                        let method_def_id = tcx.map.local_def_id(id);
+                        match tcx.impl_or_trait_item(method_def_id) {
                             MethodTraitItem(ref method_ty) => {
                                 let method_generics = &method_ty.generics;
                                 let method_bounds = &method_ty.predicates;
-                                cx.construct_parameter_environment(
+                                tcx.construct_parameter_environment(
                                     impl_item.span,
                                     method_generics,
                                     method_bounds,
-                                    cx.region_maps.call_site_extent(id, body.id))
+                                    tcx.region_maps.call_site_extent(id, body.id))
                             }
                             _ => {
                                 bug!("ParameterEnvironment::for_item(): \
@@ -1312,41 +1312,41 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
                     hir::TypeTraitItem(..) => {
                         // associated types don't have their own entry (for some reason),
                         // so for now just grab environment for the trait
-                        let trait_id = cx.map.get_parent(id);
-                        let trait_def_id = cx.map.local_def_id(trait_id);
-                        let trait_def = cx.lookup_trait_def(trait_def_id);
-                        let predicates = cx.lookup_predicates(trait_def_id);
-                        cx.construct_parameter_environment(trait_item.span,
-                                                           &trait_def.generics,
-                                                           &predicates,
-                                                           cx.region_maps.item_extent(id))
+                        let trait_id = tcx.map.get_parent(id);
+                        let trait_def_id = tcx.map.local_def_id(trait_id);
+                        let trait_def = tcx.lookup_trait_def(trait_def_id);
+                        let predicates = tcx.lookup_predicates(trait_def_id);
+                        tcx.construct_parameter_environment(trait_item.span,
+                                                            &trait_def.generics,
+                                                            &predicates,
+                                                            tcx.region_maps.item_extent(id))
                     }
                     hir::ConstTraitItem(..) => {
-                        let def_id = cx.map.local_def_id(id);
-                        let scheme = cx.lookup_item_type(def_id);
-                        let predicates = cx.lookup_predicates(def_id);
-                        cx.construct_parameter_environment(trait_item.span,
-                                                           &scheme.generics,
-                                                           &predicates,
-                                                           cx.region_maps.item_extent(id))
+                        let def_id = tcx.map.local_def_id(id);
+                        let scheme = tcx.lookup_item_type(def_id);
+                        let predicates = tcx.lookup_predicates(def_id);
+                        tcx.construct_parameter_environment(trait_item.span,
+                                                            &scheme.generics,
+                                                            &predicates,
+                                                            tcx.region_maps.item_extent(id))
                     }
                     hir::MethodTraitItem(_, ref body) => {
                         // Use call-site for extent (unless this is a
                         // trait method with no default; then fallback
                         // to the method id).
-                        let method_def_id = cx.map.local_def_id(id);
-                        match cx.impl_or_trait_item(method_def_id) {
+                        let method_def_id = tcx.map.local_def_id(id);
+                        match tcx.impl_or_trait_item(method_def_id) {
                             MethodTraitItem(ref method_ty) => {
                                 let method_generics = &method_ty.generics;
                                 let method_bounds = &method_ty.predicates;
                                 let extent = if let Some(ref body) = *body {
                                     // default impl: use call_site extent as free_id_outlive bound.
-                                    cx.region_maps.call_site_extent(id, body.id)
+                                    tcx.region_maps.call_site_extent(id, body.id)
                                 } else {
                                     // no default impl: use item extent as free_id_outlive bound.
-                                    cx.region_maps.item_extent(id)
+                                    tcx.region_maps.item_extent(id)
                                 };
-                                cx.construct_parameter_environment(
+                                tcx.construct_parameter_environment(
                                     trait_item.span,
                                     method_generics,
                                     method_bounds,
@@ -1365,15 +1365,15 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
                 match item.node {
                     hir::ItemFn(_, _, _, _, _, ref body) => {
                         // We assume this is a function.
-                        let fn_def_id = cx.map.local_def_id(id);
-                        let fn_scheme = cx.lookup_item_type(fn_def_id);
-                        let fn_predicates = cx.lookup_predicates(fn_def_id);
-
-                        cx.construct_parameter_environment(item.span,
-                                                           &fn_scheme.generics,
-                                                           &fn_predicates,
-                                                           cx.region_maps.call_site_extent(id,
-                                                                                           body.id))
+                        let fn_def_id = tcx.map.local_def_id(id);
+                        let fn_scheme = tcx.lookup_item_type(fn_def_id);
+                        let fn_predicates = tcx.lookup_predicates(fn_def_id);
+
+                        tcx.construct_parameter_environment(
+                            item.span,
+                            &fn_scheme.generics,
+                            &fn_predicates,
+                            tcx.region_maps.call_site_extent(id, body.id))
                     }
                     hir::ItemEnum(..) |
                     hir::ItemStruct(..) |
@@ -1381,22 +1381,22 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
                     hir::ItemImpl(..) |
                     hir::ItemConst(..) |
                     hir::ItemStatic(..) => {
-                        let def_id = cx.map.local_def_id(id);
-                        let scheme = cx.lookup_item_type(def_id);
-                        let predicates = cx.lookup_predicates(def_id);
-                        cx.construct_parameter_environment(item.span,
-                                                           &scheme.generics,
-                                                           &predicates,
-                                                           cx.region_maps.item_extent(id))
+                        let def_id = tcx.map.local_def_id(id);
+                        let scheme = tcx.lookup_item_type(def_id);
+                        let predicates = tcx.lookup_predicates(def_id);
+                        tcx.construct_parameter_environment(item.span,
+                                                            &scheme.generics,
+                                                            &predicates,
+                                                            tcx.region_maps.item_extent(id))
                     }
                     hir::ItemTrait(..) => {
-                        let def_id = cx.map.local_def_id(id);
-                        let trait_def = cx.lookup_trait_def(def_id);
-                        let predicates = cx.lookup_predicates(def_id);
-                        cx.construct_parameter_environment(item.span,
-                                                           &trait_def.generics,
-                                                           &predicates,
-                                                           cx.region_maps.item_extent(id))
+                        let def_id = tcx.map.local_def_id(id);
+                        let trait_def = tcx.lookup_trait_def(def_id);
+                        let predicates = tcx.lookup_predicates(def_id);
+                        tcx.construct_parameter_environment(item.span,
+                                                            &trait_def.generics,
+                                                            &predicates,
+                                                            tcx.region_maps.item_extent(id))
                     }
                     _ => {
                         span_bug!(item.span,
@@ -1408,21 +1408,21 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
             }
             Some(ast_map::NodeExpr(..)) => {
                 // This is a convenience to allow closures to work.
-                ParameterEnvironment::for_item(cx, cx.map.get_parent(id))
+                ParameterEnvironment::for_item(tcx, tcx.map.get_parent(id))
             }
             Some(ast_map::NodeForeignItem(item)) => {
-                let def_id = cx.map.local_def_id(id);
-                let scheme = cx.lookup_item_type(def_id);
-                let predicates = cx.lookup_predicates(def_id);
-                cx.construct_parameter_environment(item.span,
-                                                   &scheme.generics,
-                                                   &predicates,
-                                                   ROOT_CODE_EXTENT)
+                let def_id = tcx.map.local_def_id(id);
+                let scheme = tcx.lookup_item_type(def_id);
+                let predicates = tcx.lookup_predicates(def_id);
+                tcx.construct_parameter_environment(item.span,
+                                                    &scheme.generics,
+                                                    &predicates,
+                                                    ROOT_CODE_EXTENT)
             }
             _ => {
                 bug!("ParameterEnvironment::from_item(): \
                       `{}` is not an item",
-                     cx.map.node_to_string(id))
+                     tcx.map.node_to_string(id))
             }
         }
     }
@@ -1996,19 +1996,19 @@ pub enum ClosureKind {
 }
 
 impl ClosureKind {
-    pub fn trait_did(&self, cx: &TyCtxt) -> DefId {
+    pub fn trait_did(&self, tcx: &TyCtxt) -> DefId {
         let result = match *self {
-            ClosureKind::Fn => cx.lang_items.require(FnTraitLangItem),
+            ClosureKind::Fn => tcx.lang_items.require(FnTraitLangItem),
             ClosureKind::FnMut => {
-                cx.lang_items.require(FnMutTraitLangItem)
+                tcx.lang_items.require(FnMutTraitLangItem)
             }
             ClosureKind::FnOnce => {
-                cx.lang_items.require(FnOnceTraitLangItem)
+                tcx.lang_items.require(FnOnceTraitLangItem)
             }
         };
         match result {
             Ok(trait_did) => trait_did,
-            Err(err) => cx.sess.fatal(&err[..]),
+            Err(err) => tcx.sess.fatal(&err[..]),
         }
     }
 
@@ -2092,7 +2092,7 @@ impl LvaluePreference {
 }
 
 /// Helper for looking things up in the various maps that are populated during
-/// typeck::collect (e.g., `cx.impl_or_trait_items`, `cx.tcache`, etc).  All of
+/// typeck::collect (e.g., `tcx.impl_or_trait_items`, `tcx.tcache`, etc).  All of
 /// these share the pattern that if the id is local, it should have been loaded
 /// into the map by the `typeck::collect` phase.  If the def-id is external,
 /// then we have to go consult the crate loading code (and cache the result for
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index 709ec051ddc..600ffc3da66 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -974,18 +974,18 @@ impl<'tcx> TyS<'tcx> {
         }
     }
 
-    pub fn sequence_element_type(&self, cx: &TyCtxt<'tcx>) -> Ty<'tcx> {
+    pub fn sequence_element_type(&self, tcx: &TyCtxt<'tcx>) -> Ty<'tcx> {
         match self.sty {
             TyArray(ty, _) | TySlice(ty) => ty,
-            TyStr => cx.mk_mach_uint(ast::UintTy::U8),
+            TyStr => tcx.mk_mach_uint(ast::UintTy::U8),
             _ => bug!("sequence_element_type called on non-sequence value: {}", self),
         }
     }
 
-    pub fn simd_type(&self, cx: &TyCtxt<'tcx>) -> Ty<'tcx> {
+    pub fn simd_type(&self, tcx: &TyCtxt<'tcx>) -> Ty<'tcx> {
         match self.sty {
             TyStruct(def, substs) => {
-                def.struct_variant().fields[0].ty(cx, substs)
+                def.struct_variant().fields[0].ty(tcx, substs)
             }
             _ => bug!("simd_type called on invalid type")
         }
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs
index b6bd8f5f55f..fa95dea50a4 100644
--- a/src/librustc/ty/util.rs
+++ b/src/librustc/ty/util.rs
@@ -32,25 +32,25 @@ use syntax::codemap::Span;
 use hir;
 
 pub trait IntTypeExt {
-    fn to_ty<'tcx>(&self, cx: &TyCtxt<'tcx>) -> Ty<'tcx>;
+    fn to_ty<'tcx>(&self, tcx: &TyCtxt<'tcx>) -> Ty<'tcx>;
     fn disr_incr(&self, val: Disr) -> Option<Disr>;
     fn assert_ty_matches(&self, val: Disr);
     fn initial_discriminant(&self, tcx: &TyCtxt) -> Disr;
 }
 
 impl IntTypeExt for attr::IntType {
-    fn to_ty<'tcx>(&self, cx: &TyCtxt<'tcx>) -> Ty<'tcx> {
+    fn to_ty<'tcx>(&self, tcx: &TyCtxt<'tcx>) -> Ty<'tcx> {
         match *self {
-            SignedInt(ast::IntTy::I8)      => cx.types.i8,
-            SignedInt(ast::IntTy::I16)     => cx.types.i16,
-            SignedInt(ast::IntTy::I32)     => cx.types.i32,
-            SignedInt(ast::IntTy::I64)     => cx.types.i64,
-            SignedInt(ast::IntTy::Is)   => cx.types.isize,
-            UnsignedInt(ast::UintTy::U8)    => cx.types.u8,
-            UnsignedInt(ast::UintTy::U16)   => cx.types.u16,
-            UnsignedInt(ast::UintTy::U32)   => cx.types.u32,
-            UnsignedInt(ast::UintTy::U64)   => cx.types.u64,
-            UnsignedInt(ast::UintTy::Us) => cx.types.usize,
+            SignedInt(ast::IntTy::I8)      => tcx.types.i8,
+            SignedInt(ast::IntTy::I16)     => tcx.types.i16,
+            SignedInt(ast::IntTy::I32)     => tcx.types.i32,
+            SignedInt(ast::IntTy::I64)     => tcx.types.i64,
+            SignedInt(ast::IntTy::Is)   => tcx.types.isize,
+            UnsignedInt(ast::UintTy::U8)    => tcx.types.u8,
+            UnsignedInt(ast::UintTy::U16)   => tcx.types.u16,
+            UnsignedInt(ast::UintTy::U32)   => tcx.types.u32,
+            UnsignedInt(ast::UintTy::U64)   => tcx.types.u64,
+            UnsignedInt(ast::UintTy::Us) => tcx.types.usize,
         }
     }
 
@@ -620,35 +620,35 @@ impl<'tcx> ty::TyS<'tcx> {
 
     /// Check whether a type is representable. This means it cannot contain unboxed
     /// structural recursion. This check is needed for structs and enums.
-    pub fn is_representable(&'tcx self, cx: &TyCtxt<'tcx>, sp: Span) -> Representability {
+    pub fn is_representable(&'tcx self, tcx: &TyCtxt<'tcx>, sp: Span) -> Representability {
 
         // Iterate until something non-representable is found
-        fn find_nonrepresentable<'tcx, It: Iterator<Item=Ty<'tcx>>>(cx: &TyCtxt<'tcx>,
+        fn find_nonrepresentable<'tcx, It: Iterator<Item=Ty<'tcx>>>(tcx: &TyCtxt<'tcx>,
                                                                     sp: Span,
                                                                     seen: &mut Vec<Ty<'tcx>>,
                                                                     iter: It)
                                                                     -> Representability {
             iter.fold(Representability::Representable,
-                      |r, ty| cmp::max(r, is_type_structurally_recursive(cx, sp, seen, ty)))
+                      |r, ty| cmp::max(r, is_type_structurally_recursive(tcx, sp, seen, ty)))
         }
 
-        fn are_inner_types_recursive<'tcx>(cx: &TyCtxt<'tcx>, sp: Span,
+        fn are_inner_types_recursive<'tcx>(tcx: &TyCtxt<'tcx>, sp: Span,
                                            seen: &mut Vec<Ty<'tcx>>, ty: Ty<'tcx>)
                                            -> Representability {
             match ty.sty {
                 TyTuple(ref ts) => {
-                    find_nonrepresentable(cx, sp, seen, ts.iter().cloned())
+                    find_nonrepresentable(tcx, sp, seen, ts.iter().cloned())
                 }
                 // Fixed-length vectors.
                 // FIXME(#11924) Behavior undecided for zero-length vectors.
                 TyArray(ty, _) => {
-                    is_type_structurally_recursive(cx, sp, seen, ty)
+                    is_type_structurally_recursive(tcx, sp, seen, ty)
                 }
                 TyStruct(def, substs) | TyEnum(def, substs) => {
-                    find_nonrepresentable(cx,
+                    find_nonrepresentable(tcx,
                                           sp,
                                           seen,
-                                          def.all_fields().map(|f| f.ty(cx, substs)))
+                                          def.all_fields().map(|f| f.ty(tcx, substs)))
                 }
                 TyClosure(..) => {
                     // this check is run on type definitions, so we don't expect
@@ -691,7 +691,7 @@ impl<'tcx> ty::TyS<'tcx> {
 
         // Does the type `ty` directly (without indirection through a pointer)
         // contain any types on stack `seen`?
-        fn is_type_structurally_recursive<'tcx>(cx: &TyCtxt<'tcx>,
+        fn is_type_structurally_recursive<'tcx>(tcx: &TyCtxt<'tcx>,
                                                 sp: Span,
                                                 seen: &mut Vec<Ty<'tcx>>,
                                                 ty: Ty<'tcx>) -> Representability {
@@ -746,13 +746,13 @@ impl<'tcx> ty::TyS<'tcx> {
                     // For structs and enums, track all previously seen types by pushing them
                     // onto the 'seen' stack.
                     seen.push(ty);
-                    let out = are_inner_types_recursive(cx, sp, seen, ty);
+                    let out = are_inner_types_recursive(tcx, sp, seen, ty);
                     seen.pop();
                     out
                 }
                 _ => {
                     // No need to push in other cases.
-                    are_inner_types_recursive(cx, sp, seen, ty)
+                    are_inner_types_recursive(tcx, sp, seen, ty)
                 }
             }
         }
@@ -763,7 +763,7 @@ impl<'tcx> ty::TyS<'tcx> {
         // contains a different, structurally recursive type, maintain a stack
         // of seen types and check recursion for each of them (issues #3008, #3779).
         let mut seen: Vec<Ty> = Vec::new();
-        let r = is_type_structurally_recursive(cx, sp, &mut seen, self);
+        let r = is_type_structurally_recursive(tcx, sp, &mut seen, self);
         debug!("is_type_representable: {:?} is {:?}", self, r);
         r
     }
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs
index dc1928a5e07..0902c7497fe 100644
--- a/src/librustc_trans/common.rs
+++ b/src/librustc_trans/common.rs
@@ -62,12 +62,12 @@ pub fn type_is_sized<'tcx>(tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
     ty.is_sized(&tcx.empty_parameter_environment(), DUMMY_SP)
 }
 
-pub fn type_is_fat_ptr<'tcx>(cx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
+pub fn type_is_fat_ptr<'tcx>(tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
     match ty.sty {
         ty::TyRawPtr(ty::TypeAndMut{ty, ..}) |
         ty::TyRef(_, ty::TypeAndMut{ty, ..}) |
         ty::TyBox(ty) => {
-            !type_is_sized(cx, ty)
+            !type_is_sized(tcx, ty)
         }
         _ => {
             false
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 253003ee555..2fff091f20c 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -4791,7 +4791,7 @@ pub fn structurally_resolved_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
 }
 
 // Returns true if b contains a break that can exit from b
-pub fn may_break(cx: &TyCtxt, id: ast::NodeId, b: &hir::Block) -> bool {
+pub fn may_break(tcx: &TyCtxt, id: ast::NodeId, b: &hir::Block) -> bool {
     // First: is there an unlabeled break immediately
     // inside the loop?
     (loop_query(&b, |e| {
@@ -4804,7 +4804,7 @@ pub fn may_break(cx: &TyCtxt, id: ast::NodeId, b: &hir::Block) -> bool {
     // <id> nested anywhere inside the loop?
     (block_query(b, |e| {
         if let hir::ExprBreak(Some(_)) = e.node {
-            lookup_full_def(cx, e.span, e.id) == Def::Label(id)
+            lookup_full_def(tcx, e.span, e.id) == Def::Label(id)
         } else {
             false
         }