3 use syntax::ast::LitKind;
4 use utils::{is_direct_expn_of, match_path, paths, span_lint};
6 /// **What it does:** This lint checks for missing parameters in `panic!`.
8 /// **Known problems:** Should you want to use curly brackets in `panic!` without any parameter,
9 /// this lint will warn.
13 /// panic!("This `panic!` is probably missing a parameter there: {}");
16 pub PANIC_PARAMS, Warn, "missing parameters in `panic!`"
19 #[allow(missing_copy_implementations)]
22 impl LintPass for Pass {
23 fn get_lints(&self) -> LintArray {
24 lint_array!(PANIC_PARAMS)
28 impl LateLintPass for Pass {
29 fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
31 let ExprBlock(ref block) = expr.node,
32 let Some(ref ex) = block.expr,
33 let ExprCall(ref fun, ref params) = ex.node,
35 let ExprPath(None, ref path) = fun.node,
36 match_path(path, &paths::BEGIN_PANIC),
37 let ExprLit(ref lit) = params[0].node,
38 is_direct_expn_of(cx, params[0].span, "panic").is_some(),
39 let LitKind::Str(ref string, _) = lit.node,
40 let Some(par) = string.find('{'),
41 string[par..].contains('}')
43 span_lint(cx, PANIC_PARAMS, params[0].span,
44 "you probably are missing some parameter in your format string");