diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index b98924ff8a6..942d76e3202 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -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. diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 609c80a2b79..4c054795136 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -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()) } }); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 84cf2258ac2..910d53880f2 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -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); diff --git a/src/librustc_middle/hir/map/mod.rs b/src/librustc_middle/hir/map/mod.rs index 3cda1f41b05..c4180c3e9c7 100644 --- a/src/librustc_middle/hir/map/mod.rs +++ b/src/librustc_middle/hir/map/mod.rs @@ -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, diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 18518e78e35..b4c80f623f3 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -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 + Captures<'tcx> + 'tcx { + pub fn body_owners(self) -> impl Iterator + 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(self, f: F) { + pub fn par_body_owners(self, f: F) { par_iter(&self.hir().krate().body_ids) .for_each(|&body_id| f(self.hir().body_owner_def_id(body_id))); } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 18b3e88c86f..81ea57e4c00 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -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. diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index cc1af630cdd..ad5a649a24a 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -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); } diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index a19daa12d5b..b2c9d9956cb 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -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()); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index eebc34d3db8..4754f495ca7 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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()); }); } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 393f9f8bdfb..f7564623946 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -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 }; diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index c6c11ee9d9b..2c9e23d8095 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -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, diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index f552b53d8ba..cc99ae20199 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -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()); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 03413f67f88..3ab906b807e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -419,7 +419,10 @@ impl Clean for hir::GenericParam<'_> { impl Clean 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),