]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/context.rs
Auto merge of #64513 - varkor:sty-begone, r=eddyb
[rust.git] / src / librustc / ty / context.rs
index 8e8472a5aacc9b54966345befd0fc459e3455479..8a466567319e711434e8af2b4f33617057e17ed4 100644 (file)
@@ -138,7 +138,7 @@ fn intern_ty(&self,
             let flags = super::flags::FlagComputation::for_sty(&st);
 
             let ty_struct = TyS {
-                sty: st,
+                kind: st,
                 flags: flags.flags,
                 outer_exclusive_binder: flags.outer_exclusive_binder,
             };
@@ -205,26 +205,24 @@ pub struct LocalTableInContext<'a, V> {
 fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
                                      hir_id: hir::HirId,
                                      mut_access: bool) {
-    if cfg!(debug_assertions) {
-        if let Some(local_id_root) = local_id_root {
-            if hir_id.owner != local_id_root.index {
-                ty::tls::with(|tcx| {
-                    bug!("node {} with HirId::owner {:?} cannot be placed in \
-                          TypeckTables with local_id_root {:?}",
-                         tcx.hir().node_to_string(hir_id),
-                         DefId::local(hir_id.owner),
-                         local_id_root)
-                });
-            }
-        } else {
-            // We use "Null Object" TypeckTables in some of the analysis passes.
-            // These are just expected to be empty and their `local_id_root` is
-            // `None`. Therefore we cannot verify whether a given `HirId` would
-            // be a valid key for the given table. Instead we make sure that
-            // nobody tries to write to such a Null Object table.
-            if mut_access {
-                bug!("access to invalid TypeckTables")
-            }
+    if let Some(local_id_root) = local_id_root {
+        if hir_id.owner != local_id_root.index {
+            ty::tls::with(|tcx| {
+                bug!("node {} with HirId::owner {:?} cannot be placed in \
+                        TypeckTables with local_id_root {:?}",
+                        tcx.hir().node_to_string(hir_id),
+                        DefId::local(hir_id.owner),
+                        local_id_root)
+            });
+        }
+    } else {
+        // We use "Null Object" TypeckTables in some of the analysis passes.
+        // These are just expected to be empty and their `local_id_root` is
+        // `None`. Therefore we cannot verify whether a given `HirId` would
+        // be a valid key for the given table. Instead we make sure that
+        // nobody tries to write to such a Null Object table.
+        if mut_access {
+            bug!("access to invalid TypeckTables")
         }
     }
 }
@@ -830,7 +828,7 @@ pub fn is_identity(&self) -> bool {
 
                 user_substs.substs.iter().zip(BoundVar::new(0)..).all(|(kind, cvar)| {
                     match kind.unpack() {
-                        UnpackedKind::Type(ty) => match ty.sty {
+                        UnpackedKind::Type(ty) => match ty.kind {
                             ty::Bound(debruijn, b) => {
                                 // We only allow a `ty::INNERMOST` index in substitutions.
                                 assert_eq!(debruijn, ty::INNERMOST);
@@ -892,7 +890,7 @@ impl<'a, 'tcx> Lift<'tcx> for UserType<'a> {
 
 impl<'tcx> CommonTypes<'tcx> {
     fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
-        let mk = |sty| interners.intern_ty(sty);
+        let mk = |ty| interners.intern_ty(ty);
 
         CommonTypes {
             unit: mk(Tuple(List::empty())),
@@ -976,7 +974,7 @@ pub struct FreeRegionInfo {
 ///
 /// [rustc guide]: https://rust-lang.github.io/rustc-guide/ty.html
 #[derive(Copy, Clone)]
-#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "TyCtxt")]
+#[rustc_diagnostic_item = "TyCtxt"]
 pub struct TyCtxt<'tcx> {
     gcx: &'tcx GlobalCtxt<'tcx>,
 }
@@ -1512,9 +1510,9 @@ pub fn local_crate_exports_generics(self) -> bool {
                 CrateType::Executable |
                 CrateType::Staticlib  |
                 CrateType::ProcMacro  |
+                CrateType::Dylib      |
                 CrateType::Cdylib     => false,
-                CrateType::Rlib       |
-                CrateType::Dylib      => true,
+                CrateType::Rlib       => true,
             }
         })
     }
@@ -1567,7 +1565,7 @@ pub fn return_type_impl_trait(
         }
 
         let ret_ty = self.type_of(scope_def_id);
-        match ret_ty.sty {
+        match ret_ty.kind {
             ty::FnDef(_, _) => {
                 let sig = ret_ty.fn_sig(*self);
                 let output = self.erase_late_bound_regions(&sig.output());
@@ -2013,7 +2011,7 @@ pub fn go(tcx: TyCtxt<'_>) {
                 let shards = tcx.interners.type_.lock_shards();
                 let types = shards.iter().flat_map(|shard| shard.keys());
                 for &Interned(t) in types {
-                    let variant = match t.sty {
+                    let variant = match t.kind {
                         ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) |
                             ty::Float(..) | ty::Str | ty::Never => continue,
                         ty::Error => /* unimportant */ continue,
@@ -2082,10 +2080,10 @@ fn clone(&self) -> Self {
 }
 impl<'tcx, T: 'tcx+?Sized> Copy for Interned<'tcx, T> {}
 
-// N.B., an `Interned<Ty>` compares and hashes as a sty.
+// N.B., an `Interned<Ty>` compares and hashes as a `TyKind`.
 impl<'tcx> PartialEq for Interned<'tcx, TyS<'tcx>> {
     fn eq(&self, other: &Interned<'tcx, TyS<'tcx>>) -> bool {
-        self.0.sty == other.0.sty
+        self.0.kind == other.0.kind
     }
 }
 
@@ -2093,14 +2091,14 @@ impl<'tcx> Eq for Interned<'tcx, TyS<'tcx>> {}
 
 impl<'tcx> Hash for Interned<'tcx, TyS<'tcx>> {
     fn hash<H: Hasher>(&self, s: &mut H) {
-        self.0.sty.hash(s)
+        self.0.kind.hash(s)
     }
 }
 
 #[allow(rustc::usage_of_ty_tykind)]
 impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
     fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> {
-        &self.0.sty
+        &self.0.kind
     }
 }
 
@@ -2294,7 +2292,7 @@ pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
     /// It cannot convert a closure that requires unsafe.
     pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>, unsafety: hir::Unsafety) -> Ty<'tcx> {
         let converted_sig = sig.map_bound(|s| {
-            let params_iter = match s.inputs()[0].sty {
+            let params_iter = match s.inputs()[0].kind {
                 ty::Tuple(params) => {
                     params.into_iter().map(|k| k.expect_ty())
                 }
@@ -2396,9 +2394,9 @@ pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> {
     }
 
     #[inline]
-    pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem)  -> Ty<'tcx> {
-        let def_id = self.require_lang_item(item, None);
-        self.mk_generic_adt(def_id, ty)
+    pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem)  -> Option<Ty<'tcx>> {
+        let def_id = self.lang_items().require(item).ok()?;
+        Some(self.mk_generic_adt(def_id, ty))
     }
 
     #[inline]