Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead

Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
This commit is contained in:
bors
2022-11-17 07:42:27 +00:00
63 changed files with 449 additions and 549 deletions

View File

@@ -830,8 +830,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
),
};
let hir_id = self.lower_node_id(node_id);
let def_id = self.local_def_id(node_id);
Some(hir::GenericParam {
hir_id,
def_id,
name,
span: self.lower_span(ident.span),
pure_wrt_drop: false,
@@ -1165,7 +1167,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let node_id = self.next_node_id();
// Add a definition for the in-band const def.
self.create_def(
let def_id = self.create_def(
parent_def_id.def_id,
node_id,
DefPathData::AnonConst,
@@ -1181,6 +1183,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
};
let ct = self.with_new_scopes(|this| hir::AnonConst {
def_id,
hir_id: this.lower_node_id(node_id),
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
});
@@ -1528,6 +1531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericParam {
hir_id,
def_id: lctx.local_def_id(new_node_id),
name,
span: lifetime.ident.span,
pure_wrt_drop: false,
@@ -1985,6 +1989,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericParam {
hir_id,
def_id: this.local_def_id(new_node_id),
name,
span: lifetime.ident.span,
pure_wrt_drop: false,
@@ -2183,6 +2188,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_attrs(hir_id, &param.attrs);
hir::GenericParam {
hir_id,
def_id: self.local_def_id(param.id),
name,
span: self.lower_span(param.span()),
pure_wrt_drop: self.tcx.sess.contains_name(&param.attrs, sym::may_dangle),
@@ -2287,6 +2293,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Set the name to `impl Bound1 + Bound2`.
let param = hir::GenericParam {
hir_id: self.lower_node_id(node_id),
def_id,
name: ParamName::Plain(self.lower_ident(ident)),
pure_wrt_drop: false,
span: self.lower_span(span),
@@ -2347,6 +2354,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
self.with_new_scopes(|this| hir::AnonConst {
def_id: this.local_def_id(c.id),
hir_id: this.lower_node_id(c.id),
body: this.lower_const_body(c.value.span, Some(&c.value)),
})