Skip to content

Commit 53ca259

Browse files
committed
Auto merge of rust-lang#105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`. Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time. r? `@petrochenkov`
2 parents 2119f7d + c91dd22 commit 53ca259

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/attr.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ impl Rewrite for ast::NestedMetaItem {
260260
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
261261
match self {
262262
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
263-
ast::NestedMetaItem::Lit(ref l) => rewrite_literal(context, l.token_lit, l.span, shape),
263+
ast::NestedMetaItem::Lit(ref l) => {
264+
rewrite_literal(context, l.as_token_lit(), l.span, shape)
265+
}
264266
}
265267
}
266268
}
@@ -308,18 +310,18 @@ impl Rewrite for ast::MetaItem {
308310
}),
309311
)?
310312
}
311-
ast::MetaItemKind::NameValue(ref literal) => {
313+
ast::MetaItemKind::NameValue(ref lit) => {
312314
let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
313315
// 3 = ` = `
314316
let lit_shape = shape.shrink_left(path.len() + 3)?;
315-
// `rewrite_literal` returns `None` when `literal` exceeds max
317+
// `rewrite_literal` returns `None` when `lit` exceeds max
316318
// width. Since a literal is basically unformattable unless it
317319
// is a string literal (and only if `format_strings` is set),
318320
// we might be better off ignoring the fact that the attribute
319321
// is longer than the max width and continue on formatting.
320322
// See #2479 for example.
321-
let value = rewrite_literal(context, literal.token_lit, literal.span, lit_shape)
322-
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
323+
let value = rewrite_literal(context, lit.as_token_lit(), lit.span, lit_shape)
324+
.unwrap_or_else(|| context.snippet(lit.span).to_owned());
323325
format!("{} = {}", path, value)
324326
}
325327
})

0 commit comments

Comments
 (0)