Skip to content

Commit 6649cb3

Browse files
authored
Merge pull request #1978 from rust-lang-nursery/fix-768
fix #768 by checking for message macro expansion
2 parents 66346b2 + 2362177 commit 6649cb3

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

clippy_lints/src/panic.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
4545
is_direct_expn_of(expr.span, "panic").is_some(),
4646
let LitKind::Str(ref string, _) = lit.node,
4747
let Some(par) = string.as_str().find('{'),
48-
string.as_str()[par..].contains('}')
48+
string.as_str()[par..].contains('}'),
49+
params[0].span.source_callee().is_none()
4950
], {
5051
span_lint(cx, PANIC_PARAMS, params[0].span,
5152
"you probably are missing some parameter in your format string");

tests/ui/panic.rs

+8
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ fn ok_bracket() {
3434
}
3535
}
3636

37+
const ONE : u32= 1;
38+
39+
fn ok_nomsg() {
40+
assert!({ 1 == ONE });
41+
assert!(if 1 == ONE { ONE == 1 } else { false });
42+
}
43+
3744
fn main() {
3845
missing();
3946
ok_single();
4047
ok_multiple();
4148
ok_bracket();
4249
ok_inner();
50+
ok_nomsg();
4351
}

tests/ui/panic.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,5 @@ error: you probably are missing some parameter in your format string
1818
12 | assert!(true, "here be missing values: {}");
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020

21-
error: you probably are missing some parameter in your format string
22-
--> $DIR/panic.rs:22:5
23-
|
24-
22 | assert!("foo bar".contains(&format!("foo {}", "bar")));
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
|
27-
= note: this error originates in a macro outside of the current crate
28-
29-
error: aborting due to 4 previous errors
21+
error: aborting due to 3 previous errors
3022

0 commit comments

Comments
 (0)