1
Fork 0

Factor out a repeated expression in lower_attr_args.

This commit is contained in:
Nicholas Nethercote 2022-11-24 13:47:57 +11:00
parent 8cfc8153da
commit aa10aad1ac

View file

@ -948,15 +948,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
// In valid code the value always ends up as a single literal. Otherwise, a dummy
// literal suffices because the error is handled elsewhere.
let lit = if let ExprKind::Lit(token_lit) = expr.kind {
match Lit::from_token_lit(token_lit, expr.span) {
Ok(lit) => lit,
Err(_err) => Lit {
token_lit: token::Lit::new(token::LitKind::Err, kw::Empty, None),
kind: LitKind::Err,
span: DUMMY_SP,
},
}
let lit = if let ExprKind::Lit(token_lit) = expr.kind
&& let Ok(lit) = Lit::from_token_lit(token_lit, expr.span)
{
lit
} else {
Lit {
token_lit: token::Lit::new(token::LitKind::Err, kw::Empty, None),