diff options
| author | bors <bors@rust-lang.org> | 2024-02-12 14:51:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-12 14:51:15 +0000 |
| commit | bdc15928c8119a86d15e2946cb54851264607842 (patch) | |
| tree | d5b51d8a541e073ba30e0d8c5803760cfdb73608 /compiler/rustc_mir_build/src/thir/cx/expr.rs | |
| parent | ed195328689e052b5270b25d0e410b491914fc71 (diff) | |
| parent | 0dbd6e9572c7c2bac7922116d6cd9357177ccbc9 (diff) | |
| download | rust-bdc15928c8119a86d15e2946cb54851264607842.tar.gz rust-bdc15928c8119a86d15e2946cb54851264607842.zip | |
Auto merge of #115367 - frank-king:feature/unnamed-fields-hir, r=davidtwco
Lowering unnamed fields and anonymous adt This implements #49804. Goals: - [x] lowering anonymous ADTs from AST to HIR - [x] generating definitions of anonymous ADTs - [x] uniqueness check of the unnamed fields - [x] field projection of anonymous ADTs - [x] `#[repr(C)]` check of the anonymous ADTs Non-Goals (will be in the next PRs) - capturing generic params for the anonymous ADTs from the parent ADT - pattern matching of anonymous ADTs - structural expressions of anonymous ADTs - rustdoc support of anonymous ADTs
Diffstat (limited to 'compiler/rustc_mir_build/src/thir/cx/expr.rs')
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/cx/expr.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 35adcc33480..79719f6f4cc 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -734,11 +734,21 @@ impl<'tcx> Cx<'tcx> { }); ExprKind::Loop { body } } - hir::ExprKind::Field(source, ..) => ExprKind::Field { - lhs: self.mirror_expr(source), - variant_index: FIRST_VARIANT, - name: self.typeck_results.field_index(expr.hir_id), - }, + hir::ExprKind::Field(source, ..) => { + let mut kind = ExprKind::Field { + lhs: self.mirror_expr(source), + variant_index: FIRST_VARIANT, + name: self.typeck_results.field_index(expr.hir_id), + }; + let nested_field_tys_and_indices = + self.typeck_results.nested_field_tys_and_indices(expr.hir_id); + for &(ty, idx) in nested_field_tys_and_indices { + let expr = Expr { temp_lifetime, ty, span: source.span, kind }; + let lhs = self.thir.exprs.push(expr); + kind = ExprKind::Field { lhs, variant_index: FIRST_VARIANT, name: idx }; + } + kind + } hir::ExprKind::Cast(source, cast_ty) => { // Check for a user-given type annotation on this `cast` let user_provided_types = self.typeck_results.user_provided_types(); |
