Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7a4b5ec
feat!: fn_parameter_post_comment_alignment config option
Ripper53 May 27, 2026
5630a27
feat!: change fn_parameter_post_comment_alignment to post_comment_ali…
Ripper53 May 31, 2026
7965e53
chore: revert unnecessary variable assignment
Ripper53 May 31, 2026
1d60f38
chore!: more thorough tests
Ripper53 May 31, 2026
6a62662
chore!: remove unncessary pub
Ripper53 May 31, 2026
3fc6e29
chore!: remove unncessary lifetime
Ripper53 May 31, 2026
d063968
chore: replace comment period with comma
Ripper53 May 31, 2026
f92d794
feat!: removed align_comments field from ListFormatting
Ripper53 Jun 1, 2026
5887c12
chore: remove unnecessary imports
Ripper53 Jun 1, 2026
2ad3338
chore: move functionality into is_block_comment_multiline_or_normaliz…
Ripper53 Jun 1, 2026
0d45b67
chore: change operation and comment for readability
Ripper53 Jun 1, 2026
b14b493
chore: update Configurations.md default post_comment_alignment value
Ripper53 Jun 1, 2026
ba2076e
feat!: fn_parameter_post_comment_alignment config option
Ripper53 May 27, 2026
fbf6a0a
feat!: change fn_parameter_post_comment_alignment to post_comment_ali…
Ripper53 May 31, 2026
8213985
chore: revert unnecessary variable assignment
Ripper53 May 31, 2026
b148c1b
chore!: more thorough tests
Ripper53 May 31, 2026
772af55
chore!: remove unncessary pub
Ripper53 May 31, 2026
9c7a433
chore!: remove unncessary lifetime
Ripper53 May 31, 2026
1967a98
chore: replace comment period with comma
Ripper53 May 31, 2026
a691b21
feat!: removed align_comments field from ListFormatting
Ripper53 Jun 1, 2026
a6224d7
chore: remove unnecessary imports
Ripper53 Jun 1, 2026
bd36b12
chore: move functionality into is_block_comment_multiline_or_normaliz…
Ripper53 Jun 1, 2026
89f8f01
chore: change operation and comment for readability
Ripper53 Jun 1, 2026
c45165c
chore: update Configurations.md default post_comment_alignment value
Ripper53 Jun 1, 2026
fe2bd01
feat!: fix merge conflict
Ripper53 Jun 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,40 @@ fn lorem() -> usize {

See also: [`tab_spaces`](#tab_spaces).

## `post_comment_alignment`

Alignment of post comments

- **Default value**: `SingleSpace`
- **Possible values**: `SingleSpace`, `SameIndent`
- **Stable**: No

#### `SingleSpace`:

One space between the code and comment.

```rust
fn foo(
a: usize, // Cat
b: usize, // Dog
c: f32, // Bird
) {
}
```

#### `SameIndent` (default):

Each comment has the same indentation.

```rust
fn foo(
a: usize, // Cat
b: usize, // Dog
c: f32, // Bird
) {
}
```

## `hex_literal_case`

Control the case of the letters in hexadecimal literal values
Expand Down
2 changes: 1 addition & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn format_derive(
.tactic(tactic)
.trailing_separator(trailing_separator)
.ends_with_newline(false);
let item_str = write_list(&all_items, &fmt).ok()?;
let item_str = write_list(all_items, &fmt).ok()?;

debug!("item_str: '{}'", item_str);

Expand Down
2 changes: 1 addition & 1 deletion src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn rewrite_closure_fn_decl(
let fmt = ListFormatting::new(param_shape, context.config)
.tactic(tactic)
.preserve_newline(true);
let list_str = write_list(&item_vec, &fmt)?;
let list_str = write_list(item_vec, &fmt)?;
let mut prefix = format!("{binder}{const_}{immovable}{coro}{capture_str}|{list_str}|");

if !ret_str.is_empty() {
Expand Down
4 changes: 4 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ create_config! {
"Format the bodies of declarative macro definitions";
skip_macro_invocations: SkipMacroInvocations, false,
"Skip formatting the bodies of macros invoked with the following names.";
post_comment_alignment: PostCommentAlignmentConfig, false,
"Alignment of post comments";
hex_literal_case: HexLiteralCaseConfig, true, "Format hexadecimal integer literals";
float_literal_trailing_zero: FloatLiteralTrailingZeroConfig, false,
"Add or remove trailing zero in floating-point literals";
Expand Down Expand Up @@ -783,6 +785,7 @@ format_strings = false
format_macro_matchers = false
format_macro_bodies = true
skip_macro_invocations = []
post_comment_alignment = "SingleSpace"
hex_literal_case = "Preserve"
float_literal_trailing_zero = "Preserve"
empty_item_single_line = true
Expand Down Expand Up @@ -876,6 +879,7 @@ format_strings = false
format_macro_matchers = false
format_macro_bodies = true
skip_macro_invocations = []
post_comment_alignment = "SingleSpace"
hex_literal_case = "Preserve"
float_literal_trailing_zero = "Preserve"
empty_item_single_line = true
Expand Down
11 changes: 11 additions & 0 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ pub enum ImportGranularity {
One,
}

/// Controls how rustfmt should align post comments.
#[config_type]
pub enum PostCommentAlignment {
/// Insert one space between the code and comment.
SingleSpace,
/// List each comment with the same indentation from the previous.
SameIndent,
}

/// Controls how rustfmt should handle case in hexadecimal literals.
#[config_type]
pub enum HexLiteralCase {
Expand Down Expand Up @@ -653,6 +662,8 @@ config_option_with_style_edition_default!(
FormatMacroMatchers, bool, _ => false;
FormatMacroBodies, bool, _ => true;
SkipMacroInvocations, MacroSelectors, _ => MacroSelectors::default();
PostCommentAlignmentConfig, PostCommentAlignment, _ =>
PostCommentAlignment::SingleSpace;
HexLiteralCaseConfig, HexLiteralCase, _ => HexLiteralCase::Preserve;
FloatLiteralTrailingZeroConfig, FloatLiteralTrailingZero, _ =>
FloatLiteralTrailingZero::Preserve;
Expand Down
4 changes: 2 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ fn rewrite_struct_lit<'a>(
force_no_trailing_comma || has_base_or_rest || !context.use_block_indent(),
);

write_list(&item_vec, &fmt)?
write_list(item_vec, &fmt)?
};

let fields_str =
Expand Down Expand Up @@ -1965,7 +1965,7 @@ fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>(
let fmt = ListFormatting::new(nested_shape, context.config)
.tactic(tactic)
.ends_with_newline(false);
let list_str = write_list(&item_vec, &fmt)?;
let list_str = write_list(item_vec, &fmt)?;

Ok(format!("({list_str})"))
}
Expand Down
2 changes: 1 addition & 1 deletion src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ fn rewrite_nested_use_tree(
.preserve_newline(true)
.nested(has_nested_list);

let list_str = write_list(&list_items, &fmt)?;
let list_str = write_list(list_items, &fmt)?;

let result = if (list_str.contains('\n')
|| list_str.len() > remaining_width
Expand Down
12 changes: 6 additions & 6 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl<'a> FmtVisitor<'a> {
.trailing_separator(self.config.trailing_comma())
.preserve_newline(true);

let list = write_list(&items, &fmt).ok()?;
let list = write_list(items, &fmt).ok()?;
result.push_str(&list);
result.push_str(&original_offset.to_string_with_newline(self.config));
result.push('}');
Expand Down Expand Up @@ -2791,7 +2791,7 @@ struct WhereClauseOption {
suppress_comma: bool, // Force no trailing comma
snuggle: WhereClauseSpace,
allow_single_line: bool, // Try single line where-clause instead of vertical layout
veto_single_line: bool, // Disallow a single-line where-clause.
veto_single_line: bool, // Disallow a single-line where-clause.
}

impl WhereClauseOption {
Expand Down Expand Up @@ -2902,7 +2902,7 @@ fn rewrite_params(
.trailing_separator(trailing_separator)
.ends_with_newline(tactic.ends_with_newline(context.config.indent_style()))
.preserve_newline(true);
write_list(&param_items, &fmt)
write_list(param_items, &fmt)
}

fn compute_budgets_for_params(
Expand All @@ -2926,7 +2926,7 @@ fn compute_budgets_for_params(
let overhead = if ret_str_len == 0 { 2 } else { 3 };
let mut used_space = indent.width() + result.len() + ret_str_len + overhead;
match fn_brace_style {
FnBraceStyle::None => used_space += 1, // 1 = `;`
FnBraceStyle::None => used_space += 1, // 1 = `;`
FnBraceStyle::SameLine => used_space += 2, // 2 = `{}`
FnBraceStyle::NextLine => (),
}
Expand Down Expand Up @@ -3164,7 +3164,7 @@ fn rewrite_bounds_on_where_clause(
.tactic(shape_tactic)
.trailing_separator(comma_tactic)
.preserve_newline(preserve_newline);
write_list(&items.collect::<Vec<_>>(), &fmt)
write_list(items.collect::<Vec<_>>(), &fmt)
}

fn rewrite_where_clause(
Expand Down Expand Up @@ -3245,7 +3245,7 @@ fn rewrite_where_clause(
.trailing_separator(comma_tactic)
.ends_with_newline(tactic.ends_with_newline(context.config.indent_style()))
.preserve_newline(true);
let preds_str = write_list(&item_vec, &fmt)?;
let preds_str = write_list(item_vec, &fmt)?;

let end_length = if terminator == "{" {
// If the brace is on the next line we don't need to count it otherwise it needs two
Expand Down
Loading
Loading