-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Lint for types where cleanup before drop is desirable #32677
Copy link
Copy link
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
BufWriter.dropis broken.BufWriterflushes data ondropand ignores the result. It is incorrect for two reasons:dropmay indefinitly hang, for example, ifBufWrtiterunderlying stream is socket, and nobody reads on the other sideGenerally, I think any
dropmust only release resources, do not do anything blocking or failing.The similar issue was only partially fixed in #30888.
We (together with @cfallin) propose a solution:
Proposed solution
Add another function to
BufWriter(and probably toWritetrait):cancel. User ofBufWritermust explicitly call eitherflushorcancelprior to drop.struct BufWritergetsunfinishedflag instead ofpanicked.BufWriter.writeunconditionally setsunfinished = true.BufWriter.flushorBufWriter.cancelunconditionally setunfinished = false.And finally,
BufWriter.dropbecomes an assertion:That change is backward incompatible, however, it is not that bad: developer will likely get panic on first program run, and can quickly fix the code.
Change could be transitional: no-op
cancelfunction could be added in rust version current+1 and assertion added in rust version current+2.