about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs
blob: 205cd8ba4ee88a840a437e7c1d3bd9ccfb60fd52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//@aux-build:../../ui/auxiliary/proc_macros.rs
#![rustfmt::skip]
#![feature(custom_inner_attributes)]
#![warn(clippy::excessive_nesting)]
#![allow(
    unused,
    clippy::let_and_return,
    clippy::redundant_closure_call,
    clippy::no_effect,
    clippy::unnecessary_operation,
    clippy::never_loop,
    clippy::needless_if,
    clippy::collapsible_if,
    clippy::blocks_in_conditions,
    clippy::single_match,
)]

#[macro_use]
extern crate proc_macros;

static X: u32 = {
    let x = {
        let y = {
            let z = {
                let w = { 3 };
                //~^ excessive_nesting
                w
            };
            z
        };
        y
    };
    x
};

macro_rules! xx {
    () => {{
        {
            {
                {
                    {
                        {
                            {
                                {
                                    {
                                        {
                                            {
                                                println!("ehe"); // should not lint
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }};
}

struct A;

impl A {
    pub fn a(&self, v: u32) {
        struct B;

        impl B {
            pub fn b() {
                struct C;

                impl C {
                //~^ excessive_nesting
                    pub fn c() {}
                }
            }
        }
    }
}

struct D { d: u32 }

trait Lol {
    fn lmao() {
        fn bb() {
            fn cc() {
                let x = { 1 }; // not a warning, but cc is
                //~^ excessive_nesting
            }

            let x = { 1 }; // warning
        }
    }
}

#[allow(clippy::excessive_nesting)]
fn l() {{{{{{{{{}}}}}}}}}

use a::{b::{c::{d::{e::{f::{}}}}}}; // should not lint

pub mod a {
    pub mod b {
        pub mod c {
            pub mod d {
                pub mod e {
                //~^ excessive_nesting
                    pub mod f {}
                } // not here
            } // only warning should be here
        }
    }
}

fn a_but_not(v: u32) {}

fn main() {
    let a = A;

    a_but_not({{{{{{{{0}}}}}}}});
    //~^ excessive_nesting
    a.a({{{{{{{{{0}}}}}}}}});
    //~^ excessive_nesting
    (0, {{{{{{{1}}}}}}});
    //~^ excessive_nesting

    if true {
        if true {
            if true {
                if true {
                //~^ excessive_nesting
                    if true {

                    }
                }
            }
        }
    }

    let y = (|| {
        let x = (|| {
            let y = (|| {
                let z = (|| {
                //~^ excessive_nesting
                    let w = { 3 };
                    w
                })();
                z
            })();
            y
        })();
        x
    })();

    external! { {{{{{{{{{{{{{{{{}}}}}}}}}}}}}}}} }; // ensure this isn't linted in external macros
    with_span! { span {{{{{{{{{{{{}}}}}}}}}}}} }; // don't lint for proc macros
    xx!(); // ensure this is never linted
    let boo = true;
    !{boo as u32 + !{boo as u32 + !{boo as u32}}};

    // this is a mess, but that's intentional
    let mut y = 1;
    y += {{{{{5}}}}};
    //~^ excessive_nesting
    let z = y + {{{{{{{{{5}}}}}}}}};
    //~^ excessive_nesting
    [0, {{{{{{{{{{0}}}}}}}}}}];
    //~^ excessive_nesting
    let mut xx = [0; {{{{{{{{100}}}}}}}}];
    //~^ excessive_nesting
    xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}];
    //~^ excessive_nesting
    &mut {{{{{{{{{{y}}}}}}}}}};
    //~^ excessive_nesting

    for i in {{{{xx}}}} {{{{{{{{}}}}}}}}
    //~^ excessive_nesting
    //~| excessive_nesting

    while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}}
    //~^ excessive_nesting
    //~| excessive_nesting

    while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}}
    //~^ excessive_nesting
    //~| excessive_nesting

    let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} };
    //~^ excessive_nesting

    {{{{1;}}}}..{{{{{{3}}}}}};
    //~^ excessive_nesting
    //~| excessive_nesting
    {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}};
    //~^ excessive_nesting
    //~| excessive_nesting
    ..{{{{{{{5}}}}}}};
    //~^ excessive_nesting
    ..={{{{{3}}}}};
    //~^ excessive_nesting
    {{{{{1;}}}}}..;
    //~^ excessive_nesting

    loop { break {{{{1}}}} };
    //~^ excessive_nesting
    loop {{{{{{}}}}}}
    //~^ excessive_nesting

    match {{{{{{true}}}}}} {
    //~^ excessive_nesting
        true => {{{{}}}},
        //~^ excessive_nesting
        false => {{{{}}}},
        //~^ excessive_nesting
    }

    {
        {
            {
                {
                //~^ excessive_nesting
                    println!("warning! :)");
                }
            }
        }
    }
}

async fn b() -> u32 {
    async fn c() -> u32 {{{{{{{0}}}}}}}
    //~^ excessive_nesting

    c().await
}

async fn a() {
    {{{{b().await}}}};
    //~^ excessive_nesting
}