Use span_ends_with_comma to find a trailing comma in an attribute

This commit is contained in:
Seiichi Uchida 2018-08-27 16:37:58 +09:00
parent e1069403ca
commit 0d60f6715d

View file

@ -217,11 +217,8 @@ impl Rewrite for ast::MetaItem {
ast::MetaItemKind::List(ref list) => { ast::MetaItemKind::List(ref list) => {
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?; let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
let snippet = context.snippet(self.span); let has_comma = ::expr::span_ends_with_comma(context, self.span);
// 2 = )] (this might go wrong if there is whitespace between the brackets, but let trailing_comma = if has_comma { "," } else { "" };
// it's close enough).
let snippet = snippet[..snippet.len() - 2].trim();
let trailing_comma = if snippet.ends_with(',') { "," } else { "" };
let combine = list.len() == 1 && match list[0].node { let combine = list.len() == 1 && match list[0].node {
ast::NestedMetaItemKind::Literal(..) => false, ast::NestedMetaItemKind::Literal(..) => false,
ast::NestedMetaItemKind::MetaItem(ref inner_meta_item) => { ast::NestedMetaItemKind::MetaItem(ref inner_meta_item) => {