fix: don't strip nonexistent comma in derive
This commit is contained in:
parent
70ce18255f
commit
4cfb9ef8f4
@ -183,9 +183,11 @@ fn format_derive(
|
|||||||
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
|
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
|
||||||
// Retain the trailing comma.
|
// Retain the trailing comma.
|
||||||
result.push_str(&item_str);
|
result.push_str(&item_str);
|
||||||
} else {
|
} else if item_str.ends_with(",") {
|
||||||
// Remove the trailing comma.
|
// Remove the trailing comma.
|
||||||
result.push_str(&item_str[..item_str.len() - 1]);
|
result.push_str(&item_str[..item_str.len() - 1]);
|
||||||
|
} else {
|
||||||
|
result.push_str(&item_str);
|
||||||
}
|
}
|
||||||
result.push_str(")]");
|
result.push_str(")]");
|
||||||
|
|
||||||
|
19
tests/source/issue_4584.rs
Normal file
19
tests/source/issue_4584.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// rustfmt-indent_style: Visual
|
||||||
|
|
||||||
|
#[derive(Debug,)]
|
||||||
|
pub enum Case {
|
||||||
|
Upper,
|
||||||
|
Lower
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq,)]
|
||||||
|
pub enum Case {
|
||||||
|
Upper,
|
||||||
|
Lower
|
||||||
|
}
|
||||||
|
|
||||||
|
// NB - This formatting looks potentially off the desired state, but is
|
||||||
|
// consistent with current behavior. Included here to provide a line wrapped
|
||||||
|
// derive case with the changes applied to resolve issue #4584
|
||||||
|
#[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Mul,)]
|
||||||
|
struct Foo {}
|
32
tests/target/issue_4584.rs
Normal file
32
tests/target/issue_4584.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// rustfmt-indent_style: Visual
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Case {
|
||||||
|
Upper,
|
||||||
|
Lower,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum Case {
|
||||||
|
Upper,
|
||||||
|
Lower,
|
||||||
|
}
|
||||||
|
|
||||||
|
// NB - This formatting looks potentially off the desired state, but is
|
||||||
|
// consistent with current behavior. Included here to provide a line wrapped
|
||||||
|
// derive case with the changes applied to resolve issue #4584
|
||||||
|
#[derive(Add,
|
||||||
|
Sub,
|
||||||
|
Mul,
|
||||||
|
Div,
|
||||||
|
Clone,
|
||||||
|
Copy,
|
||||||
|
Eq,
|
||||||
|
PartialEq,
|
||||||
|
Ord,
|
||||||
|
PartialOrd,
|
||||||
|
Debug,
|
||||||
|
Hash,
|
||||||
|
Serialize,
|
||||||
|
Mul)]
|
||||||
|
struct Foo {}
|
Loading…
x
Reference in New Issue
Block a user