-
Notifications
You must be signed in to change notification settings - Fork 886
Description
Feature Request
Crates
tracing-core
Motivation
Right now, Collect::downcast_raw returns an Option<*const ()>:
tracing/tracing-core/src/collect.rs
Line 448 in eadf2a2
| 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.