[`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
[`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
[`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
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:
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,
"`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!`.
///
"`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) {
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,
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);
}
}
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",
--- /dev/null
+#![warn(clippy::panic)]
+#![allow(clippy::assertions_on_constants)]
+
+fn panic() {
+ let a = 2;
+ panic!();
+ let b = a + 2;
+}
+
+fn main() {
+ panic();
+}
--- /dev/null
+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
+
-#![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 {
let b = a + 2;
}
+fn todo() {
+ let a = 2;
+ todo!();
+ let b = a + 2;
+}
+
fn main() {
missing();
ok_single();
ok_escaped();
unimplemented();
unreachable();
+ todo();
}
|
= 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