1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
11 #![feature(tool_lints)]
14 #[warn(clippy::eval_order_dependence)]
15 #[allow(unused_assignments, unused_variables, clippy::many_single_char_names, clippy::no_effect, dead_code, clippy::blacklisted_name)]
18 let a = { x = 1; 1 } + x;
20 // Example from iss#277
23 // Does it work in weird places?
24 // ...in the base for a struct expression?
25 struct Foo { a: i32, b: i32 };
26 let base = Foo { a: 4, b: 5 };
27 let foo = Foo { a: x, .. { x = 6; base } };
28 // ...inside a closure?
33 // ...not across a closure?
35 let b = (y, || { y = 1 });
37 // && and || evaluate left-to-right.
38 let a = { x = 1; true } && (x == 3);
39 let a = { x = 1; true } || (x == 3);
41 // Make sure we don't get confused by alpha conversion.
42 let a = { let mut x = 1; x = 2; 1 } + x;
44 // No warning if we don't read the variable...
46 // ...if the assignment is in a closure...
47 let b = { || { x = 1; }; 1 } + x;
48 // ... or the access is under an address.
49 let b = ({ let p = &x; 1 }, { x = 1; x });
51 // Limitation: l-values other than simple variables don't trigger
54 let c = { tup.0 = 1; 1 } + tup.0;
55 // Limitation: you can get away with a read under address-of.
57 let b = (&{ z = x; x }, { x = 3; x });