Skip to content

Commit bdc1592

Browse files
committedFeb 12, 2024
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
2 parents ed19532 + 0dbd6e9 commit bdc1592

File tree

60 files changed

+3273
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3273
-259
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,9 +2107,9 @@ pub enum TyKind {
21072107
/// A tuple (`(A, B, C, D,...)`).
21082108
Tup(ThinVec<P<Ty>>),
21092109
/// An anonymous struct type i.e. `struct { foo: Type }`
2110-
AnonStruct(ThinVec<FieldDef>),
2110+
AnonStruct(NodeId, ThinVec<FieldDef>),
21112111
/// An anonymous union type i.e. `union { bar: Type }`
2112-
AnonUnion(ThinVec<FieldDef>),
2112+
AnonUnion(NodeId, ThinVec<FieldDef>),
21132113
/// A path (`module::module::...::Type`), optionally
21142114
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
21152115
///
@@ -2161,6 +2161,10 @@ impl TyKind {
21612161
None
21622162
}
21632163
}
2164+
2165+
pub fn is_anon_adt(&self) -> bool {
2166+
matches!(self, TyKind::AnonStruct(..) | TyKind::AnonUnion(..))
2167+
}
21642168
}
21652169

21662170
/// Syntax used to declare a trait object.

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
514514
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
515515
}
516516
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
517-
TyKind::AnonStruct(fields) | TyKind::AnonUnion(fields) => {
517+
TyKind::AnonStruct(id, fields) | TyKind::AnonUnion(id, fields) => {
518+
vis.visit_id(id);
518519
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
519520
}
520521
}

0 commit comments

Comments
 (0)
Please sign in to comment.