ast_lowering: rm separate def_id_parent
no longer necessary as we now always create a ` DefId` for anon-consts
This commit is contained in:
@@ -222,7 +222,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Wrap the expression in an AnonConst.
|
// Wrap the expression in an AnonConst.
|
||||||
let parent_def_id = self.current_def_id_parent;
|
let parent_def_id = self.current_hir_id_owner.def_id;
|
||||||
let node_id = self.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
self.create_def(
|
self.create_def(
|
||||||
parent_def_id,
|
parent_def_id,
|
||||||
|
|||||||
@@ -109,9 +109,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
hir::ConstBlock {
|
hir::ConstBlock {
|
||||||
def_id,
|
def_id,
|
||||||
hir_id: this.lower_node_id(c.id),
|
hir_id: this.lower_node_id(c.id),
|
||||||
body: this.with_def_id_parent(def_id, |this| {
|
body: this.lower_const_body(c.value.span, Some(&c.value)),
|
||||||
this.lower_const_body(c.value.span, Some(&c.value))
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
hir::ExprKind::ConstBlock(c)
|
hir::ExprKind::ConstBlock(c)
|
||||||
@@ -452,7 +450,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
let mut generic_args = ThinVec::new();
|
let mut generic_args = ThinVec::new();
|
||||||
for (idx, arg) in args.iter().cloned().enumerate() {
|
for (idx, arg) in args.iter().cloned().enumerate() {
|
||||||
if legacy_args_idx.contains(&idx) {
|
if legacy_args_idx.contains(&idx) {
|
||||||
let parent_def_id = self.current_def_id_parent;
|
let parent_def_id = self.current_hir_id_owner.def_id;
|
||||||
let node_id = self.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
|
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
|
||||||
let mut visitor = WillCreateDefIdsVisitor {};
|
let mut visitor = WillCreateDefIdsVisitor {};
|
||||||
@@ -753,8 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
lifetime_elision_allowed: false,
|
lifetime_elision_allowed: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
let body = self.with_def_id_parent(closure_def_id, move |this| {
|
let body = self.lower_body(move |this| {
|
||||||
this.lower_body(move |this| {
|
|
||||||
this.coroutine_kind = Some(coroutine_kind);
|
this.coroutine_kind = Some(coroutine_kind);
|
||||||
|
|
||||||
let old_ctx = this.task_context;
|
let old_ctx = this.task_context;
|
||||||
@@ -765,7 +762,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
this.task_context = old_ctx;
|
this.task_context = old_ctx;
|
||||||
|
|
||||||
(params, res)
|
(params, res)
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// `static |<_task_context?>| -> <return_ty> { <body> }`:
|
// `static |<_task_context?>| -> <return_ty> { <body> }`:
|
||||||
@@ -1050,7 +1046,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
|
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
|
||||||
|
|
||||||
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
|
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
|
||||||
this.with_def_id_parent(closure_def_id, move |this| {
|
|
||||||
let mut coroutine_kind = if this
|
let mut coroutine_kind = if this
|
||||||
.attrs
|
.attrs
|
||||||
.get(&closure_hir_id.local_id)
|
.get(&closure_hir_id.local_id)
|
||||||
@@ -1069,7 +1064,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
let coroutine_option =
|
let coroutine_option =
|
||||||
this.closure_movability_for_fn(decl, fn_decl_span, coroutine_kind, movability);
|
this.closure_movability_for_fn(decl, fn_decl_span, coroutine_kind, movability);
|
||||||
(body_id, coroutine_option)
|
(body_id, coroutine_option)
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
|
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
|
||||||
@@ -1159,7 +1153,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let body = self.with_new_scopes(fn_decl_span, |this| {
|
let body = self.with_new_scopes(fn_decl_span, |this| {
|
||||||
this.with_def_id_parent(closure_def_id, |this| {
|
|
||||||
let inner_decl =
|
let inner_decl =
|
||||||
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
|
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
|
||||||
|
|
||||||
@@ -1180,7 +1173,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
(parameters, expr)
|
(parameters, expr)
|
||||||
});
|
});
|
||||||
body_id
|
body_id
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
|
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
|
||||||
|
|||||||
@@ -117,18 +117,6 @@ struct LoweringContext<'a, 'hir> {
|
|||||||
is_in_dyn_type: bool,
|
is_in_dyn_type: bool,
|
||||||
|
|
||||||
current_hir_id_owner: hir::OwnerId,
|
current_hir_id_owner: hir::OwnerId,
|
||||||
/// Why do we need this in addition to [`Self::current_hir_id_owner`]?
|
|
||||||
///
|
|
||||||
/// Currently (as of June 2024), anonymous constants are not HIR owners; however,
|
|
||||||
/// they do get their own DefIds. Some of these DefIds have to be created during
|
|
||||||
/// AST lowering, rather than def collection, because we can't tell until after
|
|
||||||
/// name resolution whether an anonymous constant will end up instead being a
|
|
||||||
/// [`hir::ConstArgKind::Path`]. However, to compute which generics are
|
|
||||||
/// available to an anonymous constant nested inside another, we need to make
|
|
||||||
/// sure that the parent is recorded as the parent anon const, not the enclosing
|
|
||||||
/// item. So we need to track parent defs differently from HIR owners, since they
|
|
||||||
/// will be finer-grained in the case of anon consts.
|
|
||||||
current_def_id_parent: LocalDefId,
|
|
||||||
item_local_id_counter: hir::ItemLocalId,
|
item_local_id_counter: hir::ItemLocalId,
|
||||||
trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
|
trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
|
||||||
|
|
||||||
@@ -161,7 +149,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
attrs: SortedMap::default(),
|
attrs: SortedMap::default(),
|
||||||
children: Vec::default(),
|
children: Vec::default(),
|
||||||
current_hir_id_owner: hir::CRATE_OWNER_ID,
|
current_hir_id_owner: hir::CRATE_OWNER_ID,
|
||||||
current_def_id_parent: CRATE_DEF_ID,
|
|
||||||
item_local_id_counter: hir::ItemLocalId::ZERO,
|
item_local_id_counter: hir::ItemLocalId::ZERO,
|
||||||
ident_and_label_to_local_id: Default::default(),
|
ident_and_label_to_local_id: Default::default(),
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -565,7 +552,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
debug_assert_eq!(_old, None);
|
debug_assert_eq!(_old, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = self.with_def_id_parent(def_id, f);
|
let item = f(self);
|
||||||
debug_assert_eq!(def_id, item.def_id().def_id);
|
debug_assert_eq!(def_id, item.def_id().def_id);
|
||||||
// `f` should have consumed all the elements in these vectors when constructing `item`.
|
// `f` should have consumed all the elements in these vectors when constructing `item`.
|
||||||
debug_assert!(self.impl_trait_defs.is_empty());
|
debug_assert!(self.impl_trait_defs.is_empty());
|
||||||
@@ -590,13 +577,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
|
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_def_id_parent<T>(&mut self, parent: LocalDefId, f: impl FnOnce(&mut Self) -> T) -> T {
|
|
||||||
let current_def_id_parent = std::mem::replace(&mut self.current_def_id_parent, parent);
|
|
||||||
let result = f(self);
|
|
||||||
self.current_def_id_parent = current_def_id_parent;
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
|
fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
|
||||||
let attrs = std::mem::take(&mut self.attrs);
|
let attrs = std::mem::take(&mut self.attrs);
|
||||||
let mut bodies = std::mem::take(&mut self.bodies);
|
let mut bodies = std::mem::take(&mut self.bodies);
|
||||||
@@ -773,7 +753,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
LifetimeRes::Fresh { param, kind, .. } => {
|
LifetimeRes::Fresh { param, kind, .. } => {
|
||||||
// Late resolution delegates to us the creation of the `LocalDefId`.
|
// Late resolution delegates to us the creation of the `LocalDefId`.
|
||||||
let _def_id = self.create_def(
|
let _def_id = self.create_def(
|
||||||
self.current_hir_id_owner.def_id, // FIXME: should this use self.current_def_id_parent?
|
self.current_hir_id_owner.def_id,
|
||||||
param,
|
param,
|
||||||
kw::UnderscoreLifetime,
|
kw::UnderscoreLifetime,
|
||||||
DefKind::LifetimeParam,
|
DefKind::LifetimeParam,
|
||||||
@@ -1466,17 +1446,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
|
let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
|
||||||
debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
|
debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
|
||||||
|
|
||||||
let opaque_ty_def = self.with_def_id_parent(opaque_ty_def_id, |this| {
|
let bounds = lower_item_bounds(self);
|
||||||
let bounds = lower_item_bounds(this);
|
|
||||||
let opaque_ty_def = hir::OpaqueTy {
|
let opaque_ty_def = hir::OpaqueTy {
|
||||||
hir_id: opaque_ty_hir_id,
|
hir_id: opaque_ty_hir_id,
|
||||||
def_id: opaque_ty_def_id,
|
def_id: opaque_ty_def_id,
|
||||||
bounds,
|
bounds,
|
||||||
origin,
|
origin,
|
||||||
span: this.lower_span(opaque_ty_span),
|
span: self.lower_span(opaque_ty_span),
|
||||||
};
|
};
|
||||||
this.arena.alloc(opaque_ty_def)
|
let opaque_ty_def = self.arena.alloc(opaque_ty_def);
|
||||||
});
|
|
||||||
|
|
||||||
hir::TyKind::OpaqueDef(opaque_ty_def)
|
hir::TyKind::OpaqueDef(opaque_ty_def)
|
||||||
}
|
}
|
||||||
@@ -2084,7 +2062,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
} else {
|
} else {
|
||||||
// Construct an AnonConst where the expr is the "ty"'s path.
|
// Construct an AnonConst where the expr is the "ty"'s path.
|
||||||
|
|
||||||
let parent_def_id = self.current_def_id_parent;
|
let parent_def_id = self.current_hir_id_owner.def_id;
|
||||||
let node_id = self.next_node_id();
|
let node_id = self.next_node_id();
|
||||||
let span = self.lower_span(span);
|
let span = self.lower_span(span);
|
||||||
|
|
||||||
@@ -2108,9 +2086,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
self.arena.alloc(hir::AnonConst {
|
self.arena.alloc(hir::AnonConst {
|
||||||
def_id,
|
def_id,
|
||||||
hir_id,
|
hir_id,
|
||||||
body: this.with_def_id_parent(def_id, |this| {
|
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
|
||||||
this.lower_const_body(path_expr.span, Some(&path_expr))
|
|
||||||
}),
|
|
||||||
span,
|
span,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -2178,9 +2154,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
hir::AnonConst {
|
hir::AnonConst {
|
||||||
def_id,
|
def_id,
|
||||||
hir_id,
|
hir_id,
|
||||||
body: this.with_def_id_parent(def_id, |this| {
|
body: this.lower_const_body(c.value.span, Some(&c.value)),
|
||||||
this.lower_const_body(c.value.span, Some(&c.value))
|
|
||||||
}),
|
|
||||||
span: this.lower_span(c.value.span),
|
span: this.lower_span(c.value.span),
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user