Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ The maximum size of an enum's variant to avoid box suggestion
## `excessive-nesting-threshold`
The maximum amount of nesting a block can reside in

**Default Value:** `0`
**Default Value:** `8`

---
**Affected lints:**
Expand Down
2 changes: 1 addition & 1 deletion clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ define_Conf! {
enum_variant_size_threshold("enum-variant-size-threshold"): u64 = 200,
/// The maximum amount of nesting a block can reside in
#[lints(excessive_nesting)]
excessive_nesting_threshold("excessive-nesting-threshold"): u64 = 0,
excessive_nesting_threshold("excessive-nesting-threshold"): u64 = 8,
/// The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint
#[lints(large_futures)]
future_size_threshold("future-size-threshold"): u64 = 16 * 1024,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/excessive_nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare_clippy_lint! {
/// ### What it does
/// Checks for blocks which are nested beyond a certain threshold.
///
/// 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.
/// The default maximum nesting level is 8 and can be customized in the clippy.toml file.
///
/// ### Why is this bad?
/// It can severely hinder readability.
Expand Down Expand Up @@ -58,7 +58,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.72.0"]
pub EXCESSIVE_NESTING,
complexity,
pedantic,
"checks for blocks nested beyond a certain threshold"
}

Expand Down
93 changes: 93 additions & 0 deletions tests/ui/excessive_nesting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#![warn(clippy::pedantic)]
#![allow(clippy::let_and_return)]

fn main() {

@CommanderStorm CommanderStorm Aug 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to string you along like this. only noticed this now:

Actually, lets add a testcase for level 6 as well, so that we know that we don't lint there.

View changes since the review

// This should not trigger
let a = {
let b = {
let c = {
let d = {
let e = {
let f = { 42 };
f
};
e
};
d
};
c
};
b
};

// This should trigger at level 9
let x = {
let y = {
let z = {
let w = {
let v = {
let u = {
let t = {
let s = { 42 };
//~^ excessive_nesting
s
};
t
};
u
};
v
};
w
};
z
};
y
};
}

struct A;

impl A {
fn test() {
// This should trigger at level 9
struct B;
impl B {
fn test() {
struct C;
impl C {
fn test() {
{
if true {
let x = { 1 };
//~^ excessive_nesting
}
}
}
}
}
}
}
}

trait TestTrait {
fn test() {
// This should trigger at level 9
struct B;
impl B {
fn test() {
struct C;
impl C {
fn test() {
{
if true {
let x = { 1 };
//~^ excessive_nesting
}
}
}
}
}
}
}
}
28 changes: 28 additions & 0 deletions tests/ui/excessive_nesting.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error: this block is too nested
--> tests/ui/excessive_nesting.rs:31:41
|
LL | ... let s = { 42 };
| ^^^^^^
|
= help: try refactoring your code to minimize nesting
= note: `-D clippy::excessive-nesting` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]`

error: this block is too nested
--> tests/ui/excessive_nesting.rs:62:41
|
LL | ... let x = { 1 };
| ^^^^^
|
= help: try refactoring your code to minimize nesting

error: this block is too nested
--> tests/ui/excessive_nesting.rs:84:41
|
LL | ... let x = { 1 };
| ^^^^^
|
= help: try refactoring your code to minimize nesting

error: aborting due to 3 previous errors

Loading