Strengthen linear typing via #[must_use(dispose)]
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
#[must_use] has a hole in its coverage. Suppose we have some code like this:
let transaction = Transaction::new(&kitchen)
.catch_frogs(3)
.set_gas_flow(2.5);
if transaction.is_boiling() {
println!("How I love a nice bowl of frog soup!");
}
At this point, #[must_use] is satisfied merely because transaction has been inspected (via &self), but the call to transaction.commit() has been forgotten and there may be an error to rollback. What we want is for there to be a warning if the type has not been properly disposed of.
A type can be disposed of by destructuring, or by passing it off to another function.
Some consequences:
mem::dropcounts as disposal. It won't be infallible for the same reasons that Drop isn't infallible.- Traits like
trait Foo { fn foo(self) {} }would expose a hole. And it could be a blanket implementation. - A method can ignore
selfby usinglet Self { .. } = self.
Result could be marked #[must_use(dispose)]. But I don't think it should be.
Alternatives
- Do nothing, and change
fn inspect(&self) -> booltofn inspect(self) -> (Self, bool). - Do nothing.
- Implement with clippy instead.
- A different syntax, like
#[must_dispose]. - Make
#[must_use]function like the proposed#[must_use(dispose)].
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
No files, tests, or implementation entry points are named. Begin by resolving the proposed #[must_use(dispose)] semantics and comparing the listed alternatives; the issue is ready only when a concrete direction and acceptance criteria are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100