Rust has several operators that cannot be chained (==
, <
for example).
But the assignment operator =
can be chained.
a = b = 10;
In this case, 10 is assigned to b
, and unit ()
is assigned to a
.
Is there any reason why Rust allows us to chain =
like this?
I created Clippy issue 6576 about this.
a
is expected to be of type()
. – Hoicksa + b + c
), so since there's an RFC specifically for the comparison operators it indicates that the assignment's behavior is the default rather than an exception. That and the provided motivation for restricting the comparison operators wouldn't apply to assignments. – Tony