Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce safety of
downcast_ref
at compile time. (#1326)
* Enforce safety of `downcast_ref` at compile time. The safety of `downcast_ref` requires that `__private_get_type_id__` not be overriden by callers, since the returned `TypeId` is used to check if the cast is safe. However, all trait methods in Rust are public, so users can override `__private_get_type_id__` despite it being `#[doc(hidden)]`. This commit makes `__private_get_type_id__` return a type with a private constructor, ensuring that the only possible implementation is the default implementation. A more detailed explanation is provided in the comments added to the file. Note that the standard library was affected by this type of issue with the `Error::type_id` function: see https://blog.rust-lang.org/2019/05/14/Rust-1.34.2.html#whats-in-1.34.2-stable Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
- Loading branch information