Skip to content

Commit 0774b20

Browse files
committed
Fix false-positive in panic_params
It might still have false positives, but it’s even less likely.
1 parent 7eef989 commit 0774b20

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/panic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ impl LateLintPass for PanicPass {
3737
match_path(path, &BEGIN_UNWIND),
3838
let ExprLit(ref lit) = params[0].node,
3939
let LitKind::Str(ref string, _) = lit.node,
40-
string.contains('{'),
40+
let Some(par) = string.find('{'),
41+
string[par..].contains('}'),
4142
let Some(sp) = cx.sess().codemap()
4243
.with_expn_info(expr.span.expn_id,
4344
|info| info.map(|i| i.call_site))

tests/compile-fail/panic.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@
44
#[deny(panic_params)]
55

66
fn missing() {
7-
panic!("{}"); //~ERROR: You probably are missing some parameter
7+
if true {
8+
panic!("{}"); //~ERROR: You probably are missing some parameter
9+
} else {
10+
panic!("{:?}"); //~ERROR: You probably are missing some parameter
11+
}
812
}
913

10-
fn ok_sigle() {
14+
fn ok_single() {
1115
panic!("foo bar");
1216
}
1317

1418
fn ok_multiple() {
1519
panic!("{}", "This is {ok}");
1620
}
1721

22+
fn ok_bracket() {
23+
// the match is just here because of #759, it serves no other purpose for the lint
24+
match 42 {
25+
1337 => panic!("{so is this"),
26+
666 => panic!("so is this}"),
27+
_ => panic!("}so is that{"),
28+
}
29+
}
30+
1831
fn main() {
1932
missing();
20-
ok_sigle();
33+
ok_single();
2134
ok_multiple();
35+
ok_bracket();
2236
}

0 commit comments

Comments
 (0)