diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2024-03-14 21:05:06 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2024-03-14 22:34:24 +0300 |
| commit | 89b536dbc85e23275f08feaf73a7abce691bf72c (patch) | |
| tree | c24706525e37ffd0a3d0994a5ac5784b7ff10b12 /compiler/rustc_hir_analysis/src | |
| parent | 30f74ff0dc4d66debc8b50724c446f817e5f75f4 (diff) | |
| download | rust-89b536dbc85e23275f08feaf73a7abce691bf72c.tar.gz rust-89b536dbc85e23275f08feaf73a7abce691bf72c.zip | |
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
5 files changed, 10 insertions, 19 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/entry.rs b/compiler/rustc_hir_analysis/src/check/entry.rs index 3d803258c8e..d5908cf2851 100644 --- a/compiler/rustc_hir_analysis/src/check/entry.rs +++ b/compiler/rustc_hir_analysis/src/check/entry.rs @@ -42,8 +42,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { if !def_id.is_local() { return None; } - let hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local()); - match tcx.hir_node(hir_id) { + match tcx.hir_node_by_def_id(def_id.expect_local()) { Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. }) => { generics.params.is_empty().not().then_some(generics.span) } @@ -57,8 +56,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { if !def_id.is_local() { return None; } - let hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local()); - match tcx.hir_node(hir_id) { + match tcx.hir_node_by_def_id(def_id.expect_local()) { Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. }) => { Some(generics.where_clause_span) } @@ -79,8 +77,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { if !def_id.is_local() { return None; } - let hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local()); - match tcx.hir_node(hir_id) { + match tcx.hir_node_by_def_id(def_id.expect_local()) { Node::Item(hir::Item { kind: hir::ItemKind::Fn(fn_sig, _, _), .. }) => { Some(fn_sig.decl.output.span()) } diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index f5bfc6b1b86..22afddad633 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -130,7 +130,7 @@ fn get_owner_return_paths( ) -> Option<(LocalDefId, ReturnsVisitor<'_>)> { let hir_id = tcx.local_def_id_to_hir_id(def_id); let parent_id = tcx.hir().get_parent_item(hir_id).def_id; - tcx.opt_hir_node_by_def_id(parent_id).and_then(|node| node.body_id()).map(|body_id| { + tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| { let body = tcx.hir().body(body_id); let mut visitor = ReturnsVisitor::default(); visitor.visit_body(body); diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index ae15efc0764..f5250045344 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1969,13 +1969,10 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { // Match the existing behavior. if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) { let pred = self.normalize(span, None, pred); - let hir_node = tcx.opt_hir_node_by_def_id(self.body_def_id); // only use the span of the predicate clause (#90869) - - if let Some(hir::Generics { predicates, .. }) = - hir_node.and_then(|node| node.generics()) - { + let hir_node = tcx.hir_node_by_def_id(self.body_def_id); + if let Some(hir::Generics { predicates, .. }) = hir_node.generics() { span = predicates .iter() // There seems to be no better way to find out which predicate we are in diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 2675eacc06e..6aae4aa21b8 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -609,10 +609,8 @@ pub(super) fn implied_predicates_with_filter( return tcx.super_predicates_of(trait_def_id); }; - let trait_hir_id = tcx.local_def_id_to_hir_id(trait_def_id); - - let Node::Item(item) = tcx.hir_node(trait_hir_id) else { - bug!("trait_node_id {} is not an item", trait_hir_id); + let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else { + bug!("trait_def_id {trait_def_id:?} is not an item"); }; let (generics, bounds) = match item.kind { diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index dcb01a117b0..b5765913cb8 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -371,11 +371,10 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>( return mir_opaque_ty.ty; } - let scope = tcx.local_def_id_to_hir_id(owner_def_id); - debug!(?scope); + debug!(?owner_def_id); let mut locator = RpitConstraintChecker { def_id, tcx, found: mir_opaque_ty }; - match tcx.hir_node(scope) { + match tcx.hir_node_by_def_id(owner_def_id) { Node::Item(it) => intravisit::walk_item(&mut locator, it), Node::ImplItem(it) => intravisit::walk_impl_item(&mut locator, it), Node::TraitItem(it) => intravisit::walk_trait_item(&mut locator, it), |
