2022-05-21 06:24:00 -05:00
|
|
|
#[warn(clippy::mixed_read_write_in_expression)]
|
2018-12-09 16:26:16 -06:00
|
|
|
#[allow(
|
|
|
|
unused_assignments,
|
|
|
|
unused_variables,
|
|
|
|
clippy::no_effect,
|
|
|
|
dead_code,
|
2022-08-11 12:42:16 -05:00
|
|
|
clippy::disallowed_names
|
2018-12-09 16:26:16 -06:00
|
|
|
)]
|
2016-08-10 22:16:28 -05:00
|
|
|
fn main() {
|
|
|
|
let mut x = 0;
|
2018-12-09 16:26:16 -06:00
|
|
|
let a = {
|
|
|
|
x = 1;
|
|
|
|
1
|
|
|
|
} + x;
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: unsequenced read of `x`
|
2017-02-08 07:58:07 -06:00
|
|
|
|
2016-08-10 22:16:28 -05:00
|
|
|
// Example from iss#277
|
2018-12-09 16:26:16 -06:00
|
|
|
x += {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: unsequenced read of `x`
|
2018-12-09 16:26:16 -06:00
|
|
|
x = 20;
|
|
|
|
2
|
|
|
|
};
|
2016-08-10 22:16:28 -05:00
|
|
|
|
|
|
|
// Does it work in weird places?
|
|
|
|
// ...in the base for a struct expression?
|
2018-12-09 16:26:16 -06:00
|
|
|
struct Foo {
|
|
|
|
a: i32,
|
|
|
|
b: i32,
|
|
|
|
};
|
2016-08-10 22:16:28 -05:00
|
|
|
let base = Foo { a: 4, b: 5 };
|
2018-12-09 16:26:16 -06:00
|
|
|
let foo = Foo {
|
|
|
|
a: x,
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: unsequenced read of `x`
|
2018-12-09 16:26:16 -06:00
|
|
|
..{
|
|
|
|
x = 6;
|
|
|
|
base
|
|
|
|
}
|
|
|
|
};
|
2016-08-10 22:16:28 -05:00
|
|
|
// ...inside a closure?
|
|
|
|
let closure = || {
|
|
|
|
let mut x = 0;
|
2018-12-09 16:26:16 -06:00
|
|
|
x += {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: unsequenced read of `x`
|
2018-12-09 16:26:16 -06:00
|
|
|
x = 20;
|
|
|
|
2
|
|
|
|
};
|
2016-08-10 22:16:28 -05:00
|
|
|
};
|
|
|
|
// ...not across a closure?
|
|
|
|
let mut y = 0;
|
2018-12-09 16:26:16 -06:00
|
|
|
let b = (y, || y = 1);
|
2016-08-10 22:16:28 -05:00
|
|
|
|
|
|
|
// && and || evaluate left-to-right.
|
2018-12-09 16:26:16 -06:00
|
|
|
let a = {
|
|
|
|
x = 1;
|
|
|
|
true
|
|
|
|
} && (x == 3);
|
|
|
|
let a = {
|
|
|
|
x = 1;
|
|
|
|
true
|
|
|
|
} || (x == 3);
|
2016-08-10 22:16:28 -05:00
|
|
|
|
|
|
|
// Make sure we don't get confused by alpha conversion.
|
2018-12-09 16:26:16 -06:00
|
|
|
let a = {
|
|
|
|
let mut x = 1;
|
|
|
|
x = 2;
|
|
|
|
1
|
|
|
|
} + x;
|
2016-08-10 22:16:28 -05:00
|
|
|
|
|
|
|
// No warning if we don't read the variable...
|
2018-12-09 16:26:16 -06:00
|
|
|
x = {
|
|
|
|
x = 20;
|
|
|
|
2
|
|
|
|
};
|
2016-08-10 22:16:28 -05:00
|
|
|
// ...if the assignment is in a closure...
|
2018-12-09 16:26:16 -06:00
|
|
|
let b = {
|
|
|
|
|| {
|
|
|
|
x = 1;
|
|
|
|
};
|
|
|
|
1
|
|
|
|
} + x;
|
2016-08-10 22:16:28 -05:00
|
|
|
// ... or the access is under an address.
|
2018-12-09 16:26:16 -06:00
|
|
|
let b = (
|
|
|
|
{
|
|
|
|
let p = &x;
|
|
|
|
1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x = 1;
|
|
|
|
x
|
|
|
|
},
|
|
|
|
);
|
2016-08-10 22:16:28 -05:00
|
|
|
|
|
|
|
// Limitation: l-values other than simple variables don't trigger
|
|
|
|
// the warning.
|
|
|
|
let mut tup = (0, 0);
|
2018-12-09 16:26:16 -06:00
|
|
|
let c = {
|
|
|
|
tup.0 = 1;
|
|
|
|
1
|
|
|
|
} + tup.0;
|
2016-08-10 22:16:28 -05:00
|
|
|
// Limitation: you can get away with a read under address-of.
|
|
|
|
let mut z = 0;
|
2018-12-09 16:26:16 -06:00
|
|
|
let b = (
|
|
|
|
&{
|
|
|
|
z = x;
|
|
|
|
x
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x = 3;
|
|
|
|
x
|
|
|
|
},
|
|
|
|
);
|
2016-08-10 22:16:28 -05:00
|
|
|
}
|
2021-05-06 04:51:22 -05:00
|
|
|
|
|
|
|
async fn issue_6925() {
|
|
|
|
let _ = vec![async { true }.await, async { false }.await];
|
|
|
|
}
|