Skip to content

Any trait should be unsafe #62303

Closed
@rustonaut

Description

@rustonaut

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DSTsArea: Dynamically-sized types (DSTs)C-bugCategory: This is a bug.T-langRelevant to the language team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions