Auto merge of #83188 - petrochenkov:field, r=lcnr
ast/hir: Rename field-related structures I always forget what `ast::Field` and `ast::StructField` mean despite working with AST for long time, so this PR changes the naming to less confusing and more consistent. - `StructField` -> `FieldDef` ("field definition") - `Field` -> `ExprField` ("expression field", not "field expression") - `FieldPat` -> `PatField` ("pattern field", not "field pattern") Various visiting and other methods working with the fields are renamed correspondingly too. The second commit reduces the size of `ExprKind` by boxing fields of `ExprKind::Struct` in preparation for https://github.com/rust-lang/rust/pull/80080.
This commit is contained in:
commit
b4adc21c4f
61 changed files with 358 additions and 326 deletions
|
@ -224,8 +224,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
ExprKind::InlineAsm(ref asm) => self.lower_expr_asm(e.span, asm),
|
||||
ExprKind::LlvmInlineAsm(ref asm) => self.lower_expr_llvm_asm(asm),
|
||||
ExprKind::Struct(ref path, ref fields, ref rest) => {
|
||||
let rest = match rest {
|
||||
ExprKind::Struct(ref se) => {
|
||||
let rest = match &se.rest {
|
||||
StructRest::Base(e) => Some(self.lower_expr(e)),
|
||||
StructRest::Rest(sp) => {
|
||||
self.sess
|
||||
|
@ -240,11 +240,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
self.arena.alloc(self.lower_qpath(
|
||||
e.id,
|
||||
&None,
|
||||
path,
|
||||
&se.path,
|
||||
ParamMode::Optional,
|
||||
ImplTraitContext::disallowed(),
|
||||
)),
|
||||
self.arena.alloc_from_iter(fields.iter().map(|x| self.lower_field(x))),
|
||||
self.arena
|
||||
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
|
||||
rest,
|
||||
)
|
||||
}
|
||||
|
@ -1110,10 +1111,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
}
|
||||
// Structs.
|
||||
ExprKind::Struct(path, fields, rest) => {
|
||||
let field_pats = self.arena.alloc_from_iter(fields.iter().map(|f| {
|
||||
ExprKind::Struct(se) => {
|
||||
let field_pats = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
|
||||
let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments);
|
||||
hir::FieldPat {
|
||||
hir::PatField {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
pat,
|
||||
|
@ -1124,11 +1125,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let qpath = self.lower_qpath(
|
||||
lhs.id,
|
||||
&None,
|
||||
path,
|
||||
&se.path,
|
||||
ParamMode::Optional,
|
||||
ImplTraitContext::disallowed(),
|
||||
);
|
||||
let fields_omitted = match rest {
|
||||
let fields_omitted = match &se.rest {
|
||||
StructRest::Base(e) => {
|
||||
self.sess
|
||||
.struct_span_err(
|
||||
|
@ -1244,7 +1245,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| {
|
||||
let expr = self.lower_expr(&e);
|
||||
let ident = Ident::new(Symbol::intern(s), e.span);
|
||||
self.field(ident, expr, e.span)
|
||||
self.expr_field(ident, expr, e.span)
|
||||
}),
|
||||
);
|
||||
|
||||
|
@ -1657,8 +1658,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
hir::ExprKind::LlvmInlineAsm(self.arena.alloc(hir_asm))
|
||||
}
|
||||
|
||||
fn lower_field(&mut self, f: &Field) -> hir::Field<'hir> {
|
||||
hir::Field {
|
||||
fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> {
|
||||
hir::ExprField {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
expr: self.lower_expr(&f.expr),
|
||||
|
@ -2155,8 +2156,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
hir::Expr { hir_id, kind, span }
|
||||
}
|
||||
|
||||
fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {
|
||||
hir::Field { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
|
||||
fn expr_field(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
expr: &'hir hir::Expr<'hir>,
|
||||
span: Span,
|
||||
) -> hir::ExprField<'hir> {
|
||||
hir::ExprField { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
|
||||
}
|
||||
|
||||
fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
|
||||
|
|
|
@ -769,7 +769,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
match *vdata {
|
||||
VariantData::Struct(ref fields, recovered) => hir::VariantData::Struct(
|
||||
self.arena
|
||||
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_struct_field(f))),
|
||||
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
|
||||
recovered,
|
||||
),
|
||||
VariantData::Tuple(ref fields, id) => {
|
||||
|
@ -777,7 +777,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
self.alias_attrs(ctor_id, parent_id);
|
||||
hir::VariantData::Tuple(
|
||||
self.arena.alloc_from_iter(
|
||||
fields.iter().enumerate().map(|f| self.lower_struct_field(f)),
|
||||
fields.iter().enumerate().map(|f| self.lower_field_def(f)),
|
||||
),
|
||||
ctor_id,
|
||||
)
|
||||
|
@ -790,7 +790,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField<'hir> {
|
||||
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
|
||||
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
|
||||
let t = self.lower_path_ty(
|
||||
&f.ty,
|
||||
|
@ -805,7 +805,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
};
|
||||
let hir_id = self.lower_node_id(f.id);
|
||||
self.lower_attrs(hir_id, &f.attrs);
|
||||
hir::StructField {
|
||||
hir::FieldDef {
|
||||
span: f.span,
|
||||
hir_id,
|
||||
ident: match f.ident {
|
||||
|
|
|
@ -2559,8 +2559,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
&mut self,
|
||||
span: Span,
|
||||
pat: &'hir hir::Pat<'hir>,
|
||||
) -> &'hir [hir::FieldPat<'hir>] {
|
||||
let field = hir::FieldPat {
|
||||
) -> &'hir [hir::PatField<'hir>] {
|
||||
let field = hir::PatField {
|
||||
hir_id: self.next_id(),
|
||||
ident: Ident::new(sym::integer(0), span),
|
||||
is_shorthand: false,
|
||||
|
@ -2574,7 +2574,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
&mut self,
|
||||
span: Span,
|
||||
lang_item: hir::LangItem,
|
||||
fields: &'hir [hir::FieldPat<'hir>],
|
||||
fields: &'hir [hir::PatField<'hir>],
|
||||
) -> &'hir hir::Pat<'hir> {
|
||||
let qpath = hir::QPath::LangItem(lang_item, span);
|
||||
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
|
||||
|
|
|
@ -56,7 +56,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
ImplTraitContext::disallowed(),
|
||||
);
|
||||
|
||||
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::FieldPat {
|
||||
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
|
||||
hir_id: self.next_id(),
|
||||
ident: f.ident,
|
||||
pat: self.lower_pat(&f.pat),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue