Skip to content

Commit 98dc3aa

Browse files
committed
Add todo and tests
1 parent 8d911fe commit 98dc3aa

File tree

9 files changed

+89
-6
lines changed

9 files changed

+89
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ Released 2018-09-13
11381138
[`or_fun_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
11391139
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
11401140
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
1141+
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
11411142
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
11421143
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
11431144
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
@@ -1198,6 +1199,7 @@ Released 2018-09-13
11981199
[`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting
11991200
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
12001201
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
1202+
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
12011203
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
12021204
[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines
12031205
[`toplevel_ref_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg
@@ -1227,6 +1229,7 @@ Released 2018-09-13
12271229
[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
12281230
[`unneeded_field_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_field_pattern
12291231
[`unneeded_wildcard_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern
1232+
[`unreachable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreachable
12301233
[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
12311234
[`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name
12321235
[`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 326 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 329 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,10 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con
631631
misc::FLOAT_CMP_CONST,
632632
missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
633633
missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
634+
panic_unimplemented::PANIC,
635+
panic_unimplemented::TODO,
634636
panic_unimplemented::UNIMPLEMENTED,
637+
panic_unimplemented::UNREACHABLE,
635638
shadow::SHADOW_REUSE,
636639
shadow::SHADOW_SAME,
637640
strings::STRING_ADD,

clippy_lints/src/panic_unimplemented.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ declare_clippy_lint! {
5757
"`unimplemented!` should not be present in production code"
5858
}
5959

60+
declare_clippy_lint! {
61+
/// **What it does:** Checks for usage of `todo!`.
62+
///
63+
/// **Why is this bad?** This macro should not be present in production code
64+
///
65+
/// **Known problems:** None.
66+
///
67+
/// **Example:**
68+
/// ```no_run
69+
/// todo!();
70+
/// ```
71+
pub TODO,
72+
restriction,
73+
"`todo!` should not be present in production code"
74+
}
75+
6076
declare_clippy_lint! {
6177
/// **What it does:** Checks for usage of `unreachable!`.
6278
///
@@ -73,7 +89,7 @@ declare_clippy_lint! {
7389
"`unreachable!` should not be present in production code"
7490
}
7591

76-
declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE]);
92+
declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]);
7793

7894
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
7995
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
@@ -87,6 +103,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
87103
let span = get_outer_span(expr);
88104
span_lint(cx, UNIMPLEMENTED, span,
89105
"`unimplemented` should not be present in production code");
106+
} else if is_expn_of(expr.span, "todo").is_some() {
107+
let span = get_outer_span(expr);
108+
span_lint(cx, TODO, span,
109+
"`todo` should not be present in production code");
90110
} else if is_expn_of(expr.span, "unreachable").is_some() {
91111
let span = get_outer_span(expr);
92112
span_lint(cx, UNREACHABLE, span,
@@ -95,7 +115,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
95115
let span = get_outer_span(expr);
96116
span_lint(cx, PANIC, span,
97117
"`panic` should not be present in production code");
98-
//} else {
99118
match_panic(params, expr, cx);
100119
}
101120
}

src/lintlist/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 326] = [
9+
pub const ALL_LINTS: [Lint; 329] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -1456,6 +1456,13 @@ pub const ALL_LINTS: [Lint; 326] = [
14561456
deprecation: None,
14571457
module: "overflow_check_conditional",
14581458
},
1459+
Lint {
1460+
name: "panic",
1461+
group: "restriction",
1462+
desc: "missing parameters in `panic!` calls",
1463+
deprecation: None,
1464+
module: "panic_unimplemented",
1465+
},
14591466
Lint {
14601467
name: "panic_params",
14611468
group: "style",
@@ -1848,6 +1855,13 @@ pub const ALL_LINTS: [Lint; 326] = [
18481855
deprecation: None,
18491856
module: "methods",
18501857
},
1858+
Lint {
1859+
name: "todo",
1860+
group: "restriction",
1861+
desc: "`todo!` should not be present in production code",
1862+
deprecation: None,
1863+
module: "panic_unimplemented",
1864+
},
18511865
Lint {
18521866
name: "too_many_arguments",
18531867
group: "complexity",
@@ -2051,6 +2065,13 @@ pub const ALL_LINTS: [Lint; 326] = [
20512065
deprecation: None,
20522066
module: "misc_early",
20532067
},
2068+
Lint {
2069+
name: "unreachable",
2070+
group: "restriction",
2071+
desc: "`unreachable!` should not be present in production code",
2072+
deprecation: None,
2073+
module: "panic_unimplemented",
2074+
},
20542075
Lint {
20552076
name: "unreadable_literal",
20562077
group: "style",

tests/ui/panic.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![warn(clippy::panic)]
2+
#![allow(clippy::assertions_on_constants)]
3+
4+
fn panic() {
5+
let a = 2;
6+
panic!();
7+
let b = a + 2;
8+
}
9+
10+
fn main() {
11+
panic();
12+
}

tests/ui/panic.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `panic` should not be present in production code
2+
--> $DIR/panic.rs:6:5
3+
|
4+
LL | panic!();
5+
| ^^^^^^^^^
6+
|
7+
= note: `-D clippy::panic` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

tests/ui/panic_unimplemented.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable)]
1+
#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable, clippy::todo)]
22
#![allow(clippy::assertions_on_constants)]
33
fn missing() {
44
if true {
@@ -62,6 +62,12 @@ fn unreachable() {
6262
let b = a + 2;
6363
}
6464

65+
fn todo() {
66+
let a = 2;
67+
todo!();
68+
let b = a + 2;
69+
}
70+
6571
fn main() {
6672
missing();
6773
ok_single();
@@ -72,4 +78,5 @@ fn main() {
7278
ok_escaped();
7379
unimplemented();
7480
unreachable();
81+
todo();
7582
}

tests/ui/panic_unimplemented.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,13 @@ LL | unreachable!();
4040
|
4141
= note: `-D clippy::unreachable` implied by `-D warnings`
4242

43-
error: aborting due to 6 previous errors
43+
error: `todo` should not be present in production code
44+
--> $DIR/panic_unimplemented.rs:67:5
45+
|
46+
LL | todo!();
47+
| ^^^^^^^^
48+
|
49+
= note: `-D clippy::todo` implied by `-D warnings`
50+
51+
error: aborting due to 7 previous errors
4452

0 commit comments

Comments
 (0)