From aa10aad1ac5058e8278d8871c1cb4473134d3d54 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 24 Nov 2022 13:47:57 +1100 Subject: [PATCH] Factor out a repeated expression in `lower_attr_args`. --- compiler/rustc_ast_lowering/src/lib.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a123a58a8fb..530cf7d9787 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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),