Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any trait should be unsafe #62303

Closed
rustonaut opened this issue Jul 2, 2019 · 0 comments · Fixed by #67519
Closed

Any trait should be unsafe #62303

rustonaut opened this issue Jul 2, 2019 · 0 comments · Fixed by #67519
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.

Comments

@rustonaut
Copy link

rustonaut commented Jul 2, 2019

What is wrong?

Since type_id() is stable rust programs rely on Any to be implemented correctly for rust safety relevant thinks (like downcast).

Given the coding guide lines Any needs to be a unsafe-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:

  1. All impl. of Any happen to be correct.
  2. We can change it without causing breakage, at last as far as I can tell.

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.

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-DSTs Area: Dynamically-sized types (DSTs) labels Jul 2, 2019
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Jul 2, 2019
Centril added a commit to Centril/rust that referenced this issue Dec 22, 2019
Document why Any is not an unsafe trait

The added documentation is not public (i.e., not in a doc comment) but that seems appropriate for this sort of low-level detail.

Fixes rust-lang#62303
Centril added a commit to Centril/rust that referenced this issue Dec 22, 2019
Document why Any is not an unsafe trait

The added documentation is not public (i.e., not in a doc comment) but that seems appropriate for this sort of low-level detail.

Fixes rust-lang#62303
@bors bors closed this as completed in ce6f0b0 Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants