Skip to content

Commit 4531921

Browse files
authored
Merge pull request #2454 from radix/issue-2446
Don't generate V: { f: u8, // comment }
2 parents bdf5629 + bd0facd commit 4531921

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

rustfmt-core/src/items.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,9 @@ pub fn format_struct_struct(
12031203
one_line_budget,
12041204
)?;
12051205

1206-
if !items_str.contains('\n') && !result.contains('\n') && items_str.len() <= one_line_budget {
1206+
if !items_str.contains('\n') && !result.contains('\n') && items_str.len() <= one_line_budget
1207+
&& !last_line_contains_single_line_comment(&items_str)
1208+
{
12071209
Some(format!("{} {} }}", result, items_str))
12081210
} else {
12091211
Some(format!(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum Issue2446 {
2+
V {
3+
f: u8, // x
4+
},
5+
}
6+
7+
enum Issue2446TrailingCommentsOnly {
8+
V {
9+
f: u8, /* */
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enum Issue2446 {
2+
V {
3+
f: u8, // x
4+
},
5+
}
6+
7+
enum Issue2446TrailingCommentsOnly {
8+
V { f: u8 /* */ },
9+
}

0 commit comments

Comments
 (0)