-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Don't suggest adding 'static lifetime to function arguments #69350
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.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-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.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.
When using a temporary reference in a context where temporary references are not allowed, rustc gives a technically-correct suggestion that in practice is most often misleading and makes beginners stuck trying to solve a wrong problem:
This suggestion is very unlikely to be useful in a real program. If the function is changed to require arguments with a
'staticlifetime, it generally just causes more borrow checking errors at the call sites of the function, causing inexperienced users dig deeper in the wrong direction.My suggestions:
Don't make code change suggestions for
'staticlifetime outside of globals. In this case no suggestion at all would be better than a misleading code change.Because the correct solution is most likely not to use a reference at all, don't focus the message on the (unusual) kind of reference that would work, but explain that most (i.e. non-
'static) references won't work.I suggest changing "lifetime
'staticrequired" say something along the lines of "temporary references are not allowed".