diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2020-10-19 21:14:05 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2020-10-19 21:14:05 +0200 |
| commit | 0f193d1a62c128ae94e1f21d7c1212d7c9e95b7d (patch) | |
| tree | 23763844bd8e1688ef0e5e4ed22275765ce70ce8 /compiler/rustc_builtin_macros/src/assert.rs | |
| parent | ff8df0bbe38d8b1216661c6544de4187e41eb45b (diff) | |
| download | rust-0f193d1a62c128ae94e1f21d7c1212d7c9e95b7d.tar.gz rust-0f193d1a62c128ae94e1f21d7c1212d7c9e95b7d.zip | |
Small cleanups in assert!() and panic_fmt lint.
(From the PR feedback.) Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
Diffstat (limited to 'compiler/rustc_builtin_macros/src/assert.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/assert.rs | 60 |
1 files changed, 29 insertions, 31 deletions
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); |
