diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index a514f1a9489..f66b1a2976f 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -328,7 +328,7 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> { let typeck_results = self.maybe_typeck_results.get().or_else(|| { self.tcx .hir() - .maybe_body_owned_by(self.tcx.hir().local_def_id(expr.hir_id)) + .maybe_body_owned_by(expr.hir_id.owner) .map(|body_id| self.tcx.typeck_body(body_id)) }); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs index 4c63024367c..3e9d491af62 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs @@ -49,8 +49,8 @@ pub fn find_param_with_region<'tcx>( }; let hir = &tcx.hir(); - let local_did = id.as_local()?; - let hir_id = hir.local_def_id_to_hir_id(local_did); + let def_id = id.as_local()?; + let hir_id = hir.local_def_id_to_hir_id(def_id); // FIXME: use def_kind // Don't perform this on closures @@ -61,7 +61,7 @@ pub fn find_param_with_region<'tcx>( _ => {} } - let body_id = hir.maybe_body_owned_by(local_did)?; + let body_id = hir.maybe_body_owned_by(def_id)?; let owner_id = hir.body_owner(body_id); let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index d2ed6e08ff7..f0886036899 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1614,16 +1614,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } fn encode_info_for_anon_const(&mut self, id: hir::HirId) { - let local_did = self.tcx.hir().local_def_id(id); - debug!("EncodeContext::encode_info_for_anon_const({:?})", local_did); - let body_id = self.tcx.hir().body_owned_by(local_did); + let def_id = self.tcx.hir().local_def_id(id); + debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id); + let body_id = self.tcx.hir().body_owned_by(def_id); let const_data = self.encode_rendered_const_for_body(body_id); - let qualifs = self.tcx.mir_const_qualif(local_did); + let qualifs = self.tcx.mir_const_qualif(def_id); - record!(self.tables.kind[local_did.to_def_id()] <- EntryKind::AnonConst); - record!(self.tables.mir_const_qualif[local_did.to_def_id()] <- qualifs); - record!(self.tables.rendered_const[local_did.to_def_id()] <- const_data); - self.encode_item_type(local_did.to_def_id()); + record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst); + record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs); + record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data); + self.encode_item_type(def_id.to_def_id()); } fn encode_native_libraries(&mut self) -> LazyArray { diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 3c008749358..211a614717f 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -157,9 +157,9 @@ pub fn provide(providers: &mut Providers) { }; providers.fn_arg_names = |tcx, id| { let hir = tcx.hir(); - let local_did = id.expect_local(); - let hir_id = hir.local_def_id_to_hir_id(local_did); - if let Some(body_id) = hir.maybe_body_owned_by(local_did) { + let def_id = id.expect_local(); + let hir_id = hir.local_def_id_to_hir_id(def_id); + if let Some(body_id) = hir.maybe_body_owned_by(def_id) { tcx.arena.alloc_from_iter(hir.body_param_names(body_id)) } else if let Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(_, TraitFn::Required(idents)), diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index c6e38520f64..063c076474e 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -26,7 +26,7 @@ use rustc_span::{BytePos, Span}; pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: DefId) { let body_id = match def_id.as_local() { None => return, - Some(did) => tcx.hir().body_owned_by(did), + Some(def_id) => tcx.hir().body_owned_by(def_id), }; let pattern_arena = TypedArena::default(); diff --git a/compiler/rustc_passes/src/upvars.rs b/compiler/rustc_passes/src/upvars.rs index 6f3b0eea4b5..68d9bf22bf9 100644 --- a/compiler/rustc_passes/src/upvars.rs +++ b/compiler/rustc_passes/src/upvars.rs @@ -15,8 +15,8 @@ pub fn provide(providers: &mut Providers) { return None; } - let local_did = def_id.expect_local(); - let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(local_did)?); + let local_def_id = def_id.expect_local(); + let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(local_def_id)?); let mut local_collector = LocalCollector::default(); local_collector.visit_body(body); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index b000774ed2a..03a8de7c760 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1783,7 +1783,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let generator_body = generator_did .as_local() - .and_then(|local_did| hir.maybe_body_owned_by(local_did)) + .and_then(|def_id| hir.maybe_body_owned_by(def_id)) .map(|body_id| hir.body(body_id)); let is_async = match generator_did.as_local() { Some(_) => generator_body diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index f437eb98942..b1af3051719 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -207,10 +207,14 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { constness, ); - let body_id = local_did - .and_then(|id| tcx.hir().maybe_body_owned_by(id).map(|body| body.hir_id)) - .or(hir_id) - .map_or(hir::CRATE_HIR_ID, |did| did); + let body_id = + local_did.and_then(|id| tcx.hir().maybe_body_owned_by(id).map(|body| body.hir_id)); + let body_id = match body_id { + Some(id) => id, + None if hir_id.is_some() => hir_id.unwrap(), + _ => hir::CRATE_HIR_ID, + }; + let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); traits::normalize_param_env_or_error(tcx, unnormalized_env, cause) } diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 59e07313f54..c0726868f77 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir.local_def_id(hir_id)) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner()) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", &hir.body(body_id).value)); });