Skip to content

Commit 459280c

Browse files
committed
Reorder fields in hir::ItemKind variants.
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match the textual order in the source code. The interesting part of the change is in `compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical refactoring.
1 parent 660aede commit 459280c

18 files changed

+21
-21
lines changed

clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
272272
return;
273273
}
274274
match &item.kind {
275-
ItemKind::Enum(_, enum_def, _generics) if self.enable_ordering_for_enum => {
275+
ItemKind::Enum(_, _generics, enum_def) if self.enable_ordering_for_enum => {
276276
let mut cur_v: Option<&Variant<'_>> = None;
277277
for variant in enum_def.variants {
278278
if variant.span.in_external_macro(cx.sess().source_map()) {
@@ -288,7 +288,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
288288
cur_v = Some(variant);
289289
}
290290
},
291-
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => {
291+
ItemKind::Struct(_, _generics, VariantData::Struct { fields, .. }) if self.enable_ordering_for_struct => {
292292
let mut cur_f: Option<&FieldDef<'_>> = None;
293293
for field in *fields {
294294
if field.span.in_external_macro(cx.sess().source_map()) {

clippy_lints/src/empty_with_brackets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM_VA
9292

9393
impl LateLintPass<'_> for EmptyWithBrackets {
9494
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
95-
if let ItemKind::Struct(ident, var_data, _) = &item.kind
95+
if let ItemKind::Struct(ident, _, var_data) = &item.kind
9696
&& !item.span.from_expansion()
9797
&& has_brackets(var_data)
9898
&& let span_after_ident = item.span.with_lo(ident.span.hi())

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
3838
if cx.tcx.data_layout.pointer_size.bits() != 64 {
3939
return;
4040
}
41-
if let ItemKind::Enum(_, def, _) = &item.kind {
41+
if let ItemKind::Enum(_, _, def) = &item.kind {
4242
for var in def.variants {
4343
if let Some(anon_const) = &var.disr_expr {
4444
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);

clippy_lints/src/excessive_bools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn check_fn_decl(cx: &LateContext<'_>, decl: &FnDecl<'_>, sp: Span, max: u64) {
127127

128128
impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
129129
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
130-
if let ItemKind::Struct(_, variant_data, _) = &item.kind
130+
if let ItemKind::Struct(_, _, variant_data) = &item.kind
131131
&& variant_data.fields().len() as u64 > self.max_struct_bools
132132
&& has_n_bools(
133133
variant_data.fields().iter().map(|field| field.ty),

clippy_lints/src/exhaustive_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7676
"exported enums should not be exhaustive",
7777
[].as_slice(),
7878
),
79-
ItemKind::Struct(_, v, ..) => (
79+
ItemKind::Struct(_, _, v) => (
8080
EXHAUSTIVE_STRUCTS,
8181
"exported structs should not be exhaustive",
8282
v.fields(),

clippy_lints/src/functions/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty
103103
.did()
104104
.as_local()
105105
&& let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(local_def_id)
106-
&& let hir::ItemKind::Enum(_, ref def, _) = item.kind
106+
&& let hir::ItemKind::Enum(_, _, ref def) = item.kind
107107
{
108108
let variants_size = AdtVariantInfo::new(cx, *adt, subst);
109109
if let Some((first_variant, variants)) = variants_size.split_first()

clippy_lints/src/item_name_repetitions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,10 @@ impl LateLintPass<'_> for ItemNameRepetitions {
535535

536536
if span_is_local(item.span) {
537537
match item.kind {
538-
ItemKind::Enum(_, def, _) => {
538+
ItemKind::Enum(_, _, def) => {
539539
self.check_variants(cx, item, &def);
540540
},
541-
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _) => {
541+
ItemKind::Struct(_, _, VariantData::Struct { fields, .. }) => {
542542
self.check_fields(cx, item, fields);
543543
},
544544
_ => (),

clippy_lints/src/large_const_arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl_lint_pass!(LargeConstArrays => [LARGE_CONST_ARRAYS]);
4848

4949
impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5050
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
51-
if let ItemKind::Const(ident, _, generics, _) = &item.kind
51+
if let ItemKind::Const(ident, generics, _, _) = &item.kind
5252
// Since static items may not have generics, skip generic const items.
5353
// FIXME(generic_const_items): I don't think checking `generics.hwcp` suffices as it
5454
// doesn't account for empty where-clauses that only consist of keyword `where` IINM.

clippy_lints/src/large_enum_variant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
7373

7474
impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
7575
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
76-
if let ItemKind::Enum(ident, ref def, _) = item.kind
76+
if let ItemKind::Enum(ident, _, ref def) = item.kind
7777
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
7878
&& let ty::Adt(adt, subst) = ty.kind()
7979
&& adt.variants().len() > 1

clippy_lints/src/manual_non_exhaustive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
8787
}
8888

8989
match item.kind {
90-
ItemKind::Enum(_, def, _) if def.variants.len() > 1 => {
90+
ItemKind::Enum(_, _, def) if def.variants.len() > 1 => {
9191
let iter = def.variants.iter().filter_map(|v| {
9292
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir_attrs(v.hir_id)))
9393
.then_some((v.def_id, v.span))
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
9898
self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
9999
}
100100
},
101-
ItemKind::Struct(_, variant_data, _) => {
101+
ItemKind::Struct(_, _, variant_data) => {
102102
let fields = variant_data.fields();
103103
let private_fields = fields
104104
.iter()

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
225225
&& let typeck_results = cx.tcx.typeck_body(*body_id)
226226
&& should_lint(cx, typeck_results, block)
227227
// we intentionally only lint structs, see lint description
228-
&& let ItemKind::Struct(_, data, _) = &self_item.kind
228+
&& let ItemKind::Struct(_, _, data) = &self_item.kind
229229
{
230230
check_struct(cx, typeck_results, block, self_ty, item, data);
231231
}

clippy_lints/src/non_std_lazy_statics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ struct LazyInfo {
187187
impl LazyInfo {
188188
fn from_item(cx: &LateContext<'_>, item: &Item<'_>) -> Option<Self> {
189189
// Check if item is a `once_cell:sync::Lazy` static.
190-
if let ItemKind::Static(_, ty, _, body_id) = item.kind
190+
if let ItemKind::Static(_, _, ty, body_id) = item.kind
191191
&& let Some(path_def_id) = path_def_id(cx, ty)
192192
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
193193
&& paths::ONCE_CELL_SYNC_LAZY.matches(cx, path_def_id)

clippy_lints/src/pub_underscore_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl PubUnderscoreFields {
5858
impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
5959
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
6060
// This lint only pertains to structs.
61-
let ItemKind::Struct(_, variant_data, _) = &item.kind else {
61+
let ItemKind::Struct(_, _, variant_data) = &item.kind else {
6262
return;
6363
};
6464

clippy_lints/src/trailing_empty_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
5757
}
5858

5959
fn is_struct_with_trailing_zero_sized_array<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
60-
if let ItemKind::Struct(_, data, _) = &item.kind
60+
if let ItemKind::Struct(_, _, data) = &item.kind
6161
&& let Some(last_field) = data.fields().last()
6262
&& let field_ty = cx.tcx.normalize_erasing_regions(
6363
cx.typing_env(),

clippy_lints/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
447447
let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
448448

449449
match item.kind {
450-
ItemKind::Static(_, ty, _, _) | ItemKind::Const(_, ty, _, _) => self.check_ty(
450+
ItemKind::Static(_, _, ty, _) | ItemKind::Const(_, _, ty, _) => self.check_ty(
451451
cx,
452452
ty,
453453
CheckTyContext {

clippy_lints/src/upper_case_acronyms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
134134
ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait(_, _, ident, ..) => {
135135
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
136136
},
137-
ItemKind::Enum(ident, ref enumdef, _) => {
137+
ItemKind::Enum(ident, _, ref enumdef) => {
138138
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
139139
// check enum variants separately because again we only want to lint on private enums and
140140
// the fn check_variant does not know about the vis of the enum of its variants

clippy_utils/src/check_proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
249249
ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")),
250250
ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
251251
ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")),
252-
ItemKind::Struct(_, VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")),
252+
ItemKind::Struct(_, _, VariantData::Struct { .. }) => (Pat::Str("struct"), Pat::Str("}")),
253253
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),
254254
ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")),
255255
ItemKind::Trait(_, Safety::Unsafe, ..)

clippy_utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(&
23622362
for id in tcx.hir_module_free_items(module) {
23632363
if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
23642364
&& let item = tcx.hir_item(id)
2365-
&& let ItemKind::Const(ident, ty, _generics, _body) = item.kind
2365+
&& let ItemKind::Const(ident, _generics, ty, _body) = item.kind
23662366
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
23672367
// We could also check for the type name `test::TestDescAndFn`
23682368
&& let Res::Def(DefKind::Struct, _) = path.res

0 commit comments

Comments
 (0)