A void value is treated as linear: using it twice is a move error
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14
- Forks
- 2
- Avg merge
- 12h 42m
- Merged PRs (30d)
- 61
Description
void is spelled Type::Struct("void") (syntax/types.rs, is_void_ty), and the linearity rules consume any Type::Struct. So a valueless result behaves like an owned resource:
fn nothing() -> void { }
fn main() -> i32 {
let z = nothing();
let a = z;
let b = z;
return 0;
}
Error[E4001] at 5:11: Use of moved or consumed linear variable: z
There is nothing to move. The same rule makes a unit-valued expression (an if with no else, an empty block) report a spurious move when used twice.
Found while splitting the tensor spellings (#399). Before that work these sites answered a dims-less Tensor<f32>, which is also linear, so the behaviour predates the split and is unchanged by it — the switch to void only made the diagnostic name the type honestly instead of printing Tensor(F32, [], None) at the user.
Fix direction: exempt void/none from consumption wherever Type::Struct triggers it, or give unit its own Type variant so it cannot inherit struct rules by spelling.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in syntax/types.rs with Type::Struct("void") and is_void_ty, then trace the linearity path that consumes Type::Struct values. Reproduce the issue with the provided nothing() example and the unit-valued expression cases. Done means void and unit values can be used more than once without a spurious move error, while other linear structs retain their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100