Skip to content

Commit 54d49af

Browse files
committed
add more test cases for dbg_macro rule
1 parent 268ff85 commit 54d49af

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

clippy_lints/src/dbg_macro.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::utils::span_help_and_lint;
22
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
33
use rustc::{declare_tool_lint, lint_array};
4-
use rustc_errors::Applicability;
54
use syntax::ast;
65

76
/// **What it does:** Checks for usage of dbg!() macro.

tests/ui/dbg_macro.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#![warn(clippy::dbg_macro)]
22

3+
fn foo(n: u32) -> u32 {
4+
if let Some(n) = dbg!(n.checked_sub(4)) {
5+
n
6+
} else {
7+
n
8+
}
9+
}
10+
11+
fn factorial(n: u32) -> u32 {
12+
if dbg!(n <= 1) {
13+
dbg!(1)
14+
} else {
15+
dbg!(n * factorial(n - 1))
16+
}
17+
}
18+
319
fn main() {
420
dbg!(42);
21+
dbg!(dbg!(dbg!(42)));
22+
foo(3) + dbg!(factorial(4));
523
}

tests/ui/dbg_macro.stderr

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
11
error: `dbg!` macro is intended as a debugging tool
2-
--> $DIR/dbg_macro.rs:4:5
2+
--> $DIR/dbg_macro.rs:4:22
3+
|
4+
LL | if let Some(n) = dbg!(n.checked_sub(4)) {
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::dbg-macro` implied by `-D warnings`
8+
= help: ensure to avoid having uses of it in version control
9+
10+
error: `dbg!` macro is intended as a debugging tool
11+
--> $DIR/dbg_macro.rs:12:8
12+
|
13+
LL | if dbg!(n <= 1) {
14+
| ^^^^^^^^^^^^
15+
|
16+
= help: ensure to avoid having uses of it in version control
17+
18+
error: `dbg!` macro is intended as a debugging tool
19+
--> $DIR/dbg_macro.rs:13:9
20+
|
21+
LL | dbg!(1)
22+
| ^^^^^^^
23+
|
24+
= help: ensure to avoid having uses of it in version control
25+
26+
error: `dbg!` macro is intended as a debugging tool
27+
--> $DIR/dbg_macro.rs:15:9
28+
|
29+
LL | dbg!(n * factorial(n - 1))
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: ensure to avoid having uses of it in version control
33+
34+
error: `dbg!` macro is intended as a debugging tool
35+
--> $DIR/dbg_macro.rs:20:5
336
|
437
LL | dbg!(42);
538
| ^^^^^^^^
639
|
7-
= note: `-D clippy::dbg-macro` implied by `-D warnings`
8-
help: ensure to avoid having uses of it in version control
40+
= help: ensure to avoid having uses of it in version control
41+
42+
error: `dbg!` macro is intended as a debugging tool
43+
--> $DIR/dbg_macro.rs:21:5
44+
|
45+
LL | dbg!(dbg!(dbg!(42)));
46+
| ^^^^^^^^^^^^^^^^^^^^
47+
|
48+
= help: ensure to avoid having uses of it in version control
49+
50+
error: `dbg!` macro is intended as a debugging tool
51+
--> $DIR/dbg_macro.rs:22:14
52+
|
53+
LL | foo(3) + dbg!(factorial(4));
54+
| ^^^^^^^^^^^^^^^^^^
955
|
10-
LL | 42;
11-
| ^^
56+
= help: ensure to avoid having uses of it in version control
1257

13-
error: aborting due to previous error
58+
error: aborting due to 7 previous errors
1459

0 commit comments

Comments
 (0)