RS.CLIPPY.MIXED_READ_WRITE_IN_EXPRESSION
Whether a variable read occurs before a write depends on sub-expression evaluation order
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: mixed_read_write_in_expression. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for a read and a write to the same variable where whether the read occurs before or after the write depends on the evaluation order of sub-expressions.
Why restrict this?
While [the evaluation order of sub-expressions] is fully specified in Rust, it still may be confusing to read an expression where the evaluation order affects its behavior.
Known problems
Code which intentionally depends on the evaluation order, or which is correct for any evaluation order.
Example
let mut x = 0;
let a = {
x = 1;
1
} + x;
// Unclear whether a is 1 or 2.
Use instead:
let tmp = {
x = 1;
1
};
let a = tmp + x;
Past names
- eval_order_dependence