mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-22 20:53:21 +00:00
Add todo and tests
This commit is contained in:
parent
8d911fe988
commit
98dc3aabea
9 changed files with 89 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
12
tests/ui/panic.rs
Normal file
12
tests/ui/panic.rs
Normal file
|
@ -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();
|
||||
}
|
10
tests/ui/panic.stderr
Normal file
10
tests/ui/panic.stderr
Normal file
|
@ -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
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue