diff options
| author | Heinz N. Gies <heinz@licenser.net> | 2019-10-12 13:26:14 +0200 |
|---|---|---|
| committer | Heinz N. Gies <heinz@licenser.net> | 2019-10-18 07:37:58 +0200 |
| commit | 98dc3aabeaf4102669d46912fb9def5f125a05ca (patch) | |
| tree | 815b0b264e84b177cf47f72b5fcca5a748759151 | |
| parent | 8d911fe98839bab2b81291986624419c18ace64a (diff) | |
| download | rust-98dc3aabeaf4102669d46912fb9def5f125a05ca.tar.gz rust-98dc3aabeaf4102669d46912fb9def5f125a05ca.zip | |
Add todo and tests
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | clippy_lints/src/lib.rs | 3 | ||||
| -rw-r--r-- | clippy_lints/src/panic_unimplemented.rs | 23 | ||||
| -rw-r--r-- | src/lintlist/mod.rs | 23 | ||||
| -rw-r--r-- | tests/ui/panic.rs | 12 | ||||
| -rw-r--r-- | tests/ui/panic.stderr | 10 | ||||
| -rw-r--r-- | tests/ui/panic_unimplemented.rs | 9 | ||||
| -rw-r--r-- | tests/ui/panic_unimplemented.stderr | 10 |
9 files changed, 89 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 42ab00001d9..5ce2eb4d5de 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 5023538c5ed..7913a3eefda 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 ccc5b74de30..9fca5a4b97a 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 bbb037ad8eb..6981ecff0d0 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -58,6 +58,22 @@ declare_clippy_lint! { } 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!`. /// /// **Why is this bad?** This macro can cause cause code to panics @@ -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 1575f0e3027..24e01f32780 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", @@ -1457,6 +1457,13 @@ pub const ALL_LINTS: [Lint; 326] = [ 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", desc: "missing parameters in `panic!` calls", @@ -1849,6 +1856,13 @@ pub const ALL_LINTS: [Lint; 326] = [ 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", desc: "functions with too many arguments", @@ -2052,6 +2066,13 @@ pub const ALL_LINTS: [Lint; 326] = [ 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", desc: "long integer literal without underscores", diff --git a/tests/ui/panic.rs b/tests/ui/panic.rs new file mode 100644 index 00000000000..dee3104774c --- /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 00000000000..cfef1a16e49 --- /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 fed82f13515..f3dae3bbde6 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 5f19b35fe6c..6d847e8df3e 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 |
