Honor "enum_trailing_comma" option. Fixes #556
This commit is contained in:
parent
3c60328df8
commit
2aa35f0f6d
@ -693,7 +693,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
let fmt = ListFormatting {
|
||||
tactic: DefinitiveListTactic::Vertical,
|
||||
separator: ",",
|
||||
trailing_separator: SeparatorTactic::Always,
|
||||
trailing_separator: SeparatorTactic::from_bool(self.config.enum_trailing_comma),
|
||||
indent: self.block_indent,
|
||||
width: budget,
|
||||
ends_with_newline: true,
|
||||
|
10
src/lists.rs
10
src/lists.rs
@ -46,6 +46,16 @@ pub enum SeparatorTactic {
|
||||
|
||||
impl_enum_decodable!(SeparatorTactic, Always, Never, Vertical);
|
||||
|
||||
impl SeparatorTactic {
|
||||
pub fn from_bool(b: bool) -> SeparatorTactic {
|
||||
if b {
|
||||
SeparatorTactic::Always
|
||||
} else {
|
||||
SeparatorTactic::Never
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ListFormatting<'a> {
|
||||
pub tactic: DefinitiveListTactic,
|
||||
pub separator: &'a str,
|
||||
|
41
tests/source/enum-no_trailing_comma.rs
Normal file
41
tests/source/enum-no_trailing_comma.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// rustfmt-enum_trailing_comma: false
|
||||
|
||||
enum X {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
|
||||
enum Y {
|
||||
A,
|
||||
B
|
||||
}
|
||||
|
||||
enum TupX {
|
||||
A(u32),
|
||||
B(i32, u16),
|
||||
}
|
||||
|
||||
enum TupY {
|
||||
A(u32),
|
||||
B(i32, u16)
|
||||
}
|
||||
|
||||
enum StructX {
|
||||
A {
|
||||
s: u16,
|
||||
},
|
||||
B {
|
||||
u: u32,
|
||||
i: i32,
|
||||
},
|
||||
}
|
||||
|
||||
enum StructY {
|
||||
A {
|
||||
s: u16,
|
||||
},
|
||||
B {
|
||||
u: u32,
|
||||
i: i32,
|
||||
}
|
||||
}
|
41
tests/target/enum-no_trailing_comma.rs
Normal file
41
tests/target/enum-no_trailing_comma.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// rustfmt-enum_trailing_comma: false
|
||||
|
||||
enum X {
|
||||
A,
|
||||
B
|
||||
}
|
||||
|
||||
enum Y {
|
||||
A,
|
||||
B
|
||||
}
|
||||
|
||||
enum TupX {
|
||||
A(u32),
|
||||
B(i32, u16)
|
||||
}
|
||||
|
||||
enum TupY {
|
||||
A(u32),
|
||||
B(i32, u16)
|
||||
}
|
||||
|
||||
enum StructX {
|
||||
A {
|
||||
s: u16,
|
||||
},
|
||||
B {
|
||||
u: u32,
|
||||
i: i32,
|
||||
}
|
||||
}
|
||||
|
||||
enum StructY {
|
||||
A {
|
||||
s: u16,
|
||||
},
|
||||
B {
|
||||
u: u32,
|
||||
i: i32,
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user