fix: don't strip nonexistent comma in derive

This commit is contained in:
Caleb Cartwright 2020-12-11 12:19:30 -06:00 committed by Caleb Cartwright
parent 70ce18255f
commit 4cfb9ef8f4
3 changed files with 54 additions and 1 deletions

View File

@ -183,9 +183,11 @@ fn format_derive(
} else if let SeparatorTactic::Always = context.config.trailing_comma() {
// Retain the trailing comma.
result.push_str(&item_str);
} else {
} else if item_str.ends_with(",") {
// Remove the trailing comma.
result.push_str(&item_str[..item_str.len() - 1]);
} else {
result.push_str(&item_str);
}
result.push_str(")]");

View 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 {}

View 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 {}