rust-lang / rust-lang/rust-clippy
Lint request: warn when temporaries are used for values for which dropping has side effects
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Temporary values (that I tend to call 'anonymous values') are values for which there is no variable binding. E.g.:
let a = Vec::<u8>::new().len();
Here the value of the type Vec<u8> is a temporary value.
Temporary values are -- generally speaking -- dropped at the semi-colon that terminates the statement in which they were created. More details can be found in the reference. This is not so well known and can be confusing, see e.g. rust-lang/book#1871. This can lead to bugs when a temporary is used to store a value for which the precise point where it is dropped is important, such as a LockResult. An example can be found in rust-lang/rust#37612.
To prevent such bugs, I think it would be a good idea if clippy would warn when a 'sensitive' value is stored in a temporary. With a 'sensitive' value, I mean something like a LockResult where calling the drop() has important side effects (so not just releasing memory).
Contributor guide
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 with the temporary-lifetime explanation, the linked Rust reference section, and the LockResult examples in the issue; no repository file or test is named. Define which temporary values are sensitive enough to warn about, then verify that the lint catches the described cases without flagging ordinary temporaries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100