-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Diagnostics for cloning references are terrible #34896
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-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.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-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.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.
https://is.gd/f2AX0B
This gives the very unintuitive error:
You expect
y.clone()to return(*y).clone(), i.e. aFoo. It mysteriously returns an&Fooinstead.Because
&Thas a clone impl, it too, can be cloned (really, copied), returning a reference of the same lifetime. This is an operation you rarely want to do explicitly, except when dealing with generics.This error can crop up when you've forgotten to implement
CloneonFoo, and have a reference (which could have been silently inserted usingref, as in the code above). However, it's not very obvious what's happening here. It can also crop up if you forget aT: CloneboundWe should hint that
Fooitself isn't cloneable and thus we fell back to cloning&Foohere.This could be a lint on hitting the clone impl for references, but lints run too late.
I'm not sure how this can be implemented, since we need to see the source of a value and that's a bit tricky.