-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
strange borrowing suggestion #134805
Copy link
Copy link
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.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 lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.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.
Rustc suggests borrowing of a function's return type when there is a trait not implemented error for the function's parameters.
Not only does the borrow not help, a dereferencing is required instead, but it is suggested for the return type, which is not where the problem is at all.
Consider the following program:
On latest nightly
1.85.0-nightly (2024-12-25 7c002ff9a70cb84fd1a9)(same as on stable and beta):The example shows that if there is one parameter, a borrow is not suggested. It happens only if there is two parameters.
Related (but not the same): #132041