Closed
Description
I tried this code:
struct Unit;
Unit = Unit;
I expected to see this being treated as a (trivial) destructuring assignment.
Instead, it fails with:
error[E0070]: invalid left-hand side of assignment
--> src/main.rs:3:10
|
3 | Unit = Unit;
| ---- ^
| |
| cannot assign to this expression
For more information about this error, try `rustc --explain E0070`.
error: could not compile `playground` (bin "playground") due to previous error
Likewise:
enum Enum { Unit }
Enum::Unit = Enum::Unit;
fails similarly.
On the other hand the very similar:
struct Tup0();
Tup0() = Tup0();
works as expected.
The RFC for this says:
We support the following classes of expressions:
- Tuples.
- Slices.
- Structs (including unit and tuple structs).
- Unique variants of enums.
It looks like enums are also not implemented. The PR implementing this for structs seems to overlook unit structs, and I couldn't find any place claiming to implement it for enums.
Meta
rustc --version --verbose
:
rustc 1.71.1 (eb26296b5 2023-08-03)
binary: rustc
commit-hash: eb26296b556cef10fb713a38f3d16b9886080f26
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
release: 1.71.1
LLVM version: 16.0.5
And is also present in nightly.