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_ast/src | |
| 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_ast/src')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/visit.rs | 2 |
3 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 296a570de6b..098e2606a3b 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2107,9 +2107,9 @@ pub enum TyKind { /// A tuple (`(A, B, C, D,...)`). Tup(ThinVec<P<Ty>>), /// An anonymous struct type i.e. `struct { foo: Type }` - AnonStruct(ThinVec<FieldDef>), + AnonStruct(NodeId, ThinVec<FieldDef>), /// An anonymous union type i.e. `union { bar: Type }` - AnonUnion(ThinVec<FieldDef>), + AnonUnion(NodeId, ThinVec<FieldDef>), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`. /// @@ -2161,6 +2161,10 @@ impl TyKind { None } } + + pub fn is_anon_adt(&self) -> bool { + matches!(self, TyKind::AnonStruct(..) | TyKind::AnonUnion(..)) + } } /// Syntax used to declare a trait object. diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 90677151d25..d482ada170e 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -514,7 +514,8 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) { visit_vec(bounds, |bound| vis.visit_param_bound(bound)); } TyKind::MacCall(mac) => vis.visit_mac_call(mac), - TyKind::AnonStruct(fields) | TyKind::AnonUnion(fields) => { + TyKind::AnonStruct(id, fields) | TyKind::AnonUnion(id, fields) => { + vis.visit_id(id); fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); } } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 8d084ee29a7..4aaaa0ba424 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -450,7 +450,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {} TyKind::MacCall(mac) => visitor.visit_mac_call(mac), TyKind::Never | TyKind::CVarArgs => {} - TyKind::AnonStruct(ref fields, ..) | TyKind::AnonUnion(ref fields, ..) => { + TyKind::AnonStruct(_, ref fields) | TyKind::AnonUnion(_, ref fields) => { walk_list!(visitor, visit_field_def, fields) } } |
