about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_infer/infer/error_reporting/need_type_info.rs7
-rw-r--r--src/librustc_metadata/rmeta/decoder/cstore_impl.rs2
-rw-r--r--src/librustc_middle/hir/map/mod.rs13
-rw-r--r--src/librustc_middle/middle/stability.rs2
-rw-r--r--src/librustc_middle/query/mod.rs2
-rw-r--r--src/librustc_middle/ty/context.rs24
-rw-r--r--src/librustc_middle/ty/mod.rs2
-rw-r--r--src/librustc_middle/ty/print/pretty.rs2
-rw-r--r--src/librustc_middle/ty/util.rs9
-rw-r--r--src/librustc_mir/const_eval/eval_queries.rs2
-rw-r--r--src/librustc_mir/interpret/eval_context.rs2
-rw-r--r--src/librustc_mir/monomorphize/partitioning.rs2
-rw-r--r--src/librustc_mir/transform/const_prop.rs5
-rw-r--r--src/librustc_mir/util/pretty.rs8
-rw-r--r--src/librustc_privacy/lib.rs9
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs3
-rw-r--r--src/librustc_trait_selection/traits/error_reporting/suggestions.rs2
-rw-r--r--src/librustc_traits/lowering/mod.rs16
-rw-r--r--src/librustc_typeck/check/dropck.rs10
-rw-r--r--src/librustc_typeck/check/expr.rs5
-rw-r--r--src/librustc_typeck/check/mod.rs20
-rw-r--r--src/librustdoc/clean/inline.rs2
-rw-r--r--src/librustdoc/clean/mod.rs2
-rw-r--r--src/librustdoc/clean/utils.rs18
24 files changed, 69 insertions, 100 deletions
diff --git a/src/librustc_infer/infer/error_reporting/need_type_info.rs b/src/librustc_infer/infer/error_reporting/need_type_info.rs
index bb6e5700cca..d3bd0763ff1 100644
--- a/src/librustc_infer/infer/error_reporting/need_type_info.rs
+++ b/src/librustc_infer/infer/error_reporting/need_type_info.rs
@@ -192,12 +192,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                         .get_opt_name()
                         .map(|parent_symbol| parent_symbol.to_string());
 
-                    let type_parent_desc = self
-                        .tcx
-                        .def_kind(parent_def_id)
-                        .map(|parent_def_kind| parent_def_kind.descr(parent_def_id));
-
-                    (parent_name, type_parent_desc)
+                    (parent_name, Some(self.tcx.def_kind(parent_def_id).descr(parent_def_id)))
                 } else {
                     (None, None)
                 };
diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs
index 60bf7aba713..ecf3825dadb 100644
--- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs
+++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs
@@ -127,7 +127,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
     is_foreign_item => { cdata.is_foreign_item(def_id.index) }
     static_mutability => { cdata.static_mutability(def_id.index) }
     generator_kind => { cdata.generator_kind(def_id.index) }
-    def_kind => { Some(cdata.def_kind(def_id.index)) }
+    def_kind => { cdata.def_kind(def_id.index) }
     def_span => { cdata.get_span(def_id.index, &tcx.sess) }
     lookup_stability => {
         cdata.get_stability(def_id.index).map(|s| tcx.intern_stability(s))
diff --git a/src/librustc_middle/hir/map/mod.rs b/src/librustc_middle/hir/map/mod.rs
index bd383bde3b5..1c71fc57bea 100644
--- a/src/librustc_middle/hir/map/mod.rs
+++ b/src/librustc_middle/hir/map/mod.rs
@@ -227,15 +227,14 @@ impl<'hir> Map<'hir> {
         self.tcx.definitions.opt_local_def_id_to_hir_id(def_id)
     }
 
-    pub fn def_kind(&self, local_def_id: LocalDefId) -> Option<DefKind> {
+    pub fn def_kind(&self, local_def_id: LocalDefId) -> DefKind {
+        // FIXME(eddyb) support `find` on the crate root.
         if local_def_id.to_def_id().index == CRATE_DEF_INDEX {
-            return Some(DefKind::Mod);
+            return DefKind::Mod;
         }
 
         let hir_id = self.local_def_id_to_hir_id(local_def_id);
-        let node = self.find(hir_id)?;
-
-        Some(match node {
+        match self.get(hir_id) {
             Node::Item(item) => match item.kind {
                 ItemKind::Static(..) => DefKind::Static,
                 ItemKind::Const(..) => DefKind::Const,
@@ -273,7 +272,7 @@ impl<'hir> Map<'hir> {
             Node::Variant(_) => DefKind::Variant,
             Node::Ctor(variant_data) => {
                 // FIXME(eddyb) is this even possible, if we have a `Node::Ctor`?
-                variant_data.ctor_hir_id()?;
+                assert_ne!(variant_data.ctor_hir_id(), None);
 
                 let ctor_of = match self.find(self.get_parent_node(hir_id)) {
                     Some(Node::Item(..)) => def::CtorOf::Struct,
@@ -308,7 +307,7 @@ impl<'hir> Map<'hir> {
             | Node::Visibility(_)
             | Node::Block(_)
             | Node::Crate(_) => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)),
-        })
+        }
     }
 
     fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
diff --git a/src/librustc_middle/middle/stability.rs b/src/librustc_middle/middle/stability.rs
index 9d95a700313..54c05bca3bd 100644
--- a/src/librustc_middle/middle/stability.rs
+++ b/src/librustc_middle/middle/stability.rs
@@ -246,7 +246,7 @@ pub enum EvalResult {
 fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, mut def_id: DefId) -> bool {
     // Check if `def_id` is a trait method.
     match tcx.def_kind(def_id) {
-        Some(DefKind::AssocFn) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => {
+        DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
             if let ty::TraitContainer(trait_def_id) = tcx.associated_item(def_id).container {
                 // Trait methods do not declare visibility (even
                 // for visibility info in cstore). Use containing
diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs
index 51bbb9016b6..8b0509e314c 100644
--- a/src/librustc_middle/query/mod.rs
+++ b/src/librustc_middle/query/mod.rs
@@ -620,7 +620,7 @@ rustc_queries! {
             cache_on_disk_if { true }
         }
 
-        query def_kind(_: DefId) -> Option<DefKind> {}
+        query def_kind(_: DefId) -> DefKind {}
         query def_span(_: DefId) -> Span {
             // FIXME(mw): DefSpans are not really inputs since they are derived from
             // HIR. But at the moment HIR hashing still contains some hacks that allow
diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs
index 7797374259c..eae4055877b 100644
--- a/src/librustc_middle/ty/context.rs
+++ b/src/librustc_middle/ty/context.rs
@@ -48,7 +48,7 @@ use rustc_errors::ErrorReported;
 use rustc_hir as hir;
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
-use rustc_hir::definitions::{DefPathData, DefPathHash, Definitions};
+use rustc_hir::definitions::{DefPathHash, Definitions};
 use rustc_hir::lang_items;
 use rustc_hir::lang_items::PanicLocationLangItem;
 use rustc_hir::{HirId, Node, TraitCandidate};
@@ -1492,21 +1492,13 @@ impl<'tcx> TyCtxt<'tcx> {
 
     /// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
     pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
-        self.def_kind(def_id)
-            .map(|def_kind| (def_kind.article(), def_kind.descr(def_id)))
-            .unwrap_or_else(|| match self.def_key(def_id).disambiguated_data.data {
-                DefPathData::ClosureExpr => match self.generator_kind(def_id) {
-                    None => ("a", "closure"),
-                    Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
-                    Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
-                },
-                DefPathData::LifetimeNs(..) => ("a", "lifetime"),
-                DefPathData::Impl => ("an", "implementation"),
-                DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
-                    unreachable!()
-                }
-                _ => bug!("article_and_description called on def_id {:?}", def_id),
-            })
+        match self.def_kind(def_id) {
+            DefKind::Generator => match self.generator_kind(def_id).unwrap() {
+                rustc_hir::GeneratorKind::Async(..) => ("an", "async closure"),
+                rustc_hir::GeneratorKind::Gen => ("a", "generator"),
+            },
+            def_kind => (def_kind.article(), def_kind.descr(def_id)),
+        }
     }
 }
 
diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs
index b785f79e1f3..d6c8ccf5ea6 100644
--- a/src/librustc_middle/ty/mod.rs
+++ b/src/librustc_middle/ty/mod.rs
@@ -2680,7 +2680,7 @@ impl<'tcx> TyCtxt<'tcx> {
             }
         } else {
             match self.def_kind(def_id) {
-                Some(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy) => true,
+                DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
                 _ => false,
             }
         };
diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs
index 828f7f6a767..f8209cddd2b 100644
--- a/src/librustc_middle/ty/print/pretty.rs
+++ b/src/librustc_middle/ty/print/pretty.rs
@@ -891,7 +891,7 @@ pub trait PrettyPrinter<'tcx>:
                     p!(write("::{:?}", promoted));
                 } else {
                     match self.tcx().def_kind(did) {
-                        Some(DefKind::Static | DefKind::Const | DefKind::AssocConst) => {
+                        DefKind::Static | DefKind::Const | DefKind::AssocConst => {
                             p!(print_value_path(did, substs))
                         }
                         _ => {
diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs
index 4b10a8ba821..b46caf79852 100644
--- a/src/librustc_middle/ty/util.rs
+++ b/src/librustc_middle/ty/util.rs
@@ -16,7 +16,6 @@ use rustc_errors::ErrorReported;
 use rustc_hir as hir;
 use rustc_hir::def::DefKind;
 use rustc_hir::def_id::DefId;
-use rustc_hir::definitions::DefPathData;
 use rustc_macros::HashStable;
 use rustc_span::Span;
 use rustc_target::abi::{Integer, Size, TargetDataLayout};
@@ -446,24 +445,24 @@ impl<'tcx> TyCtxt<'tcx> {
     /// those are not yet phased out). The parent of the closure's
     /// `DefId` will also be the context where it appears.
     pub fn is_closure(self, def_id: DefId) -> bool {
-        self.def_key(def_id).disambiguated_data.data == DefPathData::ClosureExpr
+        matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Generator)
     }
 
     /// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).
     pub fn is_trait(self, def_id: DefId) -> bool {
-        self.def_kind(def_id) == Some(DefKind::Trait)
+        self.def_kind(def_id) == DefKind::Trait
     }
 
     /// Returns `true` if `def_id` refers to a trait alias (i.e., `trait Foo = ...;`),
     /// and `false` otherwise.
     pub fn is_trait_alias(self, def_id: DefId) -> bool {
-        self.def_kind(def_id) == Some(DefKind::TraitAlias)
+        self.def_kind(def_id) == DefKind::TraitAlias
     }
 
     /// Returns `true` if this `DefId` refers to the implicit constructor for
     /// a tuple struct like `struct Foo(u32)`, and `false` otherwise.
     pub fn is_constructor(self, def_id: DefId) -> bool {
-        self.def_key(def_id).disambiguated_data.data == DefPathData::Ctor
+        matches!(self.def_kind(def_id), DefKind::Ctor(..))
     }
 
     /// Given the def-ID of a fn or closure, returns the def-ID of
diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs
index 6d0a02ee3a4..b6d10d1e370 100644
--- a/src/librustc_mir/const_eval/eval_queries.rs
+++ b/src/librustc_mir/const_eval/eval_queries.rs
@@ -341,7 +341,7 @@ pub fn const_eval_raw_provider<'tcx>(
                     // because any code that existed before validation could not have failed
                     // validation thus preventing such a hard error from being a backwards
                     // compatibility hazard
-                    Some(DefKind::Const | DefKind::AssocConst) => {
+                    DefKind::Const | DefKind::AssocConst => {
                         let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
                         err.report_as_lint(
                             tcx.at(tcx.def_span(def_id)),
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 45abde43477..a497a6784ff 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -632,7 +632,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             // FIXME: The above is likely untrue. See
             // <https://github.com/rust-lang/rust/pull/70004#issuecomment-602022110>. Is it
             // okay to ignore `StorageDead`/`StorageLive` annotations during CTFE?
-            Some(DefKind::Static | DefKind::Const | DefKind::AssocConst) => {}
+            DefKind::Static | DefKind::Const | DefKind::AssocConst => {}
             _ => {
                 // Mark locals that use `Storage*` annotations as dead on function entry.
                 let always_live = AlwaysLiveLocals::new(self.body());
diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs
index cad5b114ae4..db1ea72c0a5 100644
--- a/src/librustc_mir/monomorphize/partitioning.rs
+++ b/src/librustc_mir/monomorphize/partitioning.rs
@@ -779,7 +779,7 @@ fn compute_codegen_unit_name(
                 cgu_def_id = Some(DefId { krate: def_id.krate, index: CRATE_DEF_INDEX });
             }
             break;
-        } else if tcx.def_kind(current_def_id) == Some(DefKind::Mod) {
+        } else if tcx.def_kind(current_def_id) == DefKind::Mod {
             if cgu_def_id.is_none() {
                 cgu_def_id = Some(current_def_id);
             }
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 205bfcd7b37..4493ae2fef3 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -69,10 +69,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
         let hir_id = tcx.hir().as_local_hir_id(source.def_id().expect_local());
 
         let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some();
-        let is_assoc_const = match tcx.def_kind(source.def_id()) {
-            Some(DefKind::AssocConst) => true,
-            _ => false,
-        };
+        let is_assoc_const = tcx.def_kind(source.def_id()) == DefKind::AssocConst;
 
         // Only run const prop on functions, methods, closures and associated constants
         if !is_fn_like && !is_assoc_const {
diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs
index f0fc5c12c90..8829b10d5dd 100644
--- a/src/librustc_mir/util/pretty.rs
+++ b/src/librustc_mir/util/pretty.rs
@@ -807,17 +807,17 @@ fn write_mir_sig(
     trace!("write_mir_sig: {:?}", src.instance);
     let kind = tcx.def_kind(src.def_id());
     let is_function = match kind {
-        Some(DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..)) => true,
+        DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
         _ => tcx.is_closure(src.def_id()),
     };
     match (kind, src.promoted) {
         (_, Some(i)) => write!(w, "{:?} in ", i)?,
-        (Some(DefKind::Const | DefKind::AssocConst), _) => write!(w, "const ")?,
-        (Some(DefKind::Static), _) => {
+        (DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
+        (DefKind::Static, _) => {
             write!(w, "static {}", if tcx.is_mutable_static(src.def_id()) { "mut " } else { "" })?
         }
         (_, _) if is_function => write!(w, "fn ")?,
-        (Some(DefKind::AnonConst), _) | (None, _) => {} // things like anon const, not an item
+        (DefKind::AnonConst, _) => {} // things like anon const, not an item
         _ => bug!("Unexpected def kind {:?}", kind),
     }
 
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 27bbf43bc85..e4501b5c3b5 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -538,11 +538,10 @@ impl EmbargoVisitor<'tcx> {
         for item_id in module.item_ids {
             let hir_id = item_id.id;
             let item_def_id = self.tcx.hir().local_def_id(hir_id);
-            if let Some(def_kind) = self.tcx.def_kind(item_def_id) {
-                let item = self.tcx.hir().expect_item(hir_id);
-                let vis = ty::Visibility::from_hir(&item.vis, hir_id, self.tcx);
-                self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
-            }
+            let def_kind = self.tcx.def_kind(item_def_id);
+            let item = self.tcx.hir().expect_item(hir_id);
+            let vis = ty::Visibility::from_hir(&item.vis, hir_id, self.tcx);
+            self.update_macro_reachable_def(hir_id, def_kind, vis, defining_mod);
         }
         if let Some(exports) = self.tcx.module_exports(module_def_id) {
             for export in exports {
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index 2bf9c857d6e..bd484fc7a90 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -917,7 +917,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
                 | DefKind::LifetimeParam
                 | DefKind::GlobalAsm
                 | DefKind::Closure
-                | DefKind::Impl,
+                | DefKind::Impl
+                | DefKind::Generator,
                 _,
             )
             | Res::Local(..)
diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs
index 88b9d257795..19260f4d573 100644
--- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs
+++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs
@@ -1487,7 +1487,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                 // ```
                 debug!("parent_def_kind: {:?}", self.tcx.def_kind(parent_did));
                 let is_raw_borrow_inside_fn_like_call = match self.tcx.def_kind(parent_did) {
-                    Some(DefKind::Fn | DefKind::Ctor(..)) => target_ty.is_unsafe_ptr(),
+                    DefKind::Fn | DefKind::Ctor(..) => target_ty.is_unsafe_ptr(),
                     _ => false,
                 };
 
diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs
index 4f3eba99956..19765c36ae2 100644
--- a/src/librustc_traits/lowering/mod.rs
+++ b/src/librustc_traits/lowering/mod.rs
@@ -150,10 +150,10 @@ crate fn program_clauses_for(tcx: TyCtxt<'_>, def_id: DefId) -> Clauses<'_> {
     // FIXME(eddyb) this should only be using `def_kind`.
     match tcx.def_key(def_id).disambiguated_data.data {
         DefPathData::TypeNs(..) => match tcx.def_kind(def_id) {
-            Some(DefKind::Trait | DefKind::TraitAlias) => program_clauses_for_trait(tcx, def_id),
+            DefKind::Trait | DefKind::TraitAlias => program_clauses_for_trait(tcx, def_id),
             // FIXME(eddyb) deduplicate this `associated_item` call with
             // `program_clauses_for_associated_type_{value,def}`.
-            Some(DefKind::AssocTy) => match tcx.associated_item(def_id).container {
+            DefKind::AssocTy => match tcx.associated_item(def_id).container {
                 ty::AssocItemContainer::ImplContainer(_) => {
                     program_clauses_for_associated_type_value(tcx, def_id)
                 }
@@ -161,13 +161,11 @@ crate fn program_clauses_for(tcx: TyCtxt<'_>, def_id: DefId) -> Clauses<'_> {
                     program_clauses_for_associated_type_def(tcx, def_id)
                 }
             },
-            Some(
-                DefKind::Struct
-                | DefKind::Enum
-                | DefKind::TyAlias
-                | DefKind::Union
-                | DefKind::OpaqueTy,
-            ) => program_clauses_for_type_def(tcx, def_id),
+            DefKind::Struct
+            | DefKind::Enum
+            | DefKind::TyAlias
+            | DefKind::Union
+            | DefKind::OpaqueTy => program_clauses_for_type_def(tcx, def_id),
             _ => List::empty(),
         },
         DefPathData::Impl => program_clauses_for_impl(tcx, def_id),
diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs
index 078401ee6a8..478a848cf09 100644
--- a/src/librustc_typeck/check/dropck.rs
+++ b/src/librustc_typeck/check/dropck.rs
@@ -94,10 +94,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
             }
             Err(_) => {
                 let item_span = tcx.def_span(self_type_did);
-                let self_descr = tcx
-                    .def_kind(self_type_did)
-                    .map(|kind| kind.descr(self_type_did))
-                    .unwrap_or("type");
+                let self_descr = tcx.def_kind(self_type_did).descr(self_type_did);
                 struct_span_err!(
                     tcx.sess,
                     drop_impl_span,
@@ -244,10 +241,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
 
         if !assumptions_in_impl_context.iter().any(predicate_matches_closure) {
             let item_span = tcx.hir().span(self_type_hir_id);
-            let self_descr = tcx
-                .def_kind(self_type_did)
-                .map(|kind| kind.descr(self_type_did.to_def_id()))
-                .unwrap_or("type");
+            let self_descr = tcx.def_kind(self_type_did).descr(self_type_did.to_def_id());
             struct_span_err!(
                 tcx.sess,
                 *predicate_sp,
diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs
index 2bca5e75825..d287589789e 100644
--- a/src/librustc_typeck/check/expr.rs
+++ b/src/librustc_typeck/check/expr.rs
@@ -1564,10 +1564,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         base_did: DefId,
     ) {
         let struct_path = self.tcx().def_path_str(base_did);
-        let kind_name = match self.tcx().def_kind(base_did) {
-            Some(def_kind) => def_kind.descr(base_did),
-            _ => " ",
-        };
+        let kind_name = self.tcx().def_kind(base_did).descr(base_did);
         let mut err = struct_span_err!(
             self.tcx().sess,
             field.span,
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 6db720470fb..b18546cf321 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -831,6 +831,13 @@ fn primary_body_of(
 }
 
 fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
+    // FIXME(#71104) some `LocalDefId` do not seem to have a corresponding `HirId`.
+    if let Some(def_id) = def_id.as_local() {
+        if tcx.hir().opt_local_def_id_to_hir_id(def_id).is_none() {
+            return false;
+        }
+    }
+
     // Closures' tables come from their outermost function,
     // as they are part of the same "inference environment".
     let outer_def_id = tcx.closure_base_def_id(def_id);
@@ -838,11 +845,8 @@ fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
         return tcx.has_typeck_tables(outer_def_id);
     }
 
-    // FIXME(#71104) Should really be using just `as_local_hir_id` but
-    // some `LocalDefId` do not seem to have a corresponding HirId.
-    if let Some(id) =
-        def_id.as_local().and_then(|def_id| tcx.hir().opt_local_def_id_to_hir_id(def_id))
-    {
+    if let Some(def_id) = def_id.as_local() {
+        let id = tcx.hir().local_def_id_to_hir_id(def_id);
         primary_body_of(tcx, id).is_some()
     } else {
         false
@@ -4972,12 +4976,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     sugg_call = fields.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
                     match def_id
                         .as_local()
-                        .and_then(|def_id| hir.def_kind(def_id))
+                        .map(|def_id| hir.def_kind(def_id))
                     {
-                        Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _)) => {
+                        Some(DefKind::Ctor(hir::def::CtorOf::Variant, _)) => {
                             msg = "instantiate this tuple variant";
                         }
-                        Some(hir::def::DefKind::Ctor(hir::def::CtorOf::Struct, _)) => {
+                        Some(DefKind::Ctor(CtorOf::Struct, _)) => {
                             msg = "instantiate this tuple struct";
                         }
                         _ => {}
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 6208c147101..cd098936ed6 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -278,7 +278,7 @@ fn build_type_alias_type(cx: &DocContext<'_>, did: DefId) -> Option<clean::Type>
 }
 
 pub fn build_ty(cx: &DocContext, did: DefId) -> Option<clean::Type> {
-    match cx.tcx.def_kind(did)? {
+    match cx.tcx.def_kind(did) {
         DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Const | DefKind::Static => {
             Some(cx.tcx.type_of(did).clean(cx))
         }
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 4d03bb21cb3..9849000e91c 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2134,7 +2134,7 @@ impl Clean<Vec<Item>> for doctree::Impl<'_> {
 
         let for_ = self.for_.clean(cx);
         let type_alias = for_.def_id().and_then(|did| match cx.tcx.def_kind(did) {
-            Some(DefKind::TyAlias) => Some(cx.tcx.type_of(did).clean(cx)),
+            DefKind::TyAlias => Some(cx.tcx.type_of(did).clean(cx)),
             _ => None,
         });
         let make_item = |trait_: Option<Type>, for_: Type, items: Vec<Item>| Item {
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index ec5ac48ffe4..c4e4802db6c 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -209,7 +209,7 @@ pub fn get_real_types(
                                 res.extend(adds);
                             } else if !ty.is_full_generic() {
                                 if let Some(kind) =
-                                    ty.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
+                                    ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx))
                                 {
                                     res.insert((ty, kind));
                                 }
@@ -226,9 +226,7 @@ pub fn get_real_types(
                     if !adds.is_empty() {
                         res.extend(adds);
                     } else if !ty.is_full_generic() {
-                        if let Some(kind) =
-                            ty.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
-                        {
+                        if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
                             res.insert((ty.clone(), kind));
                         }
                     }
@@ -236,7 +234,7 @@ pub fn get_real_types(
             }
         }
     } else {
-        if let Some(kind) = arg.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx)) {
+        if let Some(kind) = arg.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
             res.insert((arg.clone(), kind));
         }
         if let Some(gens) = arg.generics() {
@@ -246,9 +244,7 @@ pub fn get_real_types(
                     if !adds.is_empty() {
                         res.extend(adds);
                     }
-                } else if let Some(kind) =
-                    gen.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
-                {
+                } else if let Some(kind) = gen.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
                     res.insert((gen.clone(), kind));
                 }
             }
@@ -275,7 +271,7 @@ pub fn get_all_types(
         if !args.is_empty() {
             all_types.extend(args);
         } else {
-            if let Some(kind) = arg.type_.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx)) {
+            if let Some(kind) = arg.type_.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
                 all_types.insert((arg.type_.clone(), kind));
             }
         }
@@ -285,9 +281,7 @@ pub fn get_all_types(
         FnRetTy::Return(ref return_type) => {
             let mut ret = get_real_types(generics, &return_type, cx, 0);
             if ret.is_empty() {
-                if let Some(kind) =
-                    return_type.def_id().and_then(|did| cx.tcx.def_kind(did).clean(cx))
-                {
+                if let Some(kind) = return_type.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
                     ret.insert((return_type.clone(), kind));
                 }
             }