提交 37bb0c7f 编写于 作者: V Vadim Petrochenkov

def_collector: Do not forget to save indices of fields with multiple attributes

上级 e41ced3f
......@@ -80,15 +80,16 @@ fn visit_async_fn(
}
fn collect_field(&mut self, field: &'a StructField, index: Option<usize>) {
let index = |this: &Self| index.unwrap_or_else(|| {
let node_id = NodeId::placeholder_from_expn_id(this.expansion);
this.definitions.placeholder_field_index(node_id)
});
if field.is_placeholder {
self.definitions.set_placeholder_field_index(field.id, index(self));
self.visit_macro_invoc(field.id);
} else {
let name = field.ident.map(|ident| ident.name)
.or_else(|| index.map(sym::integer))
.unwrap_or_else(|| {
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
sym::integer(self.definitions.placeholder_field_index(node_id))
});
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
self.with_parent(def, |this| visit::walk_struct_field(this, field));
}
......@@ -190,9 +191,6 @@ fn visit_variant_data(&mut self, data: &'a VariantData) {
// and every such attribute expands into a single field after it's resolved.
for (index, field) in data.fields().iter().enumerate() {
self.collect_field(field, Some(index));
if field.is_placeholder && field.ident.is_none() {
self.definitions.set_placeholder_field_index(field.id, index);
}
}
}
......
// Duplicate non-builtin attributes can be used on unnamed fields.
// check-pass
struct S (
#[rustfmt::skip]
#[rustfmt::skip]
u8
);
fn main() {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册