]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #[warn(clippy::eval_order_dependence)] |
2 | #[allow( | |
3 | unused_assignments, | |
4 | unused_variables, | |
f20569fa XL |
5 | clippy::no_effect, |
6 | dead_code, | |
7 | clippy::blacklisted_name | |
8 | )] | |
9 | fn main() { | |
10 | let mut x = 0; | |
11 | let a = { | |
12 | x = 1; | |
13 | 1 | |
14 | } + x; | |
15 | ||
16 | // Example from iss#277 | |
17 | x += { | |
18 | x = 20; | |
19 | 2 | |
20 | }; | |
21 | ||
22 | // Does it work in weird places? | |
23 | // ...in the base for a struct expression? | |
24 | struct Foo { | |
25 | a: i32, | |
26 | b: i32, | |
27 | }; | |
28 | let base = Foo { a: 4, b: 5 }; | |
29 | let foo = Foo { | |
30 | a: x, | |
31 | ..{ | |
32 | x = 6; | |
33 | base | |
34 | } | |
35 | }; | |
36 | // ...inside a closure? | |
37 | let closure = || { | |
38 | let mut x = 0; | |
39 | x += { | |
40 | x = 20; | |
41 | 2 | |
42 | }; | |
43 | }; | |
44 | // ...not across a closure? | |
45 | let mut y = 0; | |
46 | let b = (y, || y = 1); | |
47 | ||
48 | // && and || evaluate left-to-right. | |
49 | let a = { | |
50 | x = 1; | |
51 | true | |
52 | } && (x == 3); | |
53 | let a = { | |
54 | x = 1; | |
55 | true | |
56 | } || (x == 3); | |
57 | ||
58 | // Make sure we don't get confused by alpha conversion. | |
59 | let a = { | |
60 | let mut x = 1; | |
61 | x = 2; | |
62 | 1 | |
63 | } + x; | |
64 | ||
65 | // No warning if we don't read the variable... | |
66 | x = { | |
67 | x = 20; | |
68 | 2 | |
69 | }; | |
70 | // ...if the assignment is in a closure... | |
71 | let b = { | |
72 | || { | |
73 | x = 1; | |
74 | }; | |
75 | 1 | |
76 | } + x; | |
77 | // ... or the access is under an address. | |
78 | let b = ( | |
79 | { | |
80 | let p = &x; | |
81 | 1 | |
82 | }, | |
83 | { | |
84 | x = 1; | |
85 | x | |
86 | }, | |
87 | ); | |
88 | ||
89 | // Limitation: l-values other than simple variables don't trigger | |
90 | // the warning. | |
91 | let mut tup = (0, 0); | |
92 | let c = { | |
93 | tup.0 = 1; | |
94 | 1 | |
95 | } + tup.0; | |
96 | // Limitation: you can get away with a read under address-of. | |
97 | let mut z = 0; | |
98 | let b = ( | |
99 | &{ | |
100 | z = x; | |
101 | x | |
102 | }, | |
103 | { | |
104 | x = 3; | |
105 | x | |
106 | }, | |
107 | ); | |
108 | } | |
17df50a5 XL |
109 | |
110 | async fn issue_6925() { | |
111 | let _ = vec![async { true }.await, async { false }.await]; | |
112 | } |