]> git.lizzy.rs Git - rust.git/blob - src/panic.rs
Remove * dep
[rust.git] / src / panic.rs
1 use rustc::lint::*;
2 use rustc_front::hir::*;
3 use syntax::ast::Lit_::LitStr;
4
5 use utils::{span_lint, in_external_macro, match_path, BEGIN_UNWIND};
6
7 /// **What it does:** Warn about missing parameters in `panic!`.
8 ///
9 /// **Known problems:** Should you want to use curly brackets in `panic!` without any parameter,
10 /// this lint will warn.
11 ///
12 /// **Example:**
13 /// ```
14 /// panic!("This panic! is probably missing a parameter there: {}");
15 /// ```
16 declare_lint!(pub PANIC_PARAMS, Warn, "missing parameters in `panic!`");
17
18 #[allow(missing_copy_implementations)]
19 pub struct PanicPass;
20
21 impl LintPass for PanicPass {
22     fn get_lints(&self) -> LintArray {
23         lint_array!(PANIC_PARAMS)
24     }
25 }
26
27 impl LateLintPass for PanicPass {
28     fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
29         if_let_chain! {[
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,
34             params.len() == 2,
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,
39             string.contains('{'),
40             let Some(sp) = cx.sess().codemap()
41                              .with_expn_info(expr.span.expn_id,
42                                              |info| info.map(|i| i.call_site))
43         ], {
44
45             span_lint(cx, PANIC_PARAMS, sp,
46                       "You probably are missing some parameter in your `panic!` call");
47         }}
48     }
49 }