Skip to content

Commit 1c74067

Browse files
committed
Add todo
1 parent 04e540b commit 1c74067

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

clippy_lints/src/panic_unimplemented.rs

Lines changed: 21 additions & 1 deletion
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,

tests/ui/panic_unimplemented.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

0 commit comments

Comments
 (0)