Skip to content

Commit 1dc363b

Browse files
committed
librustc_middle: return LocalDefId instead of DefId in opt_local_def_id
1 parent bc30e4d commit 1dc363b

File tree

4 files changed

+26
-16
lines changed
  • src
    • librustc_infer/infer/error_reporting
    • librustc_middle/hir/map
    • librustc_trait_selection/traits/error_reporting
    • librustdoc

4 files changed

+26
-16
lines changed

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5959
use rustc_errors::{pluralize, struct_span_err};
6060
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6161
use rustc_hir as hir;
62-
use rustc_hir::def_id::DefId;
62+
use rustc_hir::def_id::{DefId, LocalDefId};
6363
use rustc_hir::Node;
6464
use rustc_middle::middle::region;
6565
use rustc_middle::ty::error::TypeError;
@@ -1589,8 +1589,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15891589
// it's a actual definition. According to the comments (e.g. in
15901590
// librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter
15911591
// is relied upon by some other code. This might (or might not) need cleanup.
1592-
let body_owner_def_id =
1593-
self.tcx.hir().opt_local_def_id(cause.body_id).unwrap_or_else(|| {
1592+
let body_owner_def_id = self
1593+
.tcx
1594+
.hir()
1595+
.opt_local_def_id(cause.body_id)
1596+
.map(LocalDefId::to_def_id)
1597+
.unwrap_or_else(|| {
15941598
self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
15951599
});
15961600
self.check_and_note_conflicting_crates(diag, terr);

src/librustc_middle/hir/map/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'hir> Map<'hir> {
150150
}
151151

152152
pub fn def_path_from_hir_id(&self, id: HirId) -> Option<DefPath> {
153-
self.opt_local_def_id(id).map(|def_id| self.def_path(def_id.expect_local()))
153+
self.opt_local_def_id(id).map(|def_id| self.def_path(def_id))
154154
}
155155

156156
pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
@@ -175,19 +175,21 @@ impl<'hir> Map<'hir> {
175175
// FIXME(eddyb) this function can and should return `LocalDefId`.
176176
#[inline]
177177
pub fn local_def_id(&self, hir_id: HirId) -> DefId {
178-
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
179-
bug!(
180-
"local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
181-
hir_id,
182-
self.find_entry(hir_id)
183-
)
184-
})
178+
self.opt_local_def_id(hir_id)
179+
.unwrap_or_else(|| {
180+
bug!(
181+
"local_def_id: no entry for `{:?}`, which has a map of `{:?}`",
182+
hir_id,
183+
self.find_entry(hir_id)
184+
)
185+
})
186+
.to_def_id()
185187
}
186188

187189
#[inline]
188-
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
190+
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> {
189191
let node_id = self.hir_id_to_node_id(hir_id);
190-
Some(self.opt_local_def_id_from_node_id(node_id)?.to_def_id())
192+
self.opt_local_def_id_from_node_id(node_id)
191193
}
192194

193195
#[inline]

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::infer::{self, InferCtxt, TyCtxtInferExt};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
1616
use rustc_hir as hir;
17-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
17+
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
1818
use rustc_hir::{Node, QPath, TyKind, WhereBoundPredicate, WherePredicate};
1919
use rustc_middle::mir::interpret::ErrorHandled;
2020
use rustc_middle::ty::error::ExpectedFound;
@@ -354,6 +354,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
354354
let enclosing_scope_span = tcx.def_span(
355355
tcx.hir()
356356
.opt_local_def_id(obligation.cause.body_id)
357+
.map(LocalDefId::to_def_id)
357358
.unwrap_or_else(|| {
358359
tcx.hir().body_owner_def_id(hir::BodyId {
359360
hir_id: obligation.cause.body_id,

src/librustdoc/core.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,15 @@ impl<'tcx> DocContext<'tcx> {
152152
self.tcx
153153
.hir()
154154
.opt_local_def_id(id)
155-
.and_then(|def_id| self.tcx.lookup_stability(def_id))
155+
.and_then(|def_id| self.tcx.lookup_stability(def_id.to_def_id()))
156156
.cloned()
157157
}
158158

159159
pub fn deprecation(&self, id: HirId) -> Option<attr::Deprecation> {
160-
self.tcx.hir().opt_local_def_id(id).and_then(|def_id| self.tcx.lookup_deprecation(def_id))
160+
self.tcx
161+
.hir()
162+
.opt_local_def_id(id)
163+
.and_then(|def_id| self.tcx.lookup_deprecation(def_id.to_def_id()))
161164
}
162165
}
163166

0 commit comments

Comments
 (0)