Skip to content

core: change Collect::downcast_raw to return NonNull #1073

@hawkw

Description

@hawkw

Feature Request

Crates

  • tracing-core

Motivation

Right now, Collect::downcast_raw returns an Option<*const ()>:

unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {

The void pointer is expected to never be null, but rustc doesn't know that. This means that we're returning an option discriminant as well as a pointer, so it's more than 1 word.

Proposal

If we changed this to Option<NonNull<()>> we could benefit from niche optimization, saving us the option discriminant and making this return a single word pointer. That may in turn let us benefit from additional optimizations. This could make downcasting slightly faster.

Also, callers wouldn't have to null-check the pointer manually.

This is technically a breaking change, even though this API isn't supposed to be used publicly. However, we can make this change as part of tracing-core 0.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/coreRelated to the `tracing-core` cratemeta/breakingThis is a breaking change, and should wait until the next breaking release.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions