]> git.lizzy.rs Git - rust.git/commitdiff
Add todo and tests
authorHeinz N. Gies <heinz@licenser.net>
Sat, 12 Oct 2019 11:26:14 +0000 (13:26 +0200)
committerHeinz N. Gies <heinz@licenser.net>
Fri, 18 Oct 2019 05:37:58 +0000 (07:37 +0200)
CHANGELOG.md
README.md
clippy_lints/src/lib.rs
clippy_lints/src/panic_unimplemented.rs
src/lintlist/mod.rs
tests/ui/panic.rs [new file with mode: 0644]
tests/ui/panic.stderr [new file with mode: 0644]
tests/ui/panic_unimplemented.rs
tests/ui/panic_unimplemented.stderr

index 42ab00001d9749f91cb3a732e25cd364378a4a87..5ce2eb4d5de20513a39795e4f8f5841aed7ee052 100644 (file)
@@ -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
index 5023538c5ed905e0f35f0221de17112779928f16..7913a3eefdabbe83a1e37acba1c5afbb52ed6282 100644 (file)
--- 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:
 
index ccc5b74de302465bf6d019a552917fda5e2484c0..9fca5a4b97a488023e7704de9bc76b36d42f8e19 100644 (file)
@@ -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,
index bbb037ad8ebc97471a4685e496cd2b842ff02a92..6981ecff0d012822d4a6d66081e5c70495c0b618 100644 (file)
     "`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 @@
     "`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 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     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 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     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);
                 }
             }
index 1575f0e302785048adc6e830a9675b3d96c2c528..24e01f327802d93dd6b059975a97826bb50e21ec 100644 (file)
@@ -6,7 +6,7 @@
 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",
         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",
         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",
         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 (file)
index 0000000..dee3104
--- /dev/null
@@ -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 (file)
index 0000000..cfef1a1
--- /dev/null
@@ -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
+
index fed82f13515eb0f65f8593e3d5b549410b98bd23..f3dae3bbde651aa367ce528080f734badee932f4 100644 (file)
@@ -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();
 }
index 5f19b35fe6cffbe5b6eb650210f738ceb9e90ffc..6d847e8df3eb1226e025c893bd5be0bdc7d83aeb 100644 (file)
@@ -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