File tree Expand file tree Collapse file tree 5 files changed +148
-9
lines changed Expand file tree Collapse file tree 5 files changed +148
-9
lines changed Original file line number Diff line number Diff line change @@ -610,7 +610,7 @@ The maximum size of an enum's variant to avoid box suggestion
610
610
## ` excessive-nesting-threshold `
611
611
The maximum amount of nesting a block can reside in
612
612
613
- ** Default Value:** ` 0 `
613
+ ** Default Value:** ` 6 `
614
614
615
615
---
616
616
** Affected lints:**
Original file line number Diff line number Diff line change @@ -631,7 +631,7 @@ define_Conf! {
631
631
enum_variant_size_threshold: u64 = 200 ,
632
632
/// The maximum amount of nesting a block can reside in
633
633
#[ lints( excessive_nesting) ]
634
- excessive_nesting_threshold: u64 = 0 ,
634
+ excessive_nesting_threshold: u64 = 6 ,
635
635
/// The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint
636
636
#[ lints( large_futures) ]
637
637
future_size_threshold: u64 = 16 * 1024 ,
Original file line number Diff line number Diff line change @@ -12,8 +12,6 @@ declare_clippy_lint! {
12
12
/// ### What it does
13
13
/// Checks for blocks which are nested beyond a certain threshold.
14
14
///
15
- /// Note: Even though this lint is warn-by-default, it will only trigger if a maximum nesting level is defined in the clippy.toml file.
16
- ///
17
15
/// ### Why is this bad?
18
16
/// It can severely hinder readability.
19
17
///
@@ -58,7 +56,7 @@ declare_clippy_lint! {
58
56
/// ```
59
57
#[ clippy:: version = "1.72.0" ]
60
58
pub EXCESSIVE_NESTING ,
61
- complexity ,
59
+ pedantic ,
62
60
"checks for blocks nested beyond a certain threshold"
63
61
}
64
62
impl_lint_pass ! ( ExcessiveNesting => [ EXCESSIVE_NESTING ] ) ;
@@ -92,10 +90,6 @@ impl ExcessiveNesting {
92
90
93
91
impl EarlyLintPass for ExcessiveNesting {
94
92
fn check_crate ( & mut self , cx : & EarlyContext < ' _ > , krate : & Crate ) {
95
- if self . excessive_nesting_threshold == 0 {
96
- return ;
97
- }
98
-
99
93
let mut visitor = NestingVisitor {
100
94
conf : self ,
101
95
cx,
Original file line number Diff line number Diff line change
1
+ #![ warn( clippy:: pedantic) ]
2
+ #![ allow(
3
+ unused,
4
+ clippy:: let_and_return,
5
+ clippy:: redundant_closure_call,
6
+ clippy:: no_effect,
7
+ clippy:: unnecessary_operation,
8
+ clippy:: needless_if,
9
+ clippy:: single_match,
10
+ clippy:: unused_self
11
+ ) ]
12
+
13
+ fn main ( ) {
14
+ // This should not trigger with default threshold of 6
15
+ let a = {
16
+ let b = {
17
+ let c = {
18
+ let d = {
19
+ let e = {
20
+ let f = { 42 } ;
21
+ //~^ ERROR: this block is too nested
22
+ f
23
+ } ;
24
+ e
25
+ } ;
26
+ d
27
+ } ;
28
+ c
29
+ } ;
30
+ b
31
+ } ;
32
+
33
+ // This should trigger with default threshold of 6
34
+ let x = {
35
+ let y = {
36
+ let z = {
37
+ let w = {
38
+ let v = {
39
+ let u = {
40
+ //~^ ERROR: this block is too nested
41
+ let t = { 42 } ;
42
+ t
43
+ } ;
44
+ u
45
+ } ;
46
+ v
47
+ } ;
48
+ w
49
+ } ;
50
+ z
51
+ } ;
52
+ y
53
+ } ;
54
+ }
55
+
56
+ struct A ;
57
+
58
+ impl A {
59
+ fn test ( ) {
60
+ // This should not trigger
61
+ struct B ;
62
+ impl B {
63
+ fn test ( ) {
64
+ struct C ;
65
+ impl C {
66
+ fn test ( ) {
67
+ if true {
68
+ //~^ ERROR: this block is too nested
69
+ let x = { 1 } ;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ trait TestTrait {
79
+ fn test ( ) {
80
+ // This should trigger (7 levels)
81
+ struct B ;
82
+ impl B {
83
+ fn test ( ) {
84
+ struct C ;
85
+ impl C {
86
+ fn test ( ) {
87
+ if true {
88
+ //~^ ERROR: this block is too nested
89
+ let x = { 1 } ;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
Original file line number Diff line number Diff line change
1
+ error: this block is too nested
2
+ --> tests/ui/excessive_nesting.rs:20:33
3
+ |
4
+ LL | let f = { 42 };
5
+ | ^^^^^^
6
+ |
7
+ = help: try refactoring your code to minimize nesting
8
+ = note: `-D clippy::excessive-nesting` implied by `-D warnings`
9
+ = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]`
10
+
11
+ error: this block is too nested
12
+ --> tests/ui/excessive_nesting.rs:39:33
13
+ |
14
+ LL | let u = {
15
+ | _________________________________^
16
+ LL | |
17
+ LL | | let t = { 42 };
18
+ LL | | t
19
+ LL | | };
20
+ | |_________________________^
21
+ |
22
+ = help: try refactoring your code to minimize nesting
23
+
24
+ error: this block is too nested
25
+ --> tests/ui/excessive_nesting.rs:67:33
26
+ |
27
+ LL | if true {
28
+ | _________________________________^
29
+ LL | |
30
+ LL | | let x = { 1 };
31
+ LL | | }
32
+ | |_________________________^
33
+ |
34
+ = help: try refactoring your code to minimize nesting
35
+
36
+ error: this block is too nested
37
+ --> tests/ui/excessive_nesting.rs:87:33
38
+ |
39
+ LL | if true {
40
+ | _________________________________^
41
+ LL | |
42
+ LL | | let x = { 1 };
43
+ LL | | }
44
+ | |_________________________^
45
+ |
46
+ = help: try refactoring your code to minimize nesting
47
+
48
+ error: aborting due to 4 previous errors
49
+
You can’t perform that action at this time.
0 commit comments