Skip to content

try_as_dyn does not work with builtin impls #162134

Description

@Janrupf

Lifting this from a discussion on Zulip.

core::any::try_as_dyn doesn't work (always returns None) when trying to access builtin impls in any way:

trait SyncAble {}
impl<T> SyncAble for T where T: Sync /* <- builtin */ {}

println!("{}", core::any::try_as_dyn::<u32, dyn SyncAble>(&0).is_some());

Thats quite annoying because checking whether T: Sync holds would potentially allow for optimizations (offloading computations). The same applies to all other builtin impl's. This can be quite confusing, especially because its not consistent for a single trait either.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-dyn-traitArea: trait objects, vtable layoutC-bugCategory: This is a bug.F-try_as_dyn`#![feature(try_as_dyn)]`T-typesRelevant to the types 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