Any trait should be unsafe #62303
Labels
A-DSTs
Area: Dynamically-sized types (DSTs)
C-bug
Category: This is a bug.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
What is wrong?
Since
type_id()
is stable rust programs rely onAny
to be implemented correctly for rust safety relevant thinks (like downcast).Given the coding guide lines
Any
needs to be aunsafe
-to-implement trait as implementing it wrongly causes unsafety.Is it a problem?
Luckily no on can (currently) implement
Any
per-hand as any implementation conflicts with it's wild card implementations this means:Any
happen to be correct.Why should we change it?
The std is often used as an example for how thinks are done correctly in rust. If it is unsafe people looking at it would potentially think about why it needs to be unsafe and learn something from it. But if it isn't they might be surprised when there
Any
like trait is leads to unsafe behavior.What if we can't change it?
I think we can, as practically no one can implement any by hand. But if we can't we should at last document that it should be any in it's rust doc.
The text was updated successfully, but these errors were encountered: