Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8f6888a

Browse files
authored
Unrolled build for rust-lang#120872
Rollup merge of rust-lang#120872 - petrochenkov:opthirpar, r=cjgillot hir: Refactor getters for HIR parents See individual commits. I ended up removing on of the FIXMEs from rust-lang#120206 instead of addressing it.
2 parents 520b0b2 + b072838 commit 8f6888a

File tree

79 files changed

+263
-342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+263
-342
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
403403
}
404404
}
405405
let typeck = self.infcx.tcx.typeck(self.mir_def_id());
406-
let hir_id = hir.parent_id(expr.hir_id);
407-
let parent = self.infcx.tcx.hir_node(hir_id);
406+
let parent = self.infcx.tcx.parent_hir_node(expr.hir_id);
408407
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
409408
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind
410409
&& let Some(def_id) = typeck.type_dependent_def_id(parent_expr.hir_id)
@@ -1660,8 +1659,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16601659

16611660
// Check that the parent of the closure is a method call,
16621661
// with receiver matching with local's type (modulo refs)
1663-
let parent = hir.parent_id(closure_expr.hir_id);
1664-
if let hir::Node::Expr(parent) = tcx.hir_node(parent) {
1662+
if let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_expr.hir_id) {
16651663
if let hir::ExprKind::MethodCall(_, recv, ..) = parent.kind {
16661664
let recv_ty = typeck_results.expr_ty(recv);
16671665

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
944944
let hir = self.infcx.tcx.hir();
945945
let closure_id = self.mir_hir_id();
946946
let closure_span = self.infcx.tcx.def_span(self.mir_def_id());
947-
let fn_call_id = hir.parent_id(closure_id);
947+
let fn_call_id = self.infcx.tcx.parent_hir_id(closure_id);
948948
let node = self.infcx.tcx.hir_node(fn_call_id);
949949
let def_id = hir.enclosing_body_owner(fn_call_id);
950950
let mut look_at_return = true;
@@ -1034,7 +1034,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10341034
if let InstanceDef::Item(def_id) = source.instance
10351035
&& let Some(Node::Expr(hir::Expr { hir_id, kind, .. })) = hir.get_if_local(def_id)
10361036
&& let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind
1037-
&& let Some(Node::Expr(expr)) = hir.find_parent(*hir_id)
1037+
&& let Node::Expr(expr) = self.infcx.tcx.parent_hir_node(*hir_id)
10381038
{
10391039
let mut cur_expr = expr;
10401040
while let ExprKind::MethodCall(path_segment, recv, _, _) = cur_expr.kind {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
214214
if let Some(id) = placeholder.bound.kind.get_id()
215215
&& let Some(placeholder_id) = id.as_local()
216216
&& let gat_hir_id = self.infcx.tcx.local_def_id_to_hir_id(placeholder_id)
217-
&& let Some(generics_impl) =
218-
hir.get_parent(hir.parent_id(gat_hir_id)).generics()
217+
&& let Some(generics_impl) = self
218+
.infcx
219+
.tcx
220+
.parent_hir_node(self.infcx.tcx.parent_hir_id(gat_hir_id))
221+
.generics()
219222
{
220223
Some((gat_hir_id, generics_impl))
221224
} else {

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,10 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
131131
let local_def_id = def_id.expect_local();
132132
let hir_id = tcx.local_def_id_to_hir_id(local_def_id);
133133

134-
let Some(parent) = tcx.hir().opt_parent_id(hir_id) else { return false };
135-
136-
if !tcx.is_const_trait_impl_raw(parent.owner.def_id.to_def_id()) {
134+
let parent_owner_id = tcx.parent_hir_id(hir_id).owner;
135+
if !tcx.is_const_trait_impl_raw(parent_owner_id.to_def_id()) {
137136
return false;
138137
}
139138

140-
tcx.lookup_const_stability(parent.owner).is_some_and(|stab| stab.is_const_stable())
139+
tcx.lookup_const_stability(parent_owner_id).is_some_and(|stab| stab.is_const_stable())
141140
}

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,7 @@ impl<'hir> Node<'hir> {
35083508
/// ```ignore (illustrative)
35093509
/// ctor
35103510
/// .ctor_hir_id()
3511-
/// .and_then(|ctor_id| tcx.hir().find_parent(ctor_id))
3511+
/// .map(|ctor_id| tcx.parent_hir_node(ctor_id))
35123512
/// .and_then(|parent| parent.ident())
35133513
/// ```
35143514
pub fn ident(&self) -> Option<Ident> {

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,14 +2749,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27492749
arg_idx: Option<usize>,
27502750
) -> Option<Ty<'tcx>> {
27512751
let tcx = self.tcx();
2752-
let hir = tcx.hir();
2753-
27542752
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
27552753
tcx.hir_node(fn_hir_id)
27562754
else {
27572755
return None;
27582756
};
2759-
let i = hir.get_parent(fn_hir_id).expect_item().expect_impl();
2757+
let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl();
27602758

27612759
let trait_ref =
27622760
self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty));

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,8 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
224224
is_fn = true;
225225

226226
// Check if parent is const or static
227-
let parent_id = tcx.hir().parent_id(hir_ty.hir_id);
228-
let parent_node = tcx.hir_node(parent_id);
229-
230227
is_const_or_static = matches!(
231-
parent_node,
228+
tcx.parent_hir_node(hir_ty.hir_id),
232229
Node::Item(&hir::Item {
233230
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
234231
..
@@ -1085,7 +1082,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
10851082

10861083
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
10871084
// Do not try to infer the return type for a impl method coming from a trait
1088-
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.hir().get_parent(hir_id)
1085+
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id)
10891086
&& i.of_trait.is_some()
10901087
{
10911088
icx.astconv().ty_of_fn(

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
5151
// of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed.
5252
None
5353
} else if tcx.features().generic_const_exprs {
54-
let parent_node = tcx.hir().get_parent(hir_id);
54+
let parent_node = tcx.parent_hir_node(hir_id);
5555
if let Node::Variant(Variant { disr_expr: Some(constant), .. }) = parent_node
5656
&& constant.hir_id == hir_id
5757
{
@@ -113,7 +113,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
113113
Some(parent_def_id.to_def_id())
114114
}
115115
} else {
116-
let parent_node = tcx.hir().get_parent(hir_id);
116+
let parent_node = tcx.parent_hir_node(hir_id);
117117
match parent_node {
118118
// HACK(eddyb) this provides the correct generics for repeat
119119
// expressions' count (i.e. `N` in `[x; N]`), and explicit

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
315315
// We create bi-directional Outlives predicates between the original
316316
// and the duplicated parameter, to ensure that they do not get out of sync.
317317
if let Node::Item(&Item { kind: ItemKind::OpaqueTy(..), .. }) = node {
318-
let opaque_ty_id = tcx.hir().parent_id(hir_id);
319-
let opaque_ty_node = tcx.hir_node(opaque_ty_id);
318+
let opaque_ty_node = tcx.parent_hir_node(hir_id);
320319
let Node::Ty(&Ty { kind: TyKind::OpaqueDef(_, lifetimes, _), .. }) = opaque_ty_node else {
321320
bug!("unexpected {opaque_ty_node:?}")
322321
};

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
732732
let Some(def_id) = def_id.as_local() else { continue };
733733
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
734734
// Ensure that the parent of the def is an item, not HRTB
735-
let parent_id = self.tcx.hir().parent_id(hir_id);
735+
let parent_id = self.tcx.parent_hir_id(hir_id);
736736
if !parent_id.is_owner() {
737737
struct_span_code_err!(
738738
self.tcx.dcx(),

0 commit comments

Comments
 (0)