Skip to content

Commit 283cce3

Browse files
committed
Add todo
1 parent 252f04c commit 283cce3

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
@@ -58,6 +58,22 @@ declare_clippy_lint! {
5858
"`unimplemented!` should not be present in production code"
5959
}
6060

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

77-
declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE]);
93+
declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]);
7894

7995
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
8096
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
@@ -91,6 +107,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
91107
let span = get_outer_span(expr);
92108
span_lint(cx, UNIMPLEMENTED, span,
93109
"`unimplemented` should not be present in production code");
110+
} else if is_expn_of(expr.span, "todo").is_some() {
111+
let span = get_outer_span(expr);
112+
span_lint(cx, TODO, span,
113+
"`todo` should not be present in production code");
94114
} else if is_expn_of(expr.span, "unreachable").is_some() {
95115
let span = get_outer_span(expr);
96116
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)