Skip to content

Commit 2939666

Browse files
committedOct 14, 2015
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
This patch uses the same data structures for structs and enum variants in AST and HIR. These changes in data structures lead to noticeable simplification in most of code dealing with them. I didn't touch the top level, i.e. `ItemStruct` is still `ItemStruct` and not `ItemEnum` with one variant, like in the type checker. As part of this patch, structures and variants get the `kind` field making distinction between "normal" structs, tuple structs and unit structs explicit instead of relying on the number of fields and presence of constructor `NodeId`. In particular, we can now distinguish empty tuple structs from unit structs, which was impossible before! Comprehensive tests for empty structs are added and some improvements to empty struct feature gates are made. Some tests don't pass due to issue #28692 , they are still there for completeness, but are commented out. This patch fixes issue mentioned in #16819 (comment), now emptiness of tuple structs is checked after expansion. It also touches #28750 by providing span for visit_struct_def cc #28336 r? @nrc
2 parents c0dc2cb + 607b8c3 commit 2939666

Some content is hidden

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

64 files changed

+845
-894
lines changed
 

‎src/doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ The currently implemented features of the reference compiler are:
23572357
terms of encapsulation).
23582358
* - `default_type_parameter_fallback` - Allows type parameter defaults to
23592359
influence type inference.
2360-
* - `braced_empty_structs` - Allows use of empty structs with braces.
2360+
* - `braced_empty_structs` - Allows use of empty structs and enum variants with braces.
23612361

23622362
If a feature is promoted to a language feature, then all existing programs will
23632363
start to receive compilation warnings about `#![feature]` directives which enabled

‎src/librustc/front/map/collector.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -134,40 +134,29 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
134134
ItemEnum(ref enum_definition, _) => {
135135
for v in &enum_definition.variants {
136136
let variant_def_index =
137-
self.insert_def(v.node.id,
137+
self.insert_def(v.node.data.id(),
138138
NodeVariant(&**v),
139139
DefPathData::EnumVariant(v.node.name));
140140

141-
match v.node.kind {
142-
TupleVariantKind(ref args) => {
143-
for arg in args {
144-
self.create_def_with_parent(Some(variant_def_index),
145-
arg.id,
146-
DefPathData::PositionalField);
147-
}
148-
}
149-
StructVariantKind(ref def) => {
150-
for field in &def.fields {
151-
self.create_def_with_parent(
152-
Some(variant_def_index),
153-
field.node.id,
154-
DefPathData::Field(field.node.kind));
155-
}
156-
}
141+
for field in v.node.data.fields() {
142+
self.create_def_with_parent(
143+
Some(variant_def_index),
144+
field.node.id,
145+
DefPathData::Field(field.node.kind));
157146
}
158147
}
159148
}
160149
ItemForeignMod(..) => {
161150
}
162151
ItemStruct(ref struct_def, _) => {
163152
// If this is a tuple-like struct, register the constructor.
164-
if let Some(ctor_id) = struct_def.ctor_id {
165-
self.insert_def(ctor_id,
153+
if !struct_def.is_struct() {
154+
self.insert_def(struct_def.id(),
166155
NodeStructCtor(&**struct_def),
167156
DefPathData::StructCtor);
168157
}
169158

170-
for field in &struct_def.fields {
159+
for field in struct_def.fields() {
171160
self.create_def(field.node.id, DefPathData::Field(field.node.kind));
172161
}
173162
}

0 commit comments

Comments
 (0)