]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/items_after_statements.txt
Rollup merge of #101602 - nnethercote:AttrTokenStream, r=petrochenkov
[rust.git] / src / tools / clippy / src / docs / items_after_statements.txt
1 ### What it does
2 Checks for items declared after some statement in a block.
3
4 ### Why is this bad?
5 Items live for the entire scope they are declared
6 in. But statements are processed in order. This might cause confusion as
7 it's hard to figure out which item is meant in a statement.
8
9 ### Example
10 ```
11 fn foo() {
12     println!("cake");
13 }
14
15 fn main() {
16     foo(); // prints "foo"
17     fn foo() {
18         println!("foo");
19     }
20     foo(); // prints "foo"
21 }
22 ```
23
24 Use instead:
25 ```
26 fn foo() {
27     println!("cake");
28 }
29
30 fn main() {
31     fn foo() {
32         println!("foo");
33     }
34     foo(); // prints "foo"
35     foo(); // prints "foo"
36 }
37 ```