Skip to content

Commit

Permalink
subscriber: fix Layered layers not downcasting to themselves (tokio…
Browse files Browse the repository at this point in the history
…-rs#549)

Currently, a `Layered` struct's implementations of `Subscriber` and
`Layer` will successfully downcast to either the the `Layer` type or the
inner type, but *not* to `Layered<Layer, Inner>`. This means that when a
`Layer` tries to downcast the wrapped subscriber to a known type, and it
is a `Layered` (so, any time more than one layer wraps a subscriber and
a layer other than the first one tries to downcast to the inner type it
wraps), the downcast will fail incorrectly.

This commit fixes the issue by checking if the downcast target `TypeId`
equals the `Layered` type's `TypeId`, _before_ trying to downcast to the
layer itself or to the inner type.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw authored and yaahc committed Jan 28, 2020
1 parent 9b07cb3 commit c98c69b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tracing-subscriber/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@ where

#[doc(hidden)]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
if id == TypeId::of::<Self>() {
return Some(self as *const _ as *const ());
}
self.layer
.downcast_raw(id)
.or_else(|| self.inner.downcast_raw(id))
Expand Down Expand Up @@ -623,6 +626,9 @@ where

#[doc(hidden)]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
if id == TypeId::of::<Self>() {
return Some(self as *const _ as *const ());
}
self.layer
.downcast_raw(id)
.or_else(|| self.inner.downcast_raw(id))
Expand Down

0 comments on commit c98c69b

Please sign in to comment.