diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ab00001..5ce2eb4d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1138,6 +1138,7 @@ Released 2018-09-13 [`or_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call [`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing [`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional +[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic [`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params [`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap [`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl @@ -1198,6 +1199,7 @@ Released 2018-09-13 [`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting [`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment [`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr +[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo [`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments [`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines [`toplevel_ref_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg @@ -1227,6 +1229,7 @@ Released 2018-09-13 [`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap [`unneeded_field_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_field_pattern [`unneeded_wildcard_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern +[`unreachable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreachable [`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal [`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name [`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization diff --git a/README.md b/README.md index 5023538c5..7913a3eef 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 326 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 329 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index ccc5b74de..9fca5a4b9 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -631,7 +631,10 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con misc::FLOAT_CMP_CONST, missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS, missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS, + panic_unimplemented::PANIC, + panic_unimplemented::TODO, panic_unimplemented::UNIMPLEMENTED, + panic_unimplemented::UNREACHABLE, shadow::SHADOW_REUSE, shadow::SHADOW_SAME, strings::STRING_ADD, diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index bbb037ad8..6981ecff0 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -57,6 +57,22 @@ declare_clippy_lint! { "`unimplemented!` should not be present in production code" } +declare_clippy_lint! { + /// **What it does:** Checks for usage of `todo!`. + /// + /// **Why is this bad?** This macro should not be present in production code + /// + /// **Known problems:** None. + /// + /// **Example:** + /// ```no_run + /// todo!(); + /// ``` + pub TODO, + restriction, + "`todo!` should not be present in production code" +} + declare_clippy_lint! { /// **What it does:** Checks for usage of `unreachable!`. /// @@ -73,7 +89,7 @@ declare_clippy_lint! { "`unreachable!` should not be present in production code" } -declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE]); +declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { @@ -87,6 +103,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { let span = get_outer_span(expr); span_lint(cx, UNIMPLEMENTED, span, "`unimplemented` should not be present in production code"); + } else if is_expn_of(expr.span, "todo").is_some() { + let span = get_outer_span(expr); + span_lint(cx, TODO, span, + "`todo` should not be present in production code"); } else if is_expn_of(expr.span, "unreachable").is_some() { let span = get_outer_span(expr); span_lint(cx, UNREACHABLE, span, @@ -95,7 +115,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented { let span = get_outer_span(expr); span_lint(cx, PANIC, span, "`panic` should not be present in production code"); - //} else { match_panic(params, expr, cx); } } diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 1575f0e30..24e01f327 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 326] = [ +pub const ALL_LINTS: [Lint; 329] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -1456,6 +1456,13 @@ pub const ALL_LINTS: [Lint; 326] = [ deprecation: None, module: "overflow_check_conditional", }, + Lint { + name: "panic", + group: "restriction", + desc: "missing parameters in `panic!` calls", + deprecation: None, + module: "panic_unimplemented", + }, Lint { name: "panic_params", group: "style", @@ -1848,6 +1855,13 @@ pub const ALL_LINTS: [Lint; 326] = [ deprecation: None, module: "methods", }, + Lint { + name: "todo", + group: "restriction", + desc: "`todo!` should not be present in production code", + deprecation: None, + module: "panic_unimplemented", + }, Lint { name: "too_many_arguments", group: "complexity", @@ -2051,6 +2065,13 @@ pub const ALL_LINTS: [Lint; 326] = [ deprecation: None, module: "misc_early", }, + Lint { + name: "unreachable", + group: "restriction", + desc: "`unreachable!` should not be present in production code", + deprecation: None, + module: "panic_unimplemented", + }, Lint { name: "unreadable_literal", group: "style", diff --git a/tests/ui/panic.rs b/tests/ui/panic.rs new file mode 100644 index 000000000..dee310477 --- /dev/null +++ b/tests/ui/panic.rs @@ -0,0 +1,12 @@ +#![warn(clippy::panic)] +#![allow(clippy::assertions_on_constants)] + +fn panic() { + let a = 2; + panic!(); + let b = a + 2; +} + +fn main() { + panic(); +} diff --git a/tests/ui/panic.stderr b/tests/ui/panic.stderr new file mode 100644 index 000000000..cfef1a16e --- /dev/null +++ b/tests/ui/panic.stderr @@ -0,0 +1,10 @@ +error: `panic` should not be present in production code + --> $DIR/panic.rs:6:5 + | +LL | panic!(); + | ^^^^^^^^^ + | + = note: `-D clippy::panic` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/tests/ui/panic_unimplemented.rs b/tests/ui/panic_unimplemented.rs index fed82f135..f3dae3bbd 100644 --- a/tests/ui/panic_unimplemented.rs +++ b/tests/ui/panic_unimplemented.rs @@ -1,4 +1,4 @@ -#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable)] +#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable, clippy::todo)] #![allow(clippy::assertions_on_constants)] fn missing() { if true { @@ -62,6 +62,12 @@ fn unreachable() { let b = a + 2; } +fn todo() { + let a = 2; + todo!(); + let b = a + 2; +} + fn main() { missing(); ok_single(); @@ -72,4 +78,5 @@ fn main() { ok_escaped(); unimplemented(); unreachable(); + todo(); } diff --git a/tests/ui/panic_unimplemented.stderr b/tests/ui/panic_unimplemented.stderr index 5f19b35fe..6d847e8df 100644 --- a/tests/ui/panic_unimplemented.stderr +++ b/tests/ui/panic_unimplemented.stderr @@ -40,5 +40,13 @@ LL | unreachable!(); | = note: `-D clippy::unreachable` implied by `-D warnings` -error: aborting due to 6 previous errors +error: `todo` should not be present in production code + --> $DIR/panic_unimplemented.rs:67:5 + | +LL | todo!(); + | ^^^^^^^^ + | + = note: `-D clippy::todo` implied by `-D warnings` + +error: aborting due to 7 previous errors