Skip to content

Rollup of 4 pull requests #71011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
librustc_middle: return LocalDefId instead of DefId in opt_local_def_id
  • Loading branch information
marmeladema committed Apr 10, 2020
commit 1dc363bce1f02ed9863f9b9cdc10532b95a64fbb
10 changes: 7 additions & 3 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
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;
Expand Down Expand Up @@ -1589,8 +1589,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// 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);
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<'hir> Map<'hir> {
}

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 {
Expand All @@ -175,19 +175,21 @@ impl<'hir> Map<'hir> {
// 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]
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::infer::{self, InferCtxt, TyCtxtInferExt};
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;
Expand Down Expand Up @@ -354,6 +354,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
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,
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,15 @@ impl<'tcx> DocContext<'tcx> {
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()))
}
}

Expand Down