Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.
So they match the order of the parts in the source code, e.g.:
```
struct Foo<T, U> { t: T, u: U }
<-><----> <------------>
/ | \
ident generics variant_data
```
r? `@fee1-dead`
This commit is contained in:
commit
0ac0285c3f
20 changed files with 54 additions and 56 deletions
|
|
@ -3417,9 +3417,9 @@ impl Item {
|
|||
ItemKind::Fn(i) => Some(&i.generics),
|
||||
ItemKind::TyAlias(i) => Some(&i.generics),
|
||||
ItemKind::TraitAlias(_, generics, _)
|
||||
| ItemKind::Enum(_, _, generics)
|
||||
| ItemKind::Struct(_, _, generics)
|
||||
| ItemKind::Union(_, _, generics) => Some(&generics),
|
||||
| ItemKind::Enum(_, generics, _)
|
||||
| ItemKind::Struct(_, generics, _)
|
||||
| ItemKind::Union(_, generics, _) => Some(&generics),
|
||||
ItemKind::Trait(i) => Some(&i.generics),
|
||||
ItemKind::Impl(i) => Some(&i.generics),
|
||||
}
|
||||
|
|
@ -3663,15 +3663,15 @@ pub enum ItemKind {
|
|||
/// An enum definition (`enum`).
|
||||
///
|
||||
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
|
||||
Enum(Ident, EnumDef, Generics),
|
||||
Enum(Ident, Generics, EnumDef),
|
||||
/// A struct definition (`struct`).
|
||||
///
|
||||
/// E.g., `struct Foo<A> { x: A }`.
|
||||
Struct(Ident, VariantData, Generics),
|
||||
Struct(Ident, Generics, VariantData),
|
||||
/// A union definition (`union`).
|
||||
///
|
||||
/// E.g., `union Foo<A, B> { x: A, y: B }`.
|
||||
Union(Ident, VariantData, Generics),
|
||||
Union(Ident, Generics, VariantData),
|
||||
/// A trait declaration (`trait`).
|
||||
///
|
||||
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
|
||||
|
|
@ -3688,10 +3688,8 @@ pub enum ItemKind {
|
|||
///
|
||||
/// E.g., `foo!(..)`.
|
||||
MacCall(P<MacCall>),
|
||||
|
||||
/// A macro definition.
|
||||
MacroDef(Ident, MacroDef),
|
||||
|
||||
/// A single delegation item (`reuse`).
|
||||
///
|
||||
/// E.g. `reuse <Type as Trait>::name { target_expr_template }`.
|
||||
|
|
@ -3767,9 +3765,9 @@ impl ItemKind {
|
|||
Self::Fn(box Fn { generics, .. })
|
||||
| Self::TyAlias(box TyAlias { generics, .. })
|
||||
| Self::Const(box ConstItem { generics, .. })
|
||||
| Self::Enum(_, _, generics)
|
||||
| Self::Struct(_, _, generics)
|
||||
| Self::Union(_, _, generics)
|
||||
| Self::Enum(_, generics, _)
|
||||
| Self::Struct(_, generics, _)
|
||||
| Self::Union(_, generics, _)
|
||||
| Self::Trait(box Trait { generics, .. })
|
||||
| Self::TraitAlias(_, generics, _)
|
||||
| Self::Impl(box Impl { generics, .. }) => Some(generics),
|
||||
|
|
|
|||
|
|
@ -508,7 +508,7 @@ macro_rules! common_visitor_and_walkers {
|
|||
)?
|
||||
$(<V as Visitor<$lt>>::Result::output())?
|
||||
}
|
||||
ItemKind::Enum(ident, enum_definition, generics) => {
|
||||
ItemKind::Enum(ident, generics, enum_definition) => {
|
||||
try_visit!(vis.visit_ident(ident));
|
||||
try_visit!(vis.visit_generics(generics));
|
||||
$(${ignore($mut)}
|
||||
|
|
@ -516,8 +516,8 @@ macro_rules! common_visitor_and_walkers {
|
|||
)?
|
||||
$(${ignore($lt)}vis.visit_enum_def(enum_definition))?
|
||||
}
|
||||
ItemKind::Struct(ident, variant_data, generics)
|
||||
| ItemKind::Union(ident, variant_data, generics) => {
|
||||
ItemKind::Struct(ident, generics, variant_data)
|
||||
| ItemKind::Union(ident, generics, variant_data) => {
|
||||
try_visit!(vis.visit_ident(ident));
|
||||
try_visit!(vis.visit_generics(generics));
|
||||
vis.visit_variant_data(variant_data)
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
);
|
||||
hir::ItemKind::TyAlias(ident, ty, generics)
|
||||
}
|
||||
ItemKind::Enum(ident, enum_definition, generics) => {
|
||||
ItemKind::Enum(ident, generics, enum_definition) => {
|
||||
let ident = self.lower_ident(*ident);
|
||||
let (generics, variants) = self.lower_generics(
|
||||
generics,
|
||||
|
|
@ -320,7 +320,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
);
|
||||
hir::ItemKind::Enum(ident, hir::EnumDef { variants }, generics)
|
||||
}
|
||||
ItemKind::Struct(ident, struct_def, generics) => {
|
||||
ItemKind::Struct(ident, generics, struct_def) => {
|
||||
let ident = self.lower_ident(*ident);
|
||||
let (generics, struct_def) = self.lower_generics(
|
||||
generics,
|
||||
|
|
@ -330,7 +330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
);
|
||||
hir::ItemKind::Struct(ident, struct_def, generics)
|
||||
}
|
||||
ItemKind::Union(ident, vdata, generics) => {
|
||||
ItemKind::Union(ident, generics, vdata) => {
|
||||
let ident = self.lower_ident(*ident);
|
||||
let (generics, vdata) = self.lower_generics(
|
||||
generics,
|
||||
|
|
|
|||
|
|
@ -1010,7 +1010,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
});
|
||||
self.extern_mod_span = old_item;
|
||||
}
|
||||
ItemKind::Enum(_, def, _) => {
|
||||
ItemKind::Enum(_, _, def) => {
|
||||
for variant in &def.variants {
|
||||
self.visibility_not_permitted(
|
||||
&variant.vis,
|
||||
|
|
@ -1061,7 +1061,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
visit::walk_item(self, item)
|
||||
}
|
||||
ItemKind::Struct(ident, vdata, generics) => match vdata {
|
||||
ItemKind::Struct(ident, generics, vdata) => match vdata {
|
||||
VariantData::Struct { fields, .. } => {
|
||||
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
|
||||
self.visit_generics(generics);
|
||||
|
|
@ -1070,7 +1070,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
_ => visit::walk_item(self, item),
|
||||
},
|
||||
ItemKind::Union(ident, vdata, generics) => {
|
||||
ItemKind::Union(ident, generics, vdata) => {
|
||||
if vdata.fields().is_empty() {
|
||||
self.dcx().emit_err(errors::FieldlessUnion { span: item.span });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,14 +298,14 @@ impl<'a> State<'a> {
|
|||
*defaultness,
|
||||
);
|
||||
}
|
||||
ast::ItemKind::Enum(ident, enum_definition, params) => {
|
||||
self.print_enum_def(enum_definition, params, *ident, item.span, &item.vis);
|
||||
ast::ItemKind::Enum(ident, generics, enum_definition) => {
|
||||
self.print_enum_def(enum_definition, generics, *ident, item.span, &item.vis);
|
||||
}
|
||||
ast::ItemKind::Struct(ident, struct_def, generics) => {
|
||||
ast::ItemKind::Struct(ident, generics, struct_def) => {
|
||||
let (cb, ib) = self.head(visibility_qualified(&item.vis, "struct"));
|
||||
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
|
||||
}
|
||||
ast::ItemKind::Union(ident, struct_def, generics) => {
|
||||
ast::ItemKind::Union(ident, generics, struct_def) => {
|
||||
let (cb, ib) = self.head(visibility_qualified(&item.vis, "union"));
|
||||
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ pub(crate) fn expand_deriving_clone(
|
|||
let is_simple;
|
||||
match item {
|
||||
Annotatable::Item(annitem) => match &annitem.kind {
|
||||
ItemKind::Struct(_, _, Generics { params, .. })
|
||||
| ItemKind::Enum(_, _, Generics { params, .. }) => {
|
||||
ItemKind::Struct(_, Generics { params, .. }, _)
|
||||
| ItemKind::Enum(_, Generics { params, .. }, _) => {
|
||||
let container_id = cx.current_expansion.id.expn_data().parent.expect_local();
|
||||
let has_derive_copy = cx.resolver.has_derive_copy(container_id);
|
||||
if has_derive_copy
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub(crate) fn expand_deriving_partial_ord(
|
|||
|
||||
// Order in which to perform matching
|
||||
let discr_then_data = if let Annotatable::Item(item) = item
|
||||
&& let ItemKind::Enum(_, def, _) = &item.kind
|
||||
&& let ItemKind::Enum(_, _, def) = &item.kind
|
||||
{
|
||||
let dataful: Vec<bool> = def.variants.iter().map(|v| !v.data.fields().is_empty()).collect();
|
||||
match dataful.iter().filter(|&&b| b).count() {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
|
|||
item.visit_with(&mut DetectNonGenericPointeeAttr { cx });
|
||||
|
||||
let (name_ident, generics) = if let Annotatable::Item(aitem) = item
|
||||
&& let ItemKind::Struct(ident, struct_data, g) = &aitem.kind
|
||||
&& let ItemKind::Struct(ident, g, struct_data) = &aitem.kind
|
||||
{
|
||||
if !matches!(
|
||||
struct_data,
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ impl<'a> TraitDef<'a> {
|
|||
);
|
||||
|
||||
let newitem = match &item.kind {
|
||||
ast::ItemKind::Struct(ident, struct_def, generics) => self.expand_struct_def(
|
||||
ast::ItemKind::Struct(ident, generics, struct_def) => self.expand_struct_def(
|
||||
cx,
|
||||
struct_def,
|
||||
*ident,
|
||||
|
|
@ -496,7 +496,7 @@ impl<'a> TraitDef<'a> {
|
|||
from_scratch,
|
||||
is_packed,
|
||||
),
|
||||
ast::ItemKind::Enum(ident, enum_def, generics) => {
|
||||
ast::ItemKind::Enum(ident, generics, enum_def) => {
|
||||
// We ignore `is_packed` here, because `repr(packed)`
|
||||
// enums cause an error later on.
|
||||
//
|
||||
|
|
@ -504,7 +504,7 @@ impl<'a> TraitDef<'a> {
|
|||
// downstream in blatantly illegal code, so it is fine.
|
||||
self.expand_enum_def(cx, enum_def, *ident, generics, from_scratch)
|
||||
}
|
||||
ast::ItemKind::Union(ident, struct_def, generics) => {
|
||||
ast::ItemKind::Union(ident, generics, struct_def) => {
|
||||
if self.supports_unions {
|
||||
self.expand_struct_def(
|
||||
cx,
|
||||
|
|
|
|||
|
|
@ -1424,7 +1424,7 @@ pub fn parse_macro_name_and_helper_attrs(
|
|||
/// See #73345 and #83125 for more details.
|
||||
/// FIXME(#73933): Remove this eventually.
|
||||
fn pretty_printing_compatibility_hack(item: &Item, psess: &ParseSess) {
|
||||
if let ast::ItemKind::Enum(ident, enum_def, _) = &item.kind
|
||||
if let ast::ItemKind::Enum(ident, _, enum_def) = &item.kind
|
||||
&& ident.name == sym::ProceduralMasqueradeDummyType
|
||||
&& let [variant] = &*enum_def.variants
|
||||
&& variant.ident.name == sym::Input
|
||||
|
|
|
|||
|
|
@ -1577,7 +1577,7 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
|
||||
let enum_definition = EnumDef { variants: variants.into_iter().flatten().collect() };
|
||||
Ok(ItemKind::Enum(ident, enum_definition, generics))
|
||||
Ok(ItemKind::Enum(ident, generics, enum_definition))
|
||||
}
|
||||
|
||||
fn parse_enum_variant(&mut self, span: Span) -> PResult<'a, Option<Variant>> {
|
||||
|
|
@ -1732,7 +1732,7 @@ impl<'a> Parser<'a> {
|
|||
return Err(self.dcx().create_err(err));
|
||||
};
|
||||
|
||||
Ok(ItemKind::Struct(ident, vdata, generics))
|
||||
Ok(ItemKind::Struct(ident, generics, vdata))
|
||||
}
|
||||
|
||||
/// Parses `union Foo { ... }`.
|
||||
|
|
@ -1764,7 +1764,7 @@ impl<'a> Parser<'a> {
|
|||
return Err(err);
|
||||
};
|
||||
|
||||
Ok(ItemKind::Union(ident, vdata, generics))
|
||||
Ok(ItemKind::Union(ident, generics, vdata))
|
||||
}
|
||||
|
||||
/// This function parses the fields of record structs:
|
||||
|
|
|
|||
|
|
@ -823,7 +823,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
}
|
||||
|
||||
// These items live in both the type and value namespaces.
|
||||
ItemKind::Struct(ident, ref vdata, _) => {
|
||||
ItemKind::Struct(ident, _, ref vdata) => {
|
||||
self.build_reduced_graph_for_struct_variant(
|
||||
vdata.fields(),
|
||||
ident,
|
||||
|
|
@ -874,7 +874,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ItemKind::Union(ident, ref vdata, _) => {
|
||||
ItemKind::Union(ident, _, ref vdata) => {
|
||||
self.build_reduced_graph_for_struct_variant(
|
||||
vdata.fields(),
|
||||
ident,
|
||||
|
|
|
|||
|
|
@ -162,8 +162,8 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
|||
self.with_parent(def_id, |this| {
|
||||
this.with_impl_trait(ImplTraitContext::Existential, |this| {
|
||||
match i.kind {
|
||||
ItemKind::Struct(_, ref struct_def, _)
|
||||
| ItemKind::Union(_, ref struct_def, _) => {
|
||||
ItemKind::Struct(_, _, ref struct_def)
|
||||
| ItemKind::Union(_, _, ref struct_def) => {
|
||||
// If this is a unit or tuple-like struct, register the constructor.
|
||||
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
|
||||
this.create_def(
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx>
|
|||
self.current_private_vis = prev_private_vis;
|
||||
}
|
||||
|
||||
ast::ItemKind::Enum(_, EnumDef { ref variants }, _) => {
|
||||
ast::ItemKind::Enum(_, _, EnumDef { ref variants }) => {
|
||||
self.set_bindings_effective_visibilities(def_id);
|
||||
for variant in variants {
|
||||
let variant_def_id = self.r.local_def_id(variant.id);
|
||||
|
|
@ -262,7 +262,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx>
|
|||
}
|
||||
}
|
||||
|
||||
ast::ItemKind::Struct(_, ref def, _) | ast::ItemKind::Union(_, ref def, _) => {
|
||||
ast::ItemKind::Struct(_, _, ref def) | ast::ItemKind::Union(_, _, ref def) => {
|
||||
for field in def.fields() {
|
||||
self.update_field(self.r.local_def_id(field.id), def_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2694,9 +2694,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
self.resolve_define_opaques(define_opaque);
|
||||
}
|
||||
|
||||
ItemKind::Enum(_, _, ref generics)
|
||||
| ItemKind::Struct(_, _, ref generics)
|
||||
| ItemKind::Union(_, _, ref generics) => {
|
||||
ItemKind::Enum(_, ref generics, _)
|
||||
| ItemKind::Struct(_, ref generics, _)
|
||||
| ItemKind::Union(_, ref generics, _) => {
|
||||
self.resolve_adt(item, generics);
|
||||
}
|
||||
|
||||
|
|
@ -5243,9 +5243,9 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> {
|
|||
ItemKind::TyAlias(box TyAlias { generics, .. })
|
||||
| ItemKind::Const(box ConstItem { generics, .. })
|
||||
| ItemKind::Fn(box Fn { generics, .. })
|
||||
| ItemKind::Enum(_, _, generics)
|
||||
| ItemKind::Struct(_, _, generics)
|
||||
| ItemKind::Union(_, _, generics)
|
||||
| ItemKind::Enum(_, generics, _)
|
||||
| ItemKind::Struct(_, generics, _)
|
||||
| ItemKind::Union(_, generics, _)
|
||||
| ItemKind::Impl(box Impl { generics, .. })
|
||||
| ItemKind::Trait(box Trait { generics, .. })
|
||||
| ItemKind::TraitAlias(_, generics, _) => {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ declare_lint_pass!(FieldScopedVisibilityModifiers => [FIELD_SCOPED_VISIBILITY_MO
|
|||
|
||||
impl EarlyLintPass for FieldScopedVisibilityModifiers {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
let ItemKind::Struct(_, ref st, _) = item.kind else {
|
||||
let ItemKind::Struct(_, _, ref st) = item.kind else {
|
||||
return;
|
||||
};
|
||||
for field in st.fields() {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ declare_lint_pass!(PartialPubFields => [PARTIAL_PUB_FIELDS]);
|
|||
|
||||
impl EarlyLintPass for PartialPubFields {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
let ItemKind::Struct(_, ref st, _) = item.kind else {
|
||||
let ItemKind::Struct(_, _, ref st) = item.kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -436,11 +436,11 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
|
|||
&& over(lb, rb, eq_generic_bound)
|
||||
&& both(lt.as_ref(), rt.as_ref(), |l, r| eq_ty(l, r))
|
||||
},
|
||||
(Enum(li, le, lg), Enum(ri, re, rg)) => {
|
||||
eq_id(*li, *ri) && over(&le.variants, &re.variants, eq_variant) && eq_generics(lg, rg)
|
||||
(Enum(li, lg, le), Enum(ri, rg, re)) => {
|
||||
eq_id(*li, *ri) && eq_generics(lg, rg) && over(&le.variants, &re.variants, eq_variant)
|
||||
},
|
||||
(Struct(li, lv, lg), Struct(ri, rv, rg)) | (Union(li, lv, lg), Union(ri, rv, rg)) => {
|
||||
eq_id(*li, *ri) && eq_variant_data(lv, rv) && eq_generics(lg, rg)
|
||||
(Struct(li, lg, lv), Struct(ri, rg, rv)) | (Union(li, lg, lv), Union(ri, rg, rv)) => {
|
||||
eq_id(*li, *ri) && eq_generics(lg, rg) && eq_variant_data(lv, rv)
|
||||
},
|
||||
(
|
||||
Trait(box ast::Trait {
|
||||
|
|
|
|||
|
|
@ -1110,10 +1110,10 @@ impl<'a> StructParts<'a> {
|
|||
|
||||
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
|
||||
let (prefix, def, ident, generics) = match item.kind {
|
||||
ast::ItemKind::Struct(ident, ref def, ref generics) => {
|
||||
ast::ItemKind::Struct(ident, ref generics, ref def) => {
|
||||
("struct ", def, ident, generics)
|
||||
}
|
||||
ast::ItemKind::Union(ident, ref def, ref generics) => ("union ", def, ident, generics),
|
||||
ast::ItemKind::Union(ident, ref generics, ref def) => ("union ", def, ident, generics),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
StructParts {
|
||||
|
|
|
|||
|
|
@ -521,7 +521,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
ast::ItemKind::Struct(..) | ast::ItemKind::Union(..) => {
|
||||
self.visit_struct(&StructParts::from_item(item));
|
||||
}
|
||||
ast::ItemKind::Enum(ident, ref def, ref generics) => {
|
||||
ast::ItemKind::Enum(ident, ref generics, ref def) => {
|
||||
self.format_missing_with_indent(source!(self, item.span).lo());
|
||||
self.visit_enum(ident, &item.vis, def, generics, item.span);
|
||||
self.last_pos = source!(self, item.span).hi();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue