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