From 0f193d1a62c128ae94e1f21d7c1212d7c9e95b7d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 19 Oct 2020 21:14:05 +0200 Subject: Small cleanups in assert!() and panic_fmt lint. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (From the PR feedback.) Co-authored-by: Esteban Küber --- compiler/rustc_builtin_macros/src/assert.rs | 60 ++++++++++++++--------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'compiler/rustc_builtin_macros/src/assert.rs') diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index bc3276538da..bb6d3f6a007 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -27,37 +27,35 @@ pub fn expand_assert<'cx>( // context to pick up whichever is currently in scope. let sp = cx.with_call_site_ctxt(sp); - let panic_call = { - if let Some(tokens) = custom_message { - // Pass the custom message to panic!(). - cx.expr( - sp, - ExprKind::MacCall(MacCall { - path: Path::from_ident(Ident::new(sym::panic, sp)), - args: P(MacArgs::Delimited( - DelimSpan::from_single(sp), - MacDelimiter::Parenthesis, - tokens, - )), - prior_type_ascription: None, - }), - ) - } else { - // Pass our own message directly to $crate::panicking::panic(), - // because it might contain `{` and `}` that should always be - // passed literally. - cx.expr_call_global( - sp, - cx.std_path(&[sym::panicking, sym::panic]), - vec![cx.expr_str( - DUMMY_SP, - Symbol::intern(&format!( - "assertion failed: {}", - pprust::expr_to_string(&cond_expr).escape_debug() - )), - )], - ) - } + let panic_call = if let Some(tokens) = custom_message { + // Pass the custom message to panic!(). + cx.expr( + sp, + ExprKind::MacCall(MacCall { + path: Path::from_ident(Ident::new(sym::panic, sp)), + args: P(MacArgs::Delimited( + DelimSpan::from_single(sp), + MacDelimiter::Parenthesis, + tokens, + )), + prior_type_ascription: None, + }), + ) + } else { + // Pass our own message directly to $crate::panicking::panic(), + // because it might contain `{` and `}` that should always be + // passed literally. + cx.expr_call_global( + sp, + cx.std_path(&[sym::panicking, sym::panic]), + vec![cx.expr_str( + DUMMY_SP, + Symbol::intern(&format!( + "assertion failed: {}", + pprust::expr_to_string(&cond_expr).escape_debug() + )), + )], + ) }; let if_expr = cx.expr_if(sp, cx.expr(sp, ExprKind::Unary(UnOp::Not, cond_expr)), panic_call, None); -- cgit 1.4.1-3-g733a5