You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code uses a block express as both the LHS and RHS of a compound assignment operator (+=). This code is not only difficult to read - its execution order depends on the type of the expression produced by the block (see rust-lang/rust#28160 and rust-lang/rust#61572).
That is, the evaluation order of the LHS and RHS is dependent on whether or not the type used is a primitive or not.
Using a block expression with a compound assignment operator is a bad idea in and of itself - it's very difficult to read, and makes it unclear what is actually happening. However, the inconsistent evaluation order makes this even worse - a seemly unrelated change (e.g. changing the type of a variable earlier up in a function) can result in the execution order of other expressions changing.
It would be useful if Clippy were to lint the use of anything other than a variable, literal, or (chain of) method calls with a compound assignment operator.
The text was updated successfully, but these errors were encountered:
Consider the following code:
This code uses a block express as both the LHS and RHS of a compound assignment operator (
+=
). This code is not only difficult to read - its execution order depends on the type of the expression produced by the block (see rust-lang/rust#28160 and rust-lang/rust#61572).As written, this code prints:
However, this nearly identical code:
prints:
That is, the evaluation order of the LHS and RHS is dependent on whether or not the type used is a primitive or not.
Using a block expression with a compound assignment operator is a bad idea in and of itself - it's very difficult to read, and makes it unclear what is actually happening. However, the inconsistent evaluation order makes this even worse - a seemly unrelated change (e.g. changing the type of a variable earlier up in a function) can result in the execution order of other expressions changing.
It would be useful if Clippy were to lint the use of anything other than a variable, literal, or (chain of) method calls with a compound assignment operator.
The text was updated successfully, but these errors were encountered: