2 use rustc_front::hir::*;
3 use syntax::ast::Lit_::LitStr;
5 use utils::{span_lint, in_external_macro, match_path, BEGIN_UNWIND};
7 /// **What it does:** Warn about missing parameters in `panic!`.
9 /// **Known problems:** Should you want to use curly brackets in `panic!` without any parameter,
10 /// this lint will warn.
14 /// panic!("This panic! is probably missing a parameter there: {}");
16 declare_lint!(pub PANIC_PARAMS, Warn, "missing parameters in `panic!`");
18 #[allow(missing_copy_implementations)]
21 impl LintPass for PanicPass {
22 fn get_lints(&self) -> LintArray {
23 lint_array!(PANIC_PARAMS)
27 impl LateLintPass for PanicPass {
28 fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
30 in_external_macro(cx, expr.span),
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, &BEGIN_UNWIND),
37 let ExprLit(ref lit) = params[0].node,
38 let LitStr(ref string, _) = lit.node,
40 let Some(sp) = cx.sess().codemap()
41 .with_expn_info(expr.span.expn_id,
42 |info| info.map(|i| i.call_site))
45 span_lint(cx, PANIC_PARAMS, sp,
46 "You probably are missing some parameter in your `panic!` call");