Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0d60f67

Browse files
committed
Use span_ends_with_comma to find a trailing comma in an attribute
1 parent e106940 commit 0d60f67

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/attr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,8 @@ impl Rewrite for ast::MetaItem {
217217
ast::MetaItemKind::List(ref list) => {
218218
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
219219

220-
let snippet = context.snippet(self.span);
221-
// 2 = )] (this might go wrong if there is whitespace between the brackets, but
222-
// it's close enough).
223-
let snippet = snippet[..snippet.len() - 2].trim();
224-
let trailing_comma = if snippet.ends_with(',') { "," } else { "" };
220+
let has_comma = ::expr::span_ends_with_comma(context, self.span);
221+
let trailing_comma = if has_comma { "," } else { "" };
225222
let combine = list.len() == 1 && match list[0].node {
226223
ast::NestedMetaItemKind::Literal(..) => false,
227224
ast::NestedMetaItemKind::MetaItem(ref inner_meta_item) => {

0 commit comments

Comments
 (0)