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;
// 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.
{
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());
});
});
},
});
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", || {
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())
}
});
);
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);
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,
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
.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)));
}
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};
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.
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);
}
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;
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());
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());
});
}
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);
/// 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);
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 };
}
}
- 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,
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());
}
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),