mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
def_collector: Do not forget to save indices of fields with multiple attributes
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Duplicate non-builtin attributes can be used on unnamed fields.
|
||||
|
||||
// check-pass
|
||||
|
||||
struct S (
|
||||
#[rustfmt::skip]
|
||||
#[rustfmt::skip]
|
||||
u8
|
||||
);
|
||||
|
||||
fn main() {}
|
||||
Reference in New Issue
Block a user