-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Detect attempt to reuse buffer with extended borrows #147694
Copy link
Copy link
Closed
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.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.
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Given code like the following three cases where the user intended to reuse a previously allocated mutable buffer in a loop where the buffer is populated with borrows which affect the lifetime of the buffer itself, the errors are always E0597 "doesn't live long enough" pointing at the intermediary data being used.
The compiler should detect cases of buffer re-use and explain what's going on, pointing at the
bufferdeclaration.Ideally, it should recommend using
recycle_vec(or the potential std API of the same use), or theunsafecode required to reconstitute the buffer within the loop without reallocation.Case 1 in https://databento.com/blog/why-we-didnt-rewrite-our-feed-handler-in-rust, additional discussion in https://internals.rust-lang.org/t/same-old-issues-recurring-self-referential-types-generics-less-flexible-than-c-templates/23603