diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2024-02-09 23:58:36 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2024-02-10 12:24:46 +0300 |
| commit | b07283815be70d4e727187f646d5023911491001 (patch) | |
| tree | fd029186c32de4da1e1aa40e81760fc9be220f74 /compiler/rustc_hir_analysis/src | |
| parent | e46e3e710740fd5b2bbdd0bba478f58f11fd88cc (diff) | |
| download | rust-b07283815be70d4e727187f646d5023911491001.tar.gz rust-b07283815be70d4e727187f646d5023911491001.zip | |
hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}`
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
7 files changed, 11 insertions, 19 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index d438d3e7c60..1ae3ebaebbb 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2749,14 +2749,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg_idx: Option<usize>, ) -> Option<Ty<'tcx>> { let tcx = self.tcx(); - let hir = tcx.hir(); - let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) = tcx.hir_node(fn_hir_id) else { return None; }; - let i = hir.get_parent(fn_hir_id).expect_item().expect_impl(); + let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl(); let trait_ref = self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty)); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index fbcebb7c87c..f458ff01c10 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -224,11 +224,8 @@ pub(crate) fn placeholder_type_error_diag<'tcx>( is_fn = true; // Check if parent is const or static - let parent_id = tcx.hir().parent_id(hir_ty.hir_id); - let parent_node = tcx.hir_node(parent_id); - is_const_or_static = matches!( - parent_node, + tcx.parent_hir_node(hir_ty.hir_id), Node::Item(&hir::Item { kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..), .. @@ -1085,7 +1082,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig< ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => { // Do not try to infer the return type for a impl method coming from a trait - if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.hir().get_parent(hir_id) + if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id) && i.of_trait.is_some() { icx.astconv().ty_of_fn( diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 4860555de20..e5e731bbe8c 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -51,7 +51,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { // of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed. None } else if tcx.features().generic_const_exprs { - let parent_node = tcx.hir().get_parent(hir_id); + let parent_node = tcx.parent_hir_node(hir_id); if let Node::Variant(Variant { disr_expr: Some(constant), .. }) = parent_node && constant.hir_id == hir_id { @@ -113,7 +113,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { Some(parent_def_id.to_def_id()) } } else { - let parent_node = tcx.hir().get_parent(hir_id); + let parent_node = tcx.parent_hir_node(hir_id); match parent_node { // HACK(eddyb) this provides the correct generics for repeat // expressions' count (i.e. `N` in `[x; N]`), and explicit diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index ab9ed6ef98d..05755f98f20 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -315,8 +315,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // We create bi-directional Outlives predicates between the original // and the duplicated parameter, to ensure that they do not get out of sync. if let Node::Item(&Item { kind: ItemKind::OpaqueTy(..), .. }) = node { - let opaque_ty_id = tcx.hir().parent_id(hir_id); - let opaque_ty_node = tcx.hir_node(opaque_ty_id); + let opaque_ty_node = tcx.parent_hir_node(hir_id); let Node::Ty(&Ty { kind: TyKind::OpaqueDef(_, lifetimes, _), .. }) = opaque_ty_node else { bug!("unexpected {opaque_ty_node:?}") }; diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 3849c0893f4..1aa9c6929f8 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -732,7 +732,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { let Some(def_id) = def_id.as_local() else { continue }; let hir_id = self.tcx.local_def_id_to_hir_id(def_id); // Ensure that the parent of the def is an item, not HRTB - let parent_id = self.tcx.hir().parent_id(hir_id); + let parent_id = self.tcx.parent_hir_id(hir_id); if !parent_id.is_owner() { struct_span_code_err!( self.tcx.dcx(), diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 20a7663f864..c0128afe2bf 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -30,7 +30,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { ); }; - let parent_node_id = tcx.hir().parent_id(hir_id); + let parent_node_id = tcx.parent_hir_id(hir_id); let parent_node = tcx.hir_node(parent_node_id); let (generics, arg_idx) = match parent_node { @@ -79,7 +79,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { } Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. }) - if let Node::TraitRef(trait_ref) = tcx.hir_node(tcx.hir().parent_id(binding_id)) => + if let Node::TraitRef(trait_ref) = tcx.parent_hir_node(binding_id) => { let Some(trait_def_id) = trait_ref.trait_def_id() else { return Ty::new_error_with_message( diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs index 3b1ee2975fd..52ff8b2e45d 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { // Here we check if the reference to the generic type // is from the 'of_trait' field of the enclosing impl - let parent = self.tcx.hir().get_parent(self.path_segment.hir_id); + let parent = self.tcx.parent_hir_node(self.path_segment.hir_id); let parent_item = self.tcx.hir_node_by_def_id( self.tcx.hir().get_parent_item(self.path_segment.hir_id).def_id, ); @@ -770,9 +770,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { num = num_trait_generics_except_self, ); - if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id) - && let hir::Node::Expr(expr) = self.tcx.hir_node(parent_node) - { + if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(self.path_segment.hir_id) { match &expr.kind { hir::ExprKind::Path(qpath) => self .suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path( |
