pub mod ok_if_let;
pub mod open_options;
pub mod overflow_check_conditional;
-pub mod panic;
+pub mod panic_unimplemented;
pub mod partialeq_ne_impl;
pub mod precedence;
pub mod ptr;
reg.register_late_lint_pass(box escape::Pass{too_large_for_stack: conf.too_large_for_stack});
reg.register_early_lint_pass(box misc_early::MiscEarly);
reg.register_late_lint_pass(box array_indexing::ArrayIndexing);
- reg.register_late_lint_pass(box panic::Pass);
+ reg.register_late_lint_pass(box panic_unimplemented::Pass);
reg.register_late_lint_pass(box strings::StringLitAsBytes);
reg.register_late_lint_pass(box derive::Derive);
reg.register_late_lint_pass(box types::CharLitAsU8);
ok_if_let::IF_LET_SOME_RESULT,
open_options::NONSENSICAL_OPEN_OPTIONS,
overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
- panic::PANIC_PARAMS,
- panic::UNIMPLEMENTED,
+ panic_unimplemented::PANIC_PARAMS,
+ panic_unimplemented::UNIMPLEMENTED,
partialeq_ne_impl::PARTIALEQ_NE_IMPL,
precedence::PRECEDENCE,
ptr::CMP_NULL,
non_expressive_names::JUST_UNDERSCORES_AND_DIGITS,
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
ok_if_let::IF_LET_SOME_RESULT,
- panic::PANIC_PARAMS,
- panic::UNIMPLEMENTED,
+ panic_unimplemented::PANIC_PARAMS,
+ panic_unimplemented::UNIMPLEMENTED,
ptr::CMP_NULL,
ptr::PTR_ARG,
question_mark::QUESTION_MARK,
+++ /dev/null
-use rustc::hir::*;
-use rustc::lint::*;
-use syntax::ast::LitKind;
-use syntax::ptr::P;
-use utils::{is_direct_expn_of, is_expn_of, match_def_path, opt_def_id, paths, resolve_node, span_lint};
-
-/// **What it does:** Checks for missing parameters in `panic!`.
-///
-/// **Why is this bad?** Contrary to the `format!` family of macros, there are
-/// two forms of `panic!`: if there are no parameters given, the first argument
-/// is not a format string and used literally. So while `format!("{}")` will
-/// fail to compile, `panic!("{}")` will not.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// panic!("This `panic!` is probably missing a parameter there: {}");
-/// ```
-declare_clippy_lint! {
- pub PANIC_PARAMS,
- style,
- "missing parameters in `panic!` calls"
-}
-
-/// **What it does:** Checks for usage of `unimplemented!`.
-///
-/// **Why is this bad?** This macro should not be present in production code
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// unimplemented!();
-/// ```
-declare_clippy_lint! {
- pub UNIMPLEMENTED,
- style,
- "`unimplemented!` should not be present in production code"
-}
-
-#[allow(missing_copy_implementations)]
-pub struct Pass;
-
-impl LintPass for Pass {
- fn get_lints(&self) -> LintArray {
- lint_array!(PANIC_PARAMS, UNIMPLEMENTED)
- }
-}
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
- fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
- if_chain! {
- if let ExprBlock(ref block, _) = expr.node;
- if let Some(ref ex) = block.expr;
- if let ExprCall(ref fun, ref params) = ex.node;
- if let ExprPath(ref qpath) = fun.node;
- if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
- if match_def_path(cx.tcx, fun_def_id, &paths::BEGIN_PANIC);
- if params.len() == 2;
- then {
- if is_expn_of(expr.span, "unimplemented").is_some() {
- span_lint(cx, UNIMPLEMENTED, expr.span,
- "`unimplemented` should not be present in production code");
- } else {
- match_panic(params, expr, cx);
- }
- }
- }
- }
-}
-
-fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
- if_chain! {
- if let ExprLit(ref lit) = params[0].node;
- if is_direct_expn_of(expr.span, "panic").is_some();
- if let LitKind::Str(ref string, _) = lit.node;
- let string = string.as_str().replace("{{", "").replace("}}", "");
- if let Some(par) = string.find('{');
- if string[par..].contains('}');
- if params[0].span.source_callee().is_none();
- if params[0].span.lo() != params[0].span.hi();
- then {
- span_lint(cx, PANIC_PARAMS, params[0].span,
- "you probably are missing some parameter in your format string");
- }
- }
-}
--- /dev/null
+use rustc::hir::*;
+use rustc::lint::*;
+use syntax::ast::LitKind;
+use syntax::ptr::P;
+use utils::{is_direct_expn_of, is_expn_of, match_def_path, opt_def_id, paths, resolve_node, span_lint};
+
+/// **What it does:** Checks for missing parameters in `panic!`.
+///
+/// **Why is this bad?** Contrary to the `format!` family of macros, there are
+/// two forms of `panic!`: if there are no parameters given, the first argument
+/// is not a format string and used literally. So while `format!("{}")` will
+/// fail to compile, `panic!("{}")` will not.
+///
+/// **Known problems:** None.
+///
+/// **Example:**
+/// ```rust
+/// panic!("This `panic!` is probably missing a parameter there: {}");
+/// ```
+declare_clippy_lint! {
+ pub PANIC_PARAMS,
+ style,
+ "missing parameters in `panic!` calls"
+}
+
+/// **What it does:** Checks for usage of `unimplemented!`.
+///
+/// **Why is this bad?** This macro should not be present in production code
+///
+/// **Known problems:** None.
+///
+/// **Example:**
+/// ```rust
+/// unimplemented!();
+/// ```
+declare_clippy_lint! {
+ pub UNIMPLEMENTED,
+ style,
+ "`unimplemented!` should not be present in production code"
+}
+
+#[allow(missing_copy_implementations)]
+pub struct Pass;
+
+impl LintPass for Pass {
+ fn get_lints(&self) -> LintArray {
+ lint_array!(PANIC_PARAMS, UNIMPLEMENTED)
+ }
+}
+
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
+ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
+ if_chain! {
+ if let ExprBlock(ref block, _) = expr.node;
+ if let Some(ref ex) = block.expr;
+ if let ExprCall(ref fun, ref params) = ex.node;
+ if let ExprPath(ref qpath) = fun.node;
+ if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
+ if match_def_path(cx.tcx, fun_def_id, &paths::BEGIN_PANIC);
+ if params.len() == 2;
+ then {
+ if is_expn_of(expr.span, "unimplemented").is_some() {
+ span_lint(cx, UNIMPLEMENTED, expr.span,
+ "`unimplemented` should not be present in production code");
+ } else {
+ match_panic(params, expr, cx);
+ }
+ }
+ }
+ }
+}
+
+fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
+ if_chain! {
+ if let ExprLit(ref lit) = params[0].node;
+ if is_direct_expn_of(expr.span, "panic").is_some();
+ if let LitKind::Str(ref string, _) = lit.node;
+ let string = string.as_str().replace("{{", "").replace("}}", "");
+ if let Some(par) = string.find('{');
+ if string[par..].contains('}');
+ if params[0].span.source_callee().is_none();
+ if params[0].span.lo() != params[0].span.hi();
+ then {
+ span_lint(cx, PANIC_PARAMS, params[0].span,
+ "you probably are missing some parameter in your format string");
+ }
+ }
+}
+++ /dev/null
-
-
-
-#![warn(panic_params, unimplemented)]
-
-fn missing() {
- if true {
- panic!("{}");
- } else if false {
- panic!("{:?}");
- } else {
- assert!(true, "here be missing values: {}");
- }
-
- panic!("{{{this}}}");
-}
-
-fn ok_single() {
- panic!("foo bar");
-}
-
-fn ok_inner() {
- // Test for #768
- assert!("foo bar".contains(&format!("foo {}", "bar")));
-}
-
-fn ok_multiple() {
- panic!("{}", "This is {ok}");
-}
-
-fn ok_bracket() {
- match 42 {
- 1337 => panic!("{so is this"),
- 666 => panic!("so is this}"),
- _ => panic!("}so is that{"),
- }
-}
-
-const ONE : u32= 1;
-
-fn ok_nomsg() {
- assert!({ 1 == ONE });
- assert!(if 1 == ONE { ONE == 1 } else { false });
-}
-
-fn ok_escaped() {
- panic!("{{ why should this not be ok? }}");
- panic!(" or {{ that ?");
- panic!(" or }} this ?");
- panic!(" {or {{ that ?");
- panic!(" }or }} this ?");
- panic!("{{ test }");
- panic!("{case }}");
-}
-
-fn unimplemented() {
- unimplemented!();
-}
-
-fn main() {
- missing();
- ok_single();
- ok_multiple();
- ok_bracket();
- ok_inner();
- ok_nomsg();
- ok_escaped();
- unimplemented();
-}
+++ /dev/null
-error: you probably are missing some parameter in your format string
- --> $DIR/panic.rs:8:16
- |
-8 | panic!("{}");
- | ^^^^
- |
- = note: `-D panic-params` implied by `-D warnings`
-
-error: you probably are missing some parameter in your format string
- --> $DIR/panic.rs:10:16
- |
-10 | panic!("{:?}");
- | ^^^^^^
-
-error: you probably are missing some parameter in your format string
- --> $DIR/panic.rs:12:23
- |
-12 | assert!(true, "here be missing values: {}");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: you probably are missing some parameter in your format string
- --> $DIR/panic.rs:15:12
- |
-15 | panic!("{{{this}}}");
- | ^^^^^^^^^^^^
-
-error: `unimplemented` should not be present in production code
- --> $DIR/panic.rs:57:5
- |
-57 | unimplemented!();
- | ^^^^^^^^^^^^^^^^^
- |
- = note: `-D unimplemented` implied by `-D warnings`
- = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
-
-error: aborting due to 5 previous errors
-
--- /dev/null
+
+
+
+#![warn(panic_params, unimplemented)]
+
+fn missing() {
+ if true {
+ panic!("{}");
+ } else if false {
+ panic!("{:?}");
+ } else {
+ assert!(true, "here be missing values: {}");
+ }
+
+ panic!("{{{this}}}");
+}
+
+fn ok_single() {
+ panic!("foo bar");
+}
+
+fn ok_inner() {
+ // Test for #768
+ assert!("foo bar".contains(&format!("foo {}", "bar")));
+}
+
+fn ok_multiple() {
+ panic!("{}", "This is {ok}");
+}
+
+fn ok_bracket() {
+ match 42 {
+ 1337 => panic!("{so is this"),
+ 666 => panic!("so is this}"),
+ _ => panic!("}so is that{"),
+ }
+}
+
+const ONE : u32= 1;
+
+fn ok_nomsg() {
+ assert!({ 1 == ONE });
+ assert!(if 1 == ONE { ONE == 1 } else { false });
+}
+
+fn ok_escaped() {
+ panic!("{{ why should this not be ok? }}");
+ panic!(" or {{ that ?");
+ panic!(" or }} this ?");
+ panic!(" {or {{ that ?");
+ panic!(" }or }} this ?");
+ panic!("{{ test }");
+ panic!("{case }}");
+}
+
+fn unimplemented() {
+ unimplemented!();
+}
+
+fn main() {
+ missing();
+ ok_single();
+ ok_multiple();
+ ok_bracket();
+ ok_inner();
+ ok_nomsg();
+ ok_escaped();
+ unimplemented();
+}
--- /dev/null
+error: you probably are missing some parameter in your format string
+ --> $DIR/panic_unimplemented.rs:8:16
+ |
+8 | panic!("{}");
+ | ^^^^
+ |
+ = note: `-D panic-params` implied by `-D warnings`
+
+error: you probably are missing some parameter in your format string
+ --> $DIR/panic_unimplemented.rs:10:16
+ |
+10 | panic!("{:?}");
+ | ^^^^^^
+
+error: you probably are missing some parameter in your format string
+ --> $DIR/panic_unimplemented.rs:12:23
+ |
+12 | assert!(true, "here be missing values: {}");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: you probably are missing some parameter in your format string
+ --> $DIR/panic_unimplemented.rs:15:12
+ |
+15 | panic!("{{{this}}}");
+ | ^^^^^^^^^^^^
+
+error: `unimplemented` should not be present in production code
+ --> $DIR/panic_unimplemented.rs:57:5
+ |
+57 | unimplemented!();
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D unimplemented` implied by `-D warnings`
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+
+error: aborting due to 5 previous errors
+