-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Lint for undesirable, implicit copies #45683
Copy link
Copy link
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-design-concernsStatus: There are blocking design concerns.Status: There are blocking design concerns.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-design-concernsStatus: There are blocking design concerns.Status: There are blocking design concerns.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
As part of #44619, one topic that keeps coming up is that we have to find some way to mitigate the risk of large, implicit copies. Indeed, this risk exists today even without any changes to the language:
In addition to performance hazards, implicit copies can have surprising semantics. For example, there are several iterator types that would implement
Copy, but we were afraid that people would be surprised. Another, clearer example is a type likeCell<i32>, which could certainly be copy, but for this interaction:For a time before 1.0, we briefly considered introducing a new
Podtrait that acted likeCopy(memcpy is safe) but without the implicit copy semantics. At the time, @eddyb argued persuasively against this, basically saying (and rightly so) that this is more of a linting concern than anything else -- the implicit copies in the example above, after all, don't lead to any sort of unsoundness, they just may not be the semantics you expected.Since then, a number of use cases have arisen where having some kind of warning against implicit, unexpected copies would be useful:
CopyCell,RefCell, and other types with interior mutability implementingCopy#[derive(PartiallEq)]and friends with packed structs&TtoT(i.e., it'd be nice to be able to dofoo(x)wherefoo: fn(u32)andx: &u32)I will writeup a more specific proposal in the thread below.