mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-09 15:13:57 +00:00
Look for trailing comma on array and preserve it inside macro call
This commit is contained in:
parent
65cb9b4649
commit
b33df45d04
12
src/expr.rs
12
src/expr.rs
@ -479,7 +479,17 @@ pub fn rewrite_array<T: Rewrite + Spanned + ToExpr>(
|
||||
separator: ",",
|
||||
trailing_separator: if trailing_comma {
|
||||
SeparatorTactic::Always
|
||||
} else if context.inside_macro || context.config.indent_style() == IndentStyle::Visual {
|
||||
} else if context.inside_macro && !exprs.is_empty() {
|
||||
let ends_with_bracket = context.snippet(span).ends_with(']');
|
||||
let bracket_offset = if ends_with_bracket { 1 } else { 0 };
|
||||
let snippet = context.snippet(mk_sp(span.lo(), span.hi() - BytePos(bracket_offset)));
|
||||
let last_char_index = snippet.rfind(|c: char| !c.is_whitespace())?;
|
||||
if &snippet[last_char_index..last_char_index + 1] == "," {
|
||||
SeparatorTactic::Always
|
||||
} else {
|
||||
SeparatorTactic::Never
|
||||
}
|
||||
} else if context.config.indent_style() == IndentStyle::Visual {
|
||||
SeparatorTactic::Never
|
||||
} else {
|
||||
SeparatorTactic::Vertical
|
||||
|
Loading…
Reference in New Issue
Block a user