Skip to content

Commit 725399a

Browse files
committed
move to complexity but don't lint by default
1 parent 378d775 commit 725399a

File tree

8 files changed

+12
-54
lines changed

8 files changed

+12
-54
lines changed

book/src/lint_configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ The maximum cognitive complexity a function can have
161161
## `excessive-nesting-threshold`
162162
The maximum amount of nesting a block can reside in
163163

164-
**Default Value:** `10` (`u64`)
164+
**Default Value:** `0` (`u64`)
165165

166166
---
167167
**Affected lints:**

clippy_lints/src/excessive_nesting.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ use rustc_span::Span;
1111

1212
declare_clippy_lint! {
1313
/// ### What it does
14-
///
1514
/// Checks for blocks which are nested beyond a certain threshold.
1615
///
17-
/// ### Why is this bad?
16+
/// 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.
1817
///
19-
/// It can severely hinder readability. The default is very generous; if you
20-
/// exceed this, it's a sign you should refactor.
18+
/// ### Why is this bad?
19+
/// It can severely hinder readability.
2120
///
2221
/// ### Example
2322
/// An example clippy.toml configuration:
@@ -59,7 +58,7 @@ declare_clippy_lint! {
5958
/// ```
6059
#[clippy::version = "1.70.0"]
6160
pub EXCESSIVE_NESTING,
62-
restriction,
61+
complexity,
6362
"checks for blocks nested beyond a certain threshold"
6463
}
6564
impl_lint_pass!(ExcessiveNesting => [EXCESSIVE_NESTING]);
@@ -115,7 +114,9 @@ struct NestingVisitor<'conf, 'cx> {
115114

116115
impl NestingVisitor<'_, '_> {
117116
fn check_indent(&mut self, span: Span, id: NodeId) -> bool {
118-
if self.nest_level > self.conf.excessive_nesting_threshold && !in_external_macro(self.cx.sess(), span) {
117+
let threshold = self.conf.excessive_nesting_threshold;
118+
119+
if threshold != 0 && self.nest_level > threshold && !in_external_macro(self.cx.sess(), span) {
119120
self.conf.nodes.insert(id);
120121

121122
return true;

clippy_lints/src/utils/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ define_Conf! {
308308
/// Lint: EXCESSIVE_NESTING.
309309
///
310310
/// The maximum amount of nesting a block can reside in
311-
(excessive_nesting_threshold: u64 = 10),
311+
(excessive_nesting_threshold: u64 = 0),
312312
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
313313
///
314314
/// Use the Cognitive Complexity lint instead.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
excessive-nesting-threshold = 10
1+
excessive-nesting-threshold = 0
Original file line numberDiff line numberDiff line change
@@ -1,43 +0,0 @@
1-
error: this block is too nested
2-
--> $DIR/excessive_nesting.rs:154:18
3-
|
4-
LL | [0, {{{{{{{{{{0}}}}}}}}}}];
5-
| ^^^
6-
|
7-
= help: try refactoring your code to minimize nesting
8-
= note: `-D clippy::excessive-nesting` implied by `-D warnings`
9-
10-
error: this block is too nested
11-
--> $DIR/excessive_nesting.rs:156:17
12-
|
13-
LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}];
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= help: try refactoring your code to minimize nesting
17-
18-
error: this block is too nested
19-
--> $DIR/excessive_nesting.rs:157:19
20-
|
21-
LL | &mut {{{{{{{{{{y}}}}}}}}}};
22-
| ^^^
23-
|
24-
= help: try refactoring your code to minimize nesting
25-
26-
error: this block is too nested
27-
--> $DIR/excessive_nesting.rs:165:29
28-
|
29-
LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} };
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
|
32-
= help: try refactoring your code to minimize nesting
33-
34-
error: this block is too nested
35-
--> $DIR/excessive_nesting.rs:168:27
36-
|
37-
LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}};
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39-
|
40-
= help: try refactoring your code to minimize nesting
41-
42-
error: aborting due to 5 previous errors
43-

tests/ui-toml/excessive_nesting/excessive_nesting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@aux-build:macro_rules.rs
2-
//@revisions: below default
3-
//@[below] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/below
2+
//@revisions: set default
3+
//@[set] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/set
44
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/excessive_nesting/default
55
#![rustfmt::skip]
66
#![feature(custom_inner_attributes)]

0 commit comments

Comments
 (0)