1
Fork 0

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:
bors 2021-03-17 16:49:46 +00:00
commit b4adc21c4f
61 changed files with 358 additions and 326 deletions

View file

@ -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> {