Fix #518
This commit is contained in:
parent
4958878ad2
commit
592ca26e90
6 changed files with 72 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ use reexport::*;
|
|||
use syntax::codemap::Span;
|
||||
use syntax::attr::*;
|
||||
use syntax::ast::{Attribute, MetaList, MetaWord};
|
||||
use utils::{in_macro, match_path, span_lint};
|
||||
use utils::{in_macro, match_path, span_lint, BEGIN_UNWIND};
|
||||
|
||||
/// **What it does:** This lint warns on items annotated with `#[inline(always)]`, unless the annotated function is empty or simply panics.
|
||||
///
|
||||
|
|
@ -94,7 +94,7 @@ fn is_relevant_expr(expr: &Expr) -> bool {
|
|||
ExprRet(None) | ExprBreak(_) => false,
|
||||
ExprCall(ref path_expr, _) => {
|
||||
if let ExprPath(_, ref path) = path_expr.node {
|
||||
!match_path(path, &["std", "rt", "begin_unwind"])
|
||||
!match_path(path, &BEGIN_UNWIND)
|
||||
} else { true }
|
||||
}
|
||||
_ => true
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ pub mod cyclomatic_complexity;
|
|||
pub mod escape;
|
||||
pub mod misc_early;
|
||||
pub mod array_indexing;
|
||||
pub mod panic;
|
||||
|
||||
mod reexport {
|
||||
pub use syntax::ast::{Name, NodeId};
|
||||
|
|
@ -123,6 +124,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||
reg.register_early_lint_pass(box misc_early::MiscEarly);
|
||||
reg.register_late_lint_pass(box misc::UsedUnderscoreBinding);
|
||||
reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
|
||||
reg.register_late_lint_pass(box panic::PanicPass);
|
||||
|
||||
reg.register_lint_group("clippy_pedantic", vec![
|
||||
methods::OPTION_UNWRAP_USED,
|
||||
|
|
@ -198,6 +200,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||
needless_update::NEEDLESS_UPDATE,
|
||||
no_effect::NO_EFFECT,
|
||||
open_options::NONSENSICAL_OPEN_OPTIONS,
|
||||
panic::PANIC_PARAMS,
|
||||
precedence::PRECEDENCE,
|
||||
ptr_arg::PTR_ARG,
|
||||
ranges::RANGE_STEP_BY_ZERO,
|
||||
|
|
|
|||
42
src/panic.rs
Normal file
42
src/panic.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use rustc::lint::*;
|
||||
use rustc_front::hir::*;
|
||||
use syntax::ast::Lit_::LitStr;
|
||||
|
||||
use utils::{span_lint, in_external_macro, match_path, BEGIN_UNWIND};
|
||||
|
||||
/// **What it does:** Warn about missing parameters in `panic!`.
|
||||
///
|
||||
/// **Known problems:** Should you want to use curly brackets in `panic!` without any parameter,
|
||||
/// this lint will warn.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```
|
||||
/// panic!("This panic! is probably missing a parameter there: {}");
|
||||
/// ```
|
||||
declare_lint!(pub PANIC_PARAMS, Warn, "missing parameters in `panic!`");
|
||||
|
||||
#[allow(missing_copy_implementations)]
|
||||
pub struct PanicPass;
|
||||
|
||||
impl LintPass for PanicPass {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(PANIC_PARAMS)
|
||||
}
|
||||
}
|
||||
|
||||
impl LateLintPass for PanicPass {
|
||||
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
|
||||
if_let_chain! {[
|
||||
in_external_macro(cx, expr.span),
|
||||
let ExprCall(ref fun, ref params) = expr.node,
|
||||
params.len() == 2,
|
||||
let ExprPath(None, ref path) = fun.node,
|
||||
match_path(path, &BEGIN_UNWIND),
|
||||
let ExprLit(ref lit) = params[0].node,
|
||||
let LitStr(ref string, _) = lit.node,
|
||||
string.contains('{')
|
||||
], {
|
||||
span_lint(cx, PANIC_PARAMS, expr.span, "You probably are missing some parameter in your `panic!` call");
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ pub const LL_PATH: [&'static str; 3] = ["collections", "linked_list", "Linke
|
|||
pub const OPEN_OPTIONS_PATH: [&'static str; 3] = ["std", "fs", "OpenOptions"];
|
||||
pub const MUTEX_PATH: [&'static str; 4] = ["std", "sync", "mutex", "Mutex"];
|
||||
pub const CLONE_PATH: [&'static str; 2] = ["Clone", "clone"];
|
||||
pub const BEGIN_UNWIND:[&'static str; 3] = ["std", "rt", "begin_unwind"];
|
||||
|
||||
/// Produce a nested chain of if-lets and ifs from the patterns:
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue