1 #![feature(tool_lints)]
4 #[warn(clippy::eval_order_dependence)]
5 #[allow(unused_assignments, unused_variables, clippy::many_single_char_names, clippy::no_effect, dead_code, clippy::blacklisted_name)]
8 let a = { x = 1; 1 } + x;
10 // Example from iss#277
13 // Does it work in weird places?
14 // ...in the base for a struct expression?
15 struct Foo { a: i32, b: i32 };
16 let base = Foo { a: 4, b: 5 };
17 let foo = Foo { a: x, .. { x = 6; base } };
18 // ...inside a closure?
23 // ...not across a closure?
25 let b = (y, || { y = 1 });
27 // && and || evaluate left-to-right.
28 let a = { x = 1; true } && (x == 3);
29 let a = { x = 1; true } || (x == 3);
31 // Make sure we don't get confused by alpha conversion.
32 let a = { let mut x = 1; x = 2; 1 } + x;
34 // No warning if we don't read the variable...
36 // ...if the assignment is in a closure...
37 let b = { || { x = 1; }; 1 } + x;
38 // ... or the access is under an address.
39 let b = ({ let p = &x; 1 }, { x = 1; x });
41 // Limitation: l-values other than simple variables don't trigger
44 let c = { tup.0 = 1; 1 } + tup.0;
45 // Limitation: you can get away with a read under address-of.
47 let b = (&{ z = x; x }, { x = 3; x });