Skip to content

Commit e5bcb22

Browse files
committed
Reorganise config options and stabilise a few
1 parent f891d04 commit e5bcb22

File tree

1 file changed

+81
-58
lines changed

1 file changed

+81
-58
lines changed

src/config.rs

Lines changed: 81 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -501,76 +501,65 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
501501

502502

503503
create_config! {
504+
// Fundamental stuff
505+
max_width: usize, 100, true, "Maximum width of each line";
506+
hard_tabs: bool, false, true, "Use tab characters for indentation, spaces for alignment";
507+
tab_spaces: usize, 4, true, "Number of spaces per tab";
508+
newline_style: NewlineStyle, NewlineStyle::Unix, true, "Unix or Windows line endings";
504509
indent_style: IndentStyle, IndentStyle::Block, false, "How do we indent expressions or items.";
505-
unstable_features: bool, false, true,
506-
"Enables unstable features. Only available on nightly channel";
507-
verbose: bool, false, false, "Use verbose output";
508-
disable_all_formatting: bool, false, false, "Don't reformat anything";
509-
skip_children: bool, false, false, "Don't reformat out of line modules";
510-
file_lines: FileLines, FileLines::all(), false,
511-
"Lines to format; this is not supported in rustfmt.toml, and can only be specified \
512-
via the --file-lines option";
513-
max_width: usize, 100, false, "Maximum width of each line";
514-
error_on_line_overflow: bool, true, false, "Error if unable to get all lines within max_width";
515-
error_on_line_overflow_comments: bool, true, false,
516-
"Error if unable to get comments within max_width";
517-
tab_spaces: usize, 4, false, "Number of spaces per tab";
510+
511+
// strings and comments
512+
format_strings: bool, false, false, "Format string literals where necessary";
513+
wrap_comments: bool, false, true, "Break comments to fit on the line";
514+
comment_width: usize, 80, false,
515+
"Maximum length of comments. No effect unless wrap_comments = true";
516+
normalize_comments: bool, false, true, "Convert /* */ comments to // comments where possible";
517+
518+
// Width heuristics
518519
fn_call_width: usize, 60, false,
519520
"Maximum width of the args of a function call before falling back to vertical formatting";
520521
struct_lit_width: usize, 18, false,
521522
"Maximum width in the body of a struct lit before falling back to vertical formatting";
522523
struct_variant_width: usize, 35, false,
523524
"Maximum width in the body of a struct variant before falling back to vertical formatting";
524-
force_explicit_abi: bool, true, false, "Always print the abi for extern items";
525-
newline_style: NewlineStyle, NewlineStyle::Unix, false, "Unix or Windows line endings";
526-
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
527-
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
528-
"Brace style for control flow constructs";
529-
impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";
530-
trailing_comma: SeparatorTactic, SeparatorTactic::Vertical, false,
531-
"How to handle trailing commas for lists";
532-
trailing_semicolon: bool, true, false,
533-
"Add trailing semicolon after break, continue and return";
534-
fn_empty_single_line: bool, true, false, "Put empty-body functions on a single line";
535-
fn_single_line: bool, false, false, "Put single-expression functions on a single line";
536-
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
537525
array_width: usize, 60, false,
538526
"Maximum width of an array literal before falling back to vertical formatting";
539527
array_horizontal_layout_threshold: usize, 0, false,
540528
"How many elements array must have before rustfmt uses horizontal layout.";
541-
type_punctuation_density: TypeDensity, TypeDensity::Wide, false,
542-
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
529+
chain_width: usize, 60, false, "Maximum length of a chain to fit on a single line";
530+
single_line_if_else_max_width: usize, 50, false, "Maximum line length for single line if-else \
531+
expressions. A value of zero means always break \
532+
if-else expressions.";
533+
534+
// Single line expressions and items.
535+
struct_lit_single_line: bool, true, false,
536+
"Put small struct literals on a single line";
537+
impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";
538+
fn_empty_single_line: bool, true, false, "Put empty-body functions on a single line";
539+
fn_single_line: bool, false, false, "Put single-expression functions on a single line";
540+
541+
// Where clauses
543542
// TODO:
544543
// 1. Should we at least try to put the where clause on the same line as the rest of the
545544
// function decl?
546545
// 2. Currently options `Tall` and `Vertical` produce the same output.
547546
where_density: Density, Density::Vertical, false, "Density of a where clause";
548547
where_single_line: bool, false, false, "To force single line where layout";
549548
where_layout: ListTactic, ListTactic::Vertical, false, "Element layout inside a where clause";
550-
struct_lit_single_line: bool, true, false,
551-
"Put small struct literals on a single line";
552-
report_todo: ReportTactic, ReportTactic::Never, false,
553-
"Report all, none or unnumbered occurrences of TODO in source file comments";
554-
report_fixme: ReportTactic, ReportTactic::Never, false,
555-
"Report all, none or unnumbered occurrences of FIXME in source file comments";
556-
chain_width: usize, 60, false, "Maximum length of a chain to fit on a single line";
549+
550+
// Imports
557551
imports_indent: IndentStyle, IndentStyle::Visual, false, "Indent of imports";
558552
imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block";
553+
554+
// Ordering
559555
reorder_extern_crates: bool, true, false, "Reorder extern crate statements alphabetically";
560556
reorder_extern_crates_in_group: bool, true, false, "Reorder extern crate statements in group";
561557
reorder_imports: bool, false, false, "Reorder import statements alphabetically";
562558
reorder_imports_in_group: bool, false, false, "Reorder import statements in group";
563559
reorder_imported_names: bool, true, false,
564560
"Reorder lists of names in import statements alphabetically";
565-
single_line_if_else_max_width: usize, 50, false, "Maximum line length for single line if-else \
566-
expressions. A value of zero means always break \
567-
if-else expressions.";
568-
format_strings: bool, false, false, "Format string literals where necessary";
569-
hard_tabs: bool, false, false, "Use tab characters for indentation, spaces for alignment";
570-
wrap_comments: bool, false, false, "Break comments to fit on the line";
571-
comment_width: usize, 80, false,
572-
"Maximum length of comments. No effect unless wrap_comments = true";
573-
normalize_comments: bool, false, false, "Convert /* */ comments to // comments where possible";
561+
562+
// Match
574563
wrap_match_arms: bool, true, false, "Wrap the body of arms in blocks when it does not fit on \
575564
the same line with the pattern of arms";
576565
match_block_trailing_comma: bool, false, false,
@@ -579,19 +568,21 @@ create_config! {
579568
"Force match arm bodies to be in a new lines";
580569
indent_match_arms: bool, true, false, "Indent match arms instead of keeping them at the same \
581570
indentation level as the match keyword";
571+
multiline_match_arm_forces_block: bool, false, false,
572+
"Force multiline match arm bodies to be wrapped in a block";
573+
574+
// Spaces around punctuation
575+
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
576+
"Where to put a binary operator when a binary expression goes multiline.";
577+
type_punctuation_density: TypeDensity, TypeDensity::Wide, false,
578+
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
582579
space_before_colon: bool, false, false, "Leave a space before the colon";
583580
space_after_colon: bool, true, false, "Leave a space after the colon";
584581
spaces_around_ranges: bool, false, false, "Put spaces around the .. and ... range operators";
585582
spaces_within_parens_and_brackets: bool, false, false,
586583
"Put spaces within non-empty parentheses or brackets";
587-
use_try_shorthand: bool, false, false, "Replace uses of the try! macro by the ? shorthand";
588-
write_mode: WriteMode, WriteMode::Overwrite, false,
589-
"What Write Mode to use when none is supplied: \
590-
Replace, Overwrite, Display, Plain, Diff, Coverage";
591-
color: Color, Color::Auto, false,
592-
"What Color option to use when none is supplied: Always, Never, Auto";
593-
condense_wildcard_suffixes: bool, false, false, "Replace strings of _ wildcards by a single .. \
594-
in tuple patterns";
584+
585+
// Misc.
595586
combine_control_expr: bool, true, false, "Combine control expressions with function calls.";
596587
struct_field_align_threshold: usize, 0, false, "Align struct fields if their diffs fits within \
597588
threshold.";
@@ -601,13 +592,45 @@ create_config! {
601592
"Try to put attributes on the same line as fields and variants.";
602593
multiline_closure_forces_block: bool, false, false,
603594
"Force multiline closure bodies to be wrapped in a block";
604-
multiline_match_arm_forces_block: bool, false, false,
605-
"Force multiline match arm bodies to be wrapped in a block";
606-
merge_derives: bool, true, false, "Merge multiple `#[derive(...)]` into a single one";
607-
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
608-
"Where to put a binary operator when a binary expression goes multiline.";
595+
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
596+
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
597+
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
598+
"Brace style for control flow constructs";
599+
trailing_comma: SeparatorTactic, SeparatorTactic::Vertical, false,
600+
"How to handle trailing commas for lists";
601+
trailing_semicolon: bool, true, false,
602+
"Add trailing semicolon after break, continue and return";
603+
604+
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
605+
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
606+
use_try_shorthand: bool, false, false, "Replace uses of the try! macro by the ? shorthand";
607+
condense_wildcard_suffixes: bool, false, false, "Replace strings of _ wildcards by a single .. \
608+
in tuple patterns";
609+
force_explicit_abi: bool, true, true, "Always print the abi for extern items";
610+
611+
// Control options (changes the operation of rustfmt, rather than the formatting)
612+
write_mode: WriteMode, WriteMode::Overwrite, false,
613+
"What Write Mode to use when none is supplied: \
614+
Replace, Overwrite, Display, Plain, Diff, Coverage";
615+
color: Color, Color::Auto, false,
616+
"What Color option to use when none is supplied: Always, Never, Auto";
609617
required_version: String, env!("CARGO_PKG_VERSION").to_owned(), false,
610-
"Require a specific version of rustfmt."
618+
"Require a specific version of rustfmt.";
619+
unstable_features: bool, false, true,
620+
"Enables unstable features. Only available on nightly channel";
621+
verbose: bool, false, false, "Use verbose output";
622+
disable_all_formatting: bool, false, false, "Don't reformat anything";
623+
skip_children: bool, false, false, "Don't reformat out of line modules";
624+
file_lines: FileLines, FileLines::all(), false,
625+
"Lines to format; this is not supported in rustfmt.toml, and can only be specified \
626+
via the --file-lines option";
627+
error_on_line_overflow: bool, true, false, "Error if unable to get all lines within max_width";
628+
error_on_line_overflow_comments: bool, true, false,
629+
"Error if unable to get comments within max_width";
630+
report_todo: ReportTactic, ReportTactic::Never, false,
631+
"Report all, none or unnumbered occurrences of TODO in source file comments";
632+
report_fixme: ReportTactic, ReportTactic::Never, false,
633+
"Report all, none or unnumbered occurrences of FIXME in source file comments";
611634
}
612635

613636
#[cfg(test)]

0 commit comments

Comments
 (0)