From 2362177aaf99767bbe92b324e05374cbdfab24da Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Mon, 21 Aug 2017 23:23:54 +0200 Subject: [PATCH] fix #768 by checking for message macro expansion --- clippy_lints/src/panic.rs | 3 ++- tests/ui/panic.rs | 8 ++++++++ tests/ui/panic.stderr | 10 +--------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/panic.rs b/clippy_lints/src/panic.rs index e9e529cfdb4..70ee7de7b4d 100644 --- a/clippy_lints/src/panic.rs +++ b/clippy_lints/src/panic.rs @@ -45,7 +45,8 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { is_direct_expn_of(expr.span, "panic").is_some(), let LitKind::Str(ref string, _) = lit.node, let Some(par) = string.as_str().find('{'), - string.as_str()[par..].contains('}') + string.as_str()[par..].contains('}'), + params[0].span.source_callee().is_none() ], { span_lint(cx, PANIC_PARAMS, params[0].span, "you probably are missing some parameter in your format string"); diff --git a/tests/ui/panic.rs b/tests/ui/panic.rs index d1a099c1e66..03d3c3dc2d9 100644 --- a/tests/ui/panic.rs +++ b/tests/ui/panic.rs @@ -34,10 +34,18 @@ fn ok_bracket() { } } +const ONE : u32= 1; + +fn ok_nomsg() { + assert!({ 1 == ONE }); + assert!(if 1 == ONE { ONE == 1 } else { false }); +} + fn main() { missing(); ok_single(); ok_multiple(); ok_bracket(); ok_inner(); + ok_nomsg(); } diff --git a/tests/ui/panic.stderr b/tests/ui/panic.stderr index a7284124b29..25113ed80b6 100644 --- a/tests/ui/panic.stderr +++ b/tests/ui/panic.stderr @@ -18,13 +18,5 @@ error: you probably are missing some parameter in your format string 12 | assert!(true, "here be missing values: {}"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: you probably are missing some parameter in your format string - --> $DIR/panic.rs:22:5 - | -22 | assert!("foo bar".contains(&format!("foo {}", "bar"))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in a macro outside of the current crate - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors