Rollup merge of #106403 - compiler-errors:rename-hir-methods, r=cjgillot
Rename `hir::Map::{get_,find_}parent_node` to `hir::Map::{,opt_}parent_id`, and add `hir::Map::{get,find}_parent` The `hir::Map::get_parent_node` function doesn't return a `Node`, and I think that's quite confusing. Let's rename it to something that sounds more like something that gets the parent hir id => `hir::Map::parent_id`. Same with `find_parent_node` => `opt_parent_id`. Also, combine `hir.get(hir.parent_id(hir_id))` and similar `hir.find(hir.parent_id(hir_id))` function into new functions that actually retrieve the parent node in one call. This last commit is the only one that might need to be looked at closely.
This commit is contained in:
commit
5ce6311f34
54 changed files with 170 additions and 179 deletions
|
@ -2936,7 +2936,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
|
||||
hir.get(fn_hir_id) else { return None };
|
||||
let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(i), .. }) =
|
||||
hir.get(hir.get_parent_node(fn_hir_id)) else { bug!("ImplItem should have Impl parent") };
|
||||
hir.get_parent(fn_hir_id) else { bug!("ImplItem should have Impl parent") };
|
||||
|
||||
let trait_ref = self.instantiate_mono_trait_ref(
|
||||
i.of_trait.as_ref()?,
|
||||
|
|
|
@ -213,7 +213,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
|
|||
is_fn = true;
|
||||
|
||||
// Check if parent is const or static
|
||||
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id);
|
||||
let parent_id = tcx.hir().parent_id(hir_ty.hir_id);
|
||||
let parent_node = tcx.hir().get(parent_id);
|
||||
|
||||
is_const_or_static = matches!(
|
||||
|
@ -1109,7 +1109,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> 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(tcx.hir().get_parent_node(hir_id))
|
||||
tcx.hir().get_parent(hir_id)
|
||||
&& i.of_trait.is_some()
|
||||
{
|
||||
<dyn AstConv<'_>>::ty_of_fn(
|
||||
|
|
|
@ -103,7 +103,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
// `min_const_generics`.
|
||||
Some(parent_def_id.to_def_id())
|
||||
} else {
|
||||
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
|
||||
let parent_node = tcx.hir().get_parent(hir_id);
|
||||
match parent_node {
|
||||
// HACK(eddyb) this provides the correct generics for repeat
|
||||
// expressions' count (i.e. `N` in `[x; N]`), and explicit
|
||||
|
@ -320,7 +320,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
|
||||
// provide junk type parameter defs for const blocks.
|
||||
if let Node::AnonConst(_) = node {
|
||||
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
|
||||
let parent_node = tcx.hir().get_parent(hir_id);
|
||||
if let Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) = parent_node {
|
||||
params.push(ty::GenericParamDef {
|
||||
index: next_index(),
|
||||
|
|
|
@ -682,7 +682,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
};
|
||||
let hir_id = self.tcx.hir().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().get_parent_node(hir_id);
|
||||
let parent_id = self.tcx.hir().parent_id(hir_id);
|
||||
if !parent_id.is_owner() {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
|
|
@ -270,7 +270,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
|||
// 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().get_parent_node(hir_id);
|
||||
let opaque_ty_id = tcx.hir().parent_id(hir_id);
|
||||
let opaque_ty_node = tcx.hir().get(opaque_ty_id);
|
||||
let Node::Ty(&Ty { kind: TyKind::OpaqueDef(_, lifetimes, _), .. }) = opaque_ty_node else {
|
||||
bug!("unexpected {opaque_ty_node:?}")
|
||||
|
|
|
@ -28,7 +28,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
|
|||
_ => return None,
|
||||
};
|
||||
|
||||
let parent_node_id = tcx.hir().get_parent_node(hir_id);
|
||||
let parent_node_id = tcx.hir().parent_id(hir_id);
|
||||
let parent_node = tcx.hir().get(parent_node_id);
|
||||
|
||||
let (generics, arg_idx) = match parent_node {
|
||||
|
@ -402,7 +402,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
}
|
||||
|
||||
Node::AnonConst(_) => {
|
||||
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
|
||||
let parent_node = tcx.hir().get_parent(hir_id);
|
||||
match parent_node {
|
||||
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. })
|
||||
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
|
||||
|
@ -445,7 +445,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
..
|
||||
},
|
||||
) if let Node::TraitRef(trait_ref) =
|
||||
tcx.hir().get(tcx.hir().get_parent_node(binding_id))
|
||||
tcx.hir().get_parent(binding_id)
|
||||
&& e.hir_id == hir_id =>
|
||||
{
|
||||
let Some(trait_def_id) = trait_ref.trait_def_id() else {
|
||||
|
@ -472,7 +472,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
Node::TypeBinding(
|
||||
binding @ &TypeBinding { hir_id: binding_id, gen_args, ref kind, .. },
|
||||
) if let Node::TraitRef(trait_ref) =
|
||||
tcx.hir().get(tcx.hir().get_parent_node(binding_id))
|
||||
tcx.hir().get_parent(binding_id)
|
||||
&& let Some((idx, _)) =
|
||||
gen_args.args.iter().enumerate().find(|(_, arg)| {
|
||||
if let GenericArg::Const(ct) = arg {
|
||||
|
|
|
@ -716,7 +716,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
num = num_trait_generics_except_self,
|
||||
);
|
||||
|
||||
if let Some(parent_node) = self.tcx.hir().find_parent_node(self.path_segment.hir_id)
|
||||
if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id)
|
||||
&& let Some(parent_node) = self.tcx.hir().find(parent_node)
|
||||
&& let hir::Node::Expr(expr) = parent_node {
|
||||
match expr.kind {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue