Lint request: warn when temporaries are used for values for which dropping has side effects #1904
Labels
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
L-correctness
Lint: Belongs in the correctness lint group
T-middle
Type: Probably requires verifiying types
T-MIR
Type: This lint will require working with the MIR
Temporary values (that I tend to call 'anonymous values') are values for which there is no variable binding. E.g.:
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 thedrop()
has important side effects (so not just releasing memory).The text was updated successfully, but these errors were encountered: