Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ where
// Block style in non-vertical mode.
let block_mode = tactic == DefinitiveListTactic::Horizontal;
// Width restriction is only relevant in vertical mode.
let comment =
rewrite_comment(comment, block_mode, formatting.shape, formatting.config)?;
let comment_shape = formatting.shape.comment(formatting.config);
let comment = rewrite_comment(comment, block_mode, comment_shape, formatting.config)?;
Comment on lines -369 to +370

@ytmimi ytmimi Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense that we'd want to use a Shape based on the comment width here.

This next thought isn't blocking, and it might be a larger refactor, but since rewrite_comment already takes a shape and formatting.config, would it make more sense for us to calculate the comment_shape inside rewrite_comment so that we won't need to remember to compute the comment_shape at each call site? Let me know if you see any issues with that approach.

View changes since the review

result.push_str(&comment);

if !inner_item.is_empty() {
Expand Down
40 changes: 20 additions & 20 deletions tests/target/comments-in-lists/wrap-comments-not-normalized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub enum E2 {
}

pub enum E3 {
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
Variant1,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
Variant2,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
Expand All @@ -47,11 +47,11 @@ pub struct S2 {
}

pub struct S3 {
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
some_field: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
last_field: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
Expand All @@ -77,11 +77,11 @@ fn foo2(// Expand as needed, numbers should be ascending according to the stage
}

fn foo3(
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
a: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
b: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
Expand All @@ -107,11 +107,11 @@ fn main() {
];

let v3 = vec![
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
1,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
2,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
Expand All @@ -130,11 +130,11 @@ fn main() {
}

match a {
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
b => c,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
d => e,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
Expand Down
40 changes: 20 additions & 20 deletions tests/target/comments-in-lists/wrap-comments-true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub enum E2 {
}

pub enum E3 {
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
Variant1,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
Variant2,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
Expand All @@ -48,11 +48,11 @@ pub struct S2 {
}

pub struct S3 {
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
some_field: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
last_field: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
Expand All @@ -78,11 +78,11 @@ fn foo2(// Expand as needed, numbers should be ascending according to the stage
}

fn foo3(
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
a: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
b: usize,
// Expand as needed, numbers should be ascending according to the stage through the inclusion
// pipeline, or according to the descriptions
Expand All @@ -108,11 +108,11 @@ fn main() {
];

let v3 = vec![
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
1,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
2,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
Expand All @@ -131,11 +131,11 @@ fn main() {
}

match a {
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
b => c,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
// Expand as needed, numbers should be ascending according to the stage
// through the inclusion pipeline, or according to the descriptions
d => e,
// Expand as needed, numbers should be ascending according to the stage through the
// inclusion pipeline, or according to the descriptions
Expand Down
6 changes: 3 additions & 3 deletions tests/target/configs/struct_field_align_threshold/20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ fn main() {
};

A {
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
// hendrerit. Donec et mollis dolor.
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
// viverra nec consectetur ante hendrerit. Donec et mollis dolor.
first: item(),
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
// Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Expand Down
6 changes: 3 additions & 3 deletions tests/target/struct_lits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ fn main() {
};

A {
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.
// Donec et mollis dolor.
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
// viverra nec consectetur ante hendrerit. Donec et mollis dolor.
first: item(),
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
// Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Expand Down
6 changes: 3 additions & 3 deletions tests/target/struct_lits_multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ fn main() {
};

A {
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.
// Donec et mollis dolor.
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
// viverra nec consectetur ante hendrerit. Donec et mollis dolor.
first: item(),
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
// Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Expand Down
6 changes: 3 additions & 3 deletions tests/target/struct_lits_visual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ fn main() {
Baz { x: yxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
z: zzzzz /* test */ };

A { // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
// hendrerit. Donec et mollis dolor.
A { // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
// viverra nec consectetur ante hendrerit. Donec et mollis dolor.
first: item(),
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
// Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Expand Down
6 changes: 3 additions & 3 deletions tests/target/struct_lits_visual_multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ fn main() {
},
y: baz() };

A { // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
// hendrerit. Donec et mollis dolor.
A { // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
// viverra nec consectetur ante hendrerit. Donec et mollis dolor.
first: item(),
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
// Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Expand Down
6 changes: 3 additions & 3 deletions tests/target/struct_tuple_visual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ fn foo() {
Baz(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
zzzzz /* test */);

A(// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
// hendrerit. Donec et mollis dolor.
A(// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
// viverra nec consectetur ante hendrerit. Donec et mollis dolor.
item(),
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
// Nam tincidunt congue enim, ut porta lorem lacinia consectetur.
Expand Down
Loading