]> git.lizzy.rs Git - rust.git/commitdiff
librustc_middle: return LocalDefId instead of DefId in opt_local_def_id
authormarmeladema <xademax@gmail.com>
Wed, 8 Apr 2020 11:33:38 +0000 (12:33 +0100)
committermarmeladema <xademax@gmail.com>
Fri, 10 Apr 2020 11:13:54 +0000 (12:13 +0100)
src/librustc_infer/infer/error_reporting/mod.rs
src/librustc_middle/hir/map/mod.rs
src/librustc_trait_selection/traits/error_reporting/mod.rs
src/librustdoc/core.rs

index 925f92edd7da9cd3e1b0a688728d63db4e213125..b98924ff8a6fc2c7460ad334d54876e4c971b168 100644 (file)
@@ -59,7 +59,7 @@
 use rustc_errors::{pluralize, struct_span_err};
 use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
 use rustc_hir as hir;
-use rustc_hir::def_id::DefId;
+use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_hir::Node;
 use rustc_middle::middle::region;
 use rustc_middle::ty::error::TypeError;
@@ -1589,8 +1589,12 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
         // it's a actual definition. According to the comments (e.g. in
         // librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter
         // is relied upon by some other code. This might (or might not) need cleanup.
-        let body_owner_def_id =
-            self.tcx.hir().opt_local_def_id(cause.body_id).unwrap_or_else(|| {
+        let body_owner_def_id = self
+            .tcx
+            .hir()
+            .opt_local_def_id(cause.body_id)
+            .map(LocalDefId::to_def_id)
+            .unwrap_or_else(|| {
                 self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
             });
         self.check_and_note_conflicting_crates(diag, terr);
index 343afab154b44d4afbc71c9bb92a1c5a5772e40d..3cda1f41b05d51a7c5794193fa9e467cd63a7d14 100644 (file)
@@ -150,7 +150,7 @@ pub fn def_key(&self, def_id: LocalDefId) -> DefKey {
     }
 
     pub fn def_path_from_hir_id(&self, id: HirId) -> Option<DefPath> {
-        self.opt_local_def_id(id).map(|def_id| self.def_path(def_id.expect_local()))
+        self.opt_local_def_id(id).map(|def_id| self.def_path(def_id))
     }
 
     pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
@@ -175,19 +175,21 @@ pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
     // FIXME(eddyb) this function can and should return `LocalDefId`.
     #[inline]
     pub fn local_def_id(&self, hir_id: HirId) -> DefId {
-        self.opt_local_def_id(hir_id).unwrap_or_else(|| {
-            bug!(
-                "local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
-                hir_id,
-                self.find_entry(hir_id)
-            )
-        })
+        self.opt_local_def_id(hir_id)
+            .unwrap_or_else(|| {
+                bug!(
+                    "local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
+                    hir_id,
+                    self.find_entry(hir_id)
+                )
+            })
+            .to_def_id()
     }
 
     #[inline]
-    pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
+    pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> {
         let node_id = self.hir_id_to_node_id(hir_id);
-        Some(self.opt_local_def_id_from_node_id(node_id)?.to_def_id())
+        self.opt_local_def_id_from_node_id(node_id)
     }
 
     #[inline]
index f0a157b377076e82ea1bbad22a3b3524f8e86f22..a19daa12d5b87dd5a40b65e8552ef628fed1ffb1 100644 (file)
@@ -14,7 +14,7 @@
 use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
 use rustc_hir as hir;
-use rustc_hir::def_id::{DefId, LOCAL_CRATE};
+use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
 use rustc_hir::{Node, QPath, TyKind, WhereBoundPredicate, WherePredicate};
 use rustc_middle::mir::interpret::ErrorHandled;
 use rustc_middle::ty::error::ExpectedFound;
@@ -354,6 +354,7 @@ fn report_selection_error(
                             let enclosing_scope_span = tcx.def_span(
                                 tcx.hir()
                                     .opt_local_def_id(obligation.cause.body_id)
+                                    .map(LocalDefId::to_def_id)
                                     .unwrap_or_else(|| {
                                         tcx.hir().body_owner_def_id(hir::BodyId {
                                             hir_id: obligation.cause.body_id,
index 98f4b592fea6e0358c3d11f6ff38e983600ed4f9..762ec7e9ac3c6e6fd202d80739a773949e412ec6 100644 (file)
@@ -152,12 +152,15 @@ pub fn stability(&self, id: HirId) -> Option<attr::Stability> {
         self.tcx
             .hir()
             .opt_local_def_id(id)
-            .and_then(|def_id| self.tcx.lookup_stability(def_id))
+            .and_then(|def_id| self.tcx.lookup_stability(def_id.to_def_id()))
             .cloned()
     }
 
     pub fn deprecation(&self, id: HirId) -> Option<attr::Deprecation> {
-        self.tcx.hir().opt_local_def_id(id).and_then(|def_id| self.tcx.lookup_deprecation(def_id))
+        self.tcx
+            .hir()
+            .opt_local_def_id(id)
+            .and_then(|def_id| self.tcx.lookup_deprecation(def_id.to_def_id()))
     }
 }