Skip to content

Commit 5092b63

Browse files
fix: don't strip nonexistent comma in derive
1 parent 70ce182 commit 5092b63

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/attr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,11 @@ fn format_derive(
183183
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
184184
// Retain the trailing comma.
185185
result.push_str(&item_str);
186-
} else {
186+
} else if item_str.ends_with(",") {
187187
// Remove the trailing comma.
188188
result.push_str(&item_str[..item_str.len() - 1]);
189+
} else {
190+
result.push_str(&item_str);
189191
}
190192
result.push_str(")]");
191193

tests/source/issue_4584.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// rustfmt-indent_style: Visual
2+
3+
#[derive(Debug,)]
4+
pub enum Case {
5+
Upper,
6+
Lower
7+
}
8+
9+
#[derive(Debug, Clone, PartialEq, Eq,)]
10+
pub enum Case {
11+
Upper,
12+
Lower
13+
}
14+
15+
// NB - This formatting looks potentially off the desired state, but is
16+
// consistent with current behavior. Included here to provide a line wrapped
17+
// derive case with the changes applied to resolve issue #4584
18+
#[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Mul,)]
19+
struct Foo {}

tests/target/issue_4584.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// rustfmt-indent_style: Visual
2+
3+
#[derive(Debug)]
4+
pub enum Case {
5+
Upper,
6+
Lower,
7+
}
8+
9+
#[derive(Debug, Clone, PartialEq, Eq)]
10+
pub enum Case {
11+
Upper,
12+
Lower,
13+
}
14+
15+
// NB - This formatting looks potentially off the desired state, but is
16+
// consistent with current behavior. Included here to provide a line wrapped
17+
// derive case with the changes applied to resolve issue #4584
18+
#[derive(Add,
19+
Sub,
20+
Mul,
21+
Div,
22+
Clone,
23+
Copy,
24+
Eq,
25+
PartialEq,
26+
Ord,
27+
PartialOrd,
28+
Debug,
29+
Hash,
30+
Serialize,
31+
Mul)]
32+
struct Foo {}

0 commit comments

Comments
 (0)