librustc_middle: return LocalDefId instead of DefId in body_owner_def_id
This commit is contained in:
parent
1dc363bce1
commit
f62c6e1c76
@ -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, LocalDefId};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
@ -1589,16 +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)
|
||||
.map(LocalDefId::to_def_id)
|
||||
.unwrap_or_else(|| {
|
||||
let body_owner_def_id =
|
||||
self.tcx.hir().opt_local_def_id(cause.body_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);
|
||||
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);
|
||||
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id.to_def_id());
|
||||
|
||||
// It reads better to have the error origin as the final
|
||||
// thing.
|
||||
|
@ -812,7 +812,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
||||
{
|
||||
sess.time("match_checking", || {
|
||||
tcx.par_body_owners(|def_id| {
|
||||
tcx.ensure().check_match(def_id);
|
||||
tcx.ensure().check_match(def_id.to_def_id());
|
||||
});
|
||||
});
|
||||
},
|
||||
@ -834,7 +834,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
||||
});
|
||||
|
||||
sess.time("MIR_borrow_checking", || {
|
||||
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
|
||||
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id()));
|
||||
});
|
||||
|
||||
sess.time("dumping_chalk_like_clauses", || {
|
||||
@ -843,7 +843,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
||||
|
||||
sess.time("MIR_effect_checking", || {
|
||||
for def_id in tcx.body_owners() {
|
||||
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
|
||||
mir::transform::check_unsafety::check_unsafety(tcx, def_id.to_def_id())
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1166,7 +1166,7 @@ declare_lint_pass!(
|
||||
);
|
||||
|
||||
fn check_const(cx: &LateContext<'_, '_>, body_id: hir::BodyId) {
|
||||
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
|
||||
// trigger the query once for all constants since that will already report the errors
|
||||
// FIXME: Use ensure here
|
||||
let _ = cx.tcx.const_eval_poly(def_id);
|
||||
|
@ -370,9 +370,8 @@ impl<'hir> Map<'hir> {
|
||||
parent
|
||||
}
|
||||
|
||||
// FIXME(eddyb) this function can and should return `LocalDefId`.
|
||||
pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
|
||||
self.local_def_id(self.body_owner(id))
|
||||
pub fn body_owner_def_id(&self, id: BodyId) -> LocalDefId {
|
||||
self.local_def_id(self.body_owner(id)).expect_local()
|
||||
}
|
||||
|
||||
/// Given a `HirId`, returns the `BodyId` associated with it,
|
||||
|
@ -2678,13 +2678,13 @@ pub enum ImplOverlapKind {
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn body_tables(self, body: hir::BodyId) -> &'tcx TypeckTables<'tcx> {
|
||||
self.typeck_tables_of(self.hir().body_owner_def_id(body))
|
||||
self.typeck_tables_of(self.hir().body_owner_def_id(body).to_def_id())
|
||||
}
|
||||
|
||||
/// Returns an iterator of the `DefId`s for all body-owners in this
|
||||
/// crate. If you would prefer to iterate over the bodies
|
||||
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
|
||||
pub fn body_owners(self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'tcx {
|
||||
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
|
||||
self.hir()
|
||||
.krate()
|
||||
.body_ids
|
||||
@ -2692,7 +2692,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
.map(move |&body_id| self.hir().body_owner_def_id(body_id))
|
||||
}
|
||||
|
||||
pub fn par_body_owners<F: Fn(DefId) + sync::Sync + sync::Send>(self, f: F) {
|
||||
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
|
||||
par_iter(&self.hir().krate().body_ids)
|
||||
.for_each(|&body_id| f(self.hir().body_owner_def_id(body_id)));
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{shim, util};
|
||||
use rustc_ast::ast;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted};
|
||||
@ -62,7 +62,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
|
||||
let mut set = DefIdSet::default();
|
||||
|
||||
// All body-owners have MIR associated with them.
|
||||
set.extend(tcx.body_owners());
|
||||
set.extend(tcx.body_owners().map(LocalDefId::to_def_id));
|
||||
|
||||
// Additionally, tuple struct/variant constructors have MIR, but
|
||||
// they don't have a BodyId, so we need to build them separately.
|
||||
|
@ -131,8 +131,8 @@ impl Visitor<'tcx> for ItemVisitor<'tcx> {
|
||||
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
|
||||
let owner_def_id = self.tcx.hir().body_owner_def_id(body_id);
|
||||
let body = self.tcx.hir().body(body_id);
|
||||
let param_env = self.tcx.param_env(owner_def_id);
|
||||
let tables = self.tcx.typeck_tables_of(owner_def_id);
|
||||
let param_env = self.tcx.param_env(owner_def_id.to_def_id());
|
||||
let tables = self.tcx.typeck_tables_of(owner_def_id.to_def_id());
|
||||
ExprVisitor { tcx: self.tcx, param_env, tables }.visit_body(body);
|
||||
self.visit_body(body);
|
||||
}
|
||||
|
@ -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, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_hir::{Node, QPath, TyKind, WhereBoundPredicate, WherePredicate};
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
@ -354,12 +354,12 @@ 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,
|
||||
})
|
||||
}),
|
||||
})
|
||||
.to_def_id(),
|
||||
);
|
||||
|
||||
err.span_label(enclosing_scope_span, s.as_str());
|
||||
|
@ -751,7 +751,7 @@ fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: DefId) {
|
||||
fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
|
||||
debug_assert!(crate_num == LOCAL_CRATE);
|
||||
tcx.par_body_owners(|body_owner_def_id| {
|
||||
tcx.ensure().typeck_tables_of(body_owner_def_id);
|
||||
tcx.ensure().typeck_tables_of(body_owner_def_id.to_def_id());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ macro_rules! ignore_err {
|
||||
|
||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
pub fn regionck_expr(&self, body: &'tcx hir::Body<'tcx>) {
|
||||
let subject = self.tcx.hir().body_owner_def_id(body.id());
|
||||
let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
|
||||
let id = body.value.hir_id;
|
||||
let mut rcx =
|
||||
RegionCtxt::new(self, RepeatingScope(id), id, Subject(subject), self.param_env);
|
||||
@ -154,7 +154,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// constraints to add.
|
||||
pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) {
|
||||
debug!("regionck_fn(id={})", fn_id);
|
||||
let subject = self.tcx.hir().body_owner_def_id(body.id());
|
||||
let subject = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
|
||||
let hir_id = body.value.hir_id;
|
||||
let mut rcx =
|
||||
RegionCtxt::new(self, RepeatingScope(hir_id), hir_id, Subject(subject), self.param_env);
|
||||
@ -290,7 +290,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
|
||||
|
||||
let body_id = body.id();
|
||||
self.body_id = body_id.hir_id;
|
||||
self.body_owner = self.tcx.hir().body_owner_def_id(body_id);
|
||||
self.body_owner = self.tcx.hir().body_owner_def_id(body_id).to_def_id();
|
||||
|
||||
let call_site =
|
||||
region::Scope { id: body.value.hir_id.local_id, data: region::ScopeData::CallSite };
|
||||
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id());
|
||||
let body_owner_def_id = self.tcx.hir().body_owner_def_id(body.id()).to_def_id();
|
||||
assert_eq!(body_owner_def_id, closure_def_id);
|
||||
let mut delegate = InferBorrowKind {
|
||||
fcx: self,
|
||||
|
@ -12,7 +12,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
let mut used_trait_imports = DefIdSet::default();
|
||||
for &body_id in tcx.hir().krate().bodies.keys() {
|
||||
let item_def_id = tcx.hir().body_owner_def_id(body_id);
|
||||
let imports = tcx.used_trait_imports(item_def_id);
|
||||
let imports = tcx.used_trait_imports(item_def_id.to_def_id());
|
||||
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
|
||||
used_trait_imports.extend(imports.iter());
|
||||
}
|
||||
|
@ -419,7 +419,10 @@ impl Clean<Lifetime> for hir::GenericParam<'_> {
|
||||
impl Clean<Constant> for hir::ConstArg {
|
||||
fn clean(&self, cx: &DocContext<'_>) -> Constant {
|
||||
Constant {
|
||||
type_: cx.tcx.type_of(cx.tcx.hir().body_owner_def_id(self.value.body)).clean(cx),
|
||||
type_: cx
|
||||
.tcx
|
||||
.type_of(cx.tcx.hir().body_owner_def_id(self.value.body).to_def_id())
|
||||
.clean(cx),
|
||||
expr: print_const_expr(cx, self.value.body),
|
||||
value: None,
|
||||
is_literal: is_literal_expr(cx, self.value.body.hir_id),
|
||||
|
Loading…
Reference in New Issue
Block a user