Skip to content

Commit 40deece

Browse files
authored
Rollup merge of #102719 - Nilstrieb:tidy-alphabetical, r=jackh726
Enforce alphabetical sorting with tidy We have many places where things are supposed to be sorted alphabetically. For the smaller and more recent size assertions, this is mostly upheld, but in other more... alive places it's very messy. This introduces a new tidy directive to check that a section of code is sorted alphabetically and fixes all places where sorting has gone wrong.
2 parents dc9f6f3 + ce35609 commit 40deece

File tree

19 files changed

+234
-103
lines changed

19 files changed

+234
-103
lines changed

compiler/rustc_ast/src/ast.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ pub type ForeignItem = Item<ForeignItemKind>;
30393039
mod size_asserts {
30403040
use super::*;
30413041
use rustc_data_structures::static_assert_size;
3042-
// These are in alphabetical order, which is easy to maintain.
3042+
// tidy-alphabetical-start
30433043
static_assert_size!(AssocItem, 104);
30443044
static_assert_size!(AssocItemKind, 32);
30453045
static_assert_size!(Attribute, 32);
@@ -3060,11 +3060,12 @@ mod size_asserts {
30603060
static_assert_size!(Local, 72);
30613061
static_assert_size!(Param, 40);
30623062
static_assert_size!(Pat, 120);
3063-
static_assert_size!(PatKind, 96);
30643063
static_assert_size!(Path, 40);
30653064
static_assert_size!(PathSegment, 24);
3065+
static_assert_size!(PatKind, 96);
30663066
static_assert_size!(Stmt, 32);
30673067
static_assert_size!(StmtKind, 16);
30683068
static_assert_size!(Ty, 96);
30693069
static_assert_size!(TyKind, 72);
3070+
// tidy-alphabetical-end
30703071
}

compiler/rustc_ast/src/token.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,11 @@ where
889889
mod size_asserts {
890890
use super::*;
891891
use rustc_data_structures::static_assert_size;
892-
// These are in alphabetical order, which is easy to maintain.
892+
// tidy-alphabetical-start
893893
static_assert_size!(Lit, 12);
894894
static_assert_size!(LitKind, 2);
895895
static_assert_size!(Nonterminal, 16);
896896
static_assert_size!(Token, 24);
897897
static_assert_size!(TokenKind, 16);
898+
// tidy-alphabetical-end
898899
}

compiler/rustc_ast/src/tokenstream.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,11 @@ impl DelimSpan {
646646
mod size_asserts {
647647
use super::*;
648648
use rustc_data_structures::static_assert_size;
649-
// These are in alphabetical order, which is easy to maintain.
649+
// tidy-alphabetical-start
650650
static_assert_size!(AttrTokenStream, 8);
651651
static_assert_size!(AttrTokenTree, 32);
652652
static_assert_size!(LazyAttrTokenStream, 8);
653653
static_assert_size!(TokenStream, 8);
654654
static_assert_size!(TokenTree, 32);
655+
// tidy-alphabetical-end
655656
}

compiler/rustc_const_eval/src/interpret/operand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
788788
mod size_asserts {
789789
use super::*;
790790
use rustc_data_structures::static_assert_size;
791-
// These are in alphabetical order, which is easy to maintain.
791+
// tidy-alphabetical-start
792792
static_assert_size!(Immediate, 48);
793793
static_assert_size!(ImmTy<'_>, 64);
794794
static_assert_size!(Operand, 56);
795795
static_assert_size!(OpTy<'_>, 80);
796+
// tidy-alphabetical-end
796797
}

compiler/rustc_const_eval/src/interpret/place.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,11 @@ where
892892
mod size_asserts {
893893
use super::*;
894894
use rustc_data_structures::static_assert_size;
895-
// These are in alphabetical order, which is easy to maintain.
896-
static_assert_size!(MemPlaceMeta, 24);
895+
// tidy-alphabetical-start
897896
static_assert_size!(MemPlace, 40);
897+
static_assert_size!(MemPlaceMeta, 24);
898898
static_assert_size!(MPlaceTy<'_>, 64);
899899
static_assert_size!(Place, 40);
900900
static_assert_size!(PlaceTy<'_>, 64);
901+
// tidy-alphabetical-end
901902
}

compiler/rustc_error_messages/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3535

3636
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
3737
fluent_messages! {
38+
// tidy-alphabetical-start
3839
ast_lowering => "../locales/en-US/ast_lowering.ftl",
3940
ast_passes => "../locales/en-US/ast_passes.ftl",
4041
attr => "../locales/en-US/attr.ftl",
@@ -64,6 +65,7 @@ fluent_messages! {
6465
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
6566
trait_selection => "../locales/en-US/trait_selection.ftl",
6667
ty_utils => "../locales/en-US/ty_utils.ftl",
68+
// tidy-alphabetical-end
6769
}
6870

6971
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

compiler/rustc_hir/src/hir.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3514,7 +3514,7 @@ impl<'hir> Node<'hir> {
35143514
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
35153515
mod size_asserts {
35163516
use super::*;
3517-
// These are in alphabetical order, which is easy to maintain.
3517+
// tidy-alphabetical-start
35183518
static_assert_size!(Block<'_>, 48);
35193519
static_assert_size!(Body<'_>, 32);
35203520
static_assert_size!(Expr<'_>, 64);
@@ -3533,9 +3533,9 @@ mod size_asserts {
35333533
static_assert_size!(Local<'_>, 64);
35343534
static_assert_size!(Param<'_>, 32);
35353535
static_assert_size!(Pat<'_>, 72);
3536-
static_assert_size!(PatKind<'_>, 48);
35373536
static_assert_size!(Path<'_>, 40);
35383537
static_assert_size!(PathSegment<'_>, 48);
3538+
static_assert_size!(PatKind<'_>, 48);
35393539
static_assert_size!(QPath<'_>, 24);
35403540
static_assert_size!(Res, 12);
35413541
static_assert_size!(Stmt<'_>, 32);
@@ -3544,4 +3544,5 @@ mod size_asserts {
35443544
static_assert_size!(TraitItemKind<'_>, 48);
35453545
static_assert_size!(Ty<'_>, 48);
35463546
static_assert_size!(TyKind<'_>, 32);
3547+
// tidy-alphabetical-end
35473548
}

compiler/rustc_interface/src/tests.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ fn test_codegen_options_tracking_hash() {
540540
}
541541

542542
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
543-
// This list is in alphabetical order.
543+
// tidy-alphabetical-start
544544
untracked!(ar, String::from("abc"));
545545
untracked!(codegen_units, Some(42));
546546
untracked!(default_linker_libraries, true);
@@ -556,6 +556,7 @@ fn test_codegen_options_tracking_hash() {
556556
untracked!(rpath, true);
557557
untracked!(save_temps, true);
558558
untracked!(strip, Strip::Debuginfo);
559+
// tidy-alphabetical-end
559560

560561
macro_rules! tracked {
561562
($name: ident, $non_default_value: expr) => {
@@ -567,7 +568,7 @@ fn test_codegen_options_tracking_hash() {
567568
}
568569

569570
// Make sure that changing a [TRACKED] option changes the hash.
570-
// This list is in alphabetical order.
571+
// tidy-alphabetical-start
571572
tracked!(code_model, Some(CodeModel::Large));
572573
tracked!(control_flow_guard, CFGuard::Checks);
573574
tracked!(debug_assertions, Some(true));
@@ -577,8 +578,8 @@ fn test_codegen_options_tracking_hash() {
577578
tracked!(force_unwind_tables, Some(true));
578579
tracked!(inline_threshold, Some(0xf007ba11));
579580
tracked!(instrument_coverage, Some(InstrumentCoverage::All));
580-
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
581581
tracked!(link_dead_code, Some(true));
582+
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
582583
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
583584
tracked!(lto, LtoCli::Fat);
584585
tracked!(metadata, vec![String::from("A"), String::from("B")]);
@@ -599,6 +600,7 @@ fn test_codegen_options_tracking_hash() {
599600
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
600601
tracked!(target_cpu, Some(String::from("abc")));
601602
tracked!(target_feature, String::from("all the features, all of them"));
603+
// tidy-alphabetical-end
602604
}
603605

604606
#[test]
@@ -619,12 +621,13 @@ fn test_top_level_options_tracked_no_crate() {
619621
}
620622

621623
// Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
622-
// This list is in alphabetical order.
623-
tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
624+
// tidy-alphabetical-start
624625
tracked!(
625626
real_rust_source_base_dir,
626627
Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into())
627628
);
629+
tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
630+
// tidy-alphabetical-end
628631
}
629632

630633
#[test]
@@ -641,7 +644,7 @@ fn test_unstable_options_tracking_hash() {
641644
}
642645

643646
// Make sure that changing an [UNTRACKED] option leaves the hash unchanged.
644-
// This list is in alphabetical order.
647+
// tidy-alphabetical-start
645648
untracked!(assert_incr_state, Some(String::from("loaded")));
646649
untracked!(deduplicate_diagnostics, false);
647650
untracked!(dep_tasks, true);
@@ -678,12 +681,12 @@ fn test_unstable_options_tracking_hash() {
678681
untracked!(perf_stats, true);
679682
// `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
680683
untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
681-
untracked!(profile_closures, true);
682684
untracked!(print_llvm_passes, true);
683685
untracked!(print_mono_items, Some(String::from("abc")));
684686
untracked!(print_type_sizes, true);
685687
untracked!(proc_macro_backtrace, true);
686688
untracked!(proc_macro_execution_strategy, ProcMacroExecutionStrategy::CrossThread);
689+
untracked!(profile_closures, true);
687690
untracked!(query_dep_graph, true);
688691
untracked!(save_analysis, true);
689692
untracked!(self_profile, SwitchWithOptPath::Enabled(None));
@@ -701,6 +704,7 @@ fn test_unstable_options_tracking_hash() {
701704
untracked!(unstable_options, true);
702705
untracked!(validate_mir, true);
703706
untracked!(verbose, true);
707+
// tidy-alphabetical-end
704708

705709
macro_rules! tracked {
706710
($name: ident, $non_default_value: expr) => {
@@ -712,7 +716,7 @@ fn test_unstable_options_tracking_hash() {
712716
}
713717

714718
// Make sure that changing a [TRACKED] option changes the hash.
715-
// This list is in alphabetical order.
719+
// tidy-alphabetical-start
716720
tracked!(allow_features, Some(vec![String::from("lang_items")]));
717721
tracked!(always_encode_mir, true);
718722
tracked!(asm_comments, true);
@@ -733,10 +737,10 @@ fn test_unstable_options_tracking_hash() {
733737
tracked!(debug_macros, true);
734738
tracked!(dep_info_omit_d_target, true);
735739
tracked!(drop_tracking, true);
736-
tracked!(export_executable_symbols, true);
737740
tracked!(dual_proc_macros, true);
738741
tracked!(dwarf_version, Some(5));
739742
tracked!(emit_thin_lto, false);
743+
tracked!(export_executable_symbols, true);
740744
tracked!(fewer_names, Some(true));
741745
tracked!(force_unstable_if_unmarked, true);
742746
tracked!(fuel, Some(("abc".to_string(), 99)));
@@ -759,8 +763,8 @@ fn test_unstable_options_tracking_hash() {
759763
tracked!(mutable_noalias, Some(true));
760764
tracked!(no_generate_arange_section, true);
761765
tracked!(no_link, true);
762-
tracked!(no_unique_section_names, true);
763766
tracked!(no_profiler_runtime, true);
767+
tracked!(no_unique_section_names, true);
764768
tracked!(oom, OomStrategy::Panic);
765769
tracked!(osx_rpath_install_name, true);
766770
tracked!(packed_bundled_libs, true);
@@ -773,8 +777,8 @@ fn test_unstable_options_tracking_hash() {
773777
tracked!(print_fuel, Some("abc".to_string()));
774778
tracked!(profile, true);
775779
tracked!(profile_emit, Some(PathBuf::from("abc")));
776-
tracked!(profiler_runtime, "abc".to_string());
777780
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
781+
tracked!(profiler_runtime, "abc".to_string());
778782
tracked!(relax_elf_relocations, Some(true));
779783
tracked!(relro_level, Some(RelroLevel::Full));
780784
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
@@ -803,6 +807,7 @@ fn test_unstable_options_tracking_hash() {
803807
tracked!(verify_llvm_ir, true);
804808
tracked!(virtual_function_elimination, true);
805809
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
810+
// tidy-alphabetical-end
806811

807812
macro_rules! tracked_no_crate_hash {
808813
($name: ident, $non_default_value: expr) => {

compiler/rustc_middle/src/mir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2946,11 +2946,12 @@ impl Location {
29462946
mod size_asserts {
29472947
use super::*;
29482948
use rustc_data_structures::static_assert_size;
2949-
// These are in alphabetical order, which is easy to maintain.
2949+
// tidy-alphabetical-start
29502950
static_assert_size!(BasicBlockData<'_>, 144);
29512951
static_assert_size!(LocalDecl<'_>, 56);
29522952
static_assert_size!(Statement<'_>, 32);
29532953
static_assert_size!(StatementKind<'_>, 16);
29542954
static_assert_size!(Terminator<'_>, 112);
29552955
static_assert_size!(TerminatorKind<'_>, 96);
2956+
// tidy-alphabetical-end
29562957
}

compiler/rustc_middle/src/mir/syntax.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1245,10 +1245,11 @@ pub enum BinOp {
12451245
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
12461246
mod size_asserts {
12471247
use super::*;
1248-
// These are in alphabetical order, which is easy to maintain.
1248+
// tidy-alphabetical-start
12491249
static_assert_size!(AggregateKind<'_>, 40);
12501250
static_assert_size!(Operand<'_>, 24);
12511251
static_assert_size!(Place<'_>, 16);
12521252
static_assert_size!(PlaceElem<'_>, 24);
12531253
static_assert_size!(Rvalue<'_>, 40);
1254+
// tidy-alphabetical-end
12541255
}

compiler/rustc_middle/src/thir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,13 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
848848
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
849849
mod size_asserts {
850850
use super::*;
851-
// These are in alphabetical order, which is easy to maintain.
851+
// tidy-alphabetical-start
852852
static_assert_size!(Block, 56);
853853
static_assert_size!(Expr<'_>, 64);
854854
static_assert_size!(ExprKind<'_>, 40);
855855
static_assert_size!(Pat<'_>, 72);
856856
static_assert_size!(PatKind<'_>, 56);
857857
static_assert_size!(Stmt<'_>, 48);
858858
static_assert_size!(StmtKind<'_>, 40);
859+
// tidy-alphabetical-end
859860
}

compiler/rustc_middle/src/ty/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2668,8 +2668,9 @@ pub struct DestructuredConst<'tcx> {
26682668
mod size_asserts {
26692669
use super::*;
26702670
use rustc_data_structures::static_assert_size;
2671-
// These are in alphabetical order, which is easy to maintain.
2671+
// tidy-alphabetical-start
26722672
static_assert_size!(PredicateS<'_>, 48);
26732673
static_assert_size!(TyS<'_>, 40);
26742674
static_assert_size!(WithStableHash<TyS<'_>>, 56);
2675+
// tidy-alphabetical-end
26752676
}

compiler/rustc_parse/src/parser/attr_wrapper.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ fn make_token_stream(
459459
mod size_asserts {
460460
use super::*;
461461
use rustc_data_structures::static_assert_size;
462-
// These are in alphabetical order, which is easy to maintain.
462+
// tidy-alphabetical-start
463463
static_assert_size!(AttrWrapper, 16);
464464
static_assert_size!(LazyAttrTokenStreamImpl, 144);
465+
// tidy-alphabetical-end
465466
}

0 commit comments

Comments
 (0)