summaryrefslogtreecommitdiffstats
path: root/vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:11:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:12:43 +0000
commitcf94bdc0742c13e2a0cac864c478b8626b266e1b (patch)
tree044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs
parentAdding debian version 1.65.0+dfsg1-2. (diff)
downloadrustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz
rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs')
-rw-r--r--vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs68
1 files changed, 0 insertions, 68 deletions
diff --git a/vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs b/vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs
deleted file mode 100644
index b5f7e35ce..000000000
--- a/vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs
+++ /dev/null
@@ -1,68 +0,0 @@
-use tracing::Subscriber;
-use tracing_subscriber::filter::Targets;
-use tracing_subscriber::prelude::*;
-use tracing_subscriber::Layer;
-
-#[test]
-fn downcast_ref_to_inner_layer_and_filter() {
- // Test that a filtered layer gives downcast_ref access to
- // both the layer and the filter.
-
- struct WrappedLayer;
-
- impl<S> Layer<S> for WrappedLayer
- where
- S: Subscriber,
- S: for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>,
- {
- }
-
- let layer = WrappedLayer;
- let filter = Targets::new().with_default(tracing::Level::INFO);
- let registry = tracing_subscriber::registry().with(layer.with_filter(filter));
- let dispatch = tracing::dispatcher::Dispatch::new(registry);
-
- // The filter is available
- assert!(dispatch.downcast_ref::<Targets>().is_some());
- // The wrapped layer is available
- assert!(dispatch.downcast_ref::<WrappedLayer>().is_some());
-}
-
-#[test]
-fn forward_downcast_raw_to_layer() {
- // Test that a filtered layer still gives its wrapped layer a chance to
- // return a custom struct from downcast_raw.
- // https://github.com/tokio-rs/tracing/issues/1618
-
- struct WrappedLayer {
- with_context: WithContext,
- }
-
- struct WithContext;
-
- impl<S> Layer<S> for WrappedLayer
- where
- S: Subscriber,
- S: for<'lookup> tracing_subscriber::registry::LookupSpan<'lookup>,
- {
- unsafe fn downcast_raw(&self, id: std::any::TypeId) -> Option<*const ()> {
- match id {
- id if id == std::any::TypeId::of::<Self>() => Some(self as *const _ as *const ()),
- id if id == std::any::TypeId::of::<WithContext>() => {
- Some(&self.with_context as *const _ as *const ())
- }
- _ => None,
- }
- }
- }
-
- let layer = WrappedLayer {
- with_context: WithContext,
- };
- let filter = Targets::new().with_default(tracing::Level::INFO);
- let registry = tracing_subscriber::registry().with(layer.with_filter(filter));
- let dispatch = tracing::dispatcher::Dispatch::new(registry);
-
- // Types from a custom implementation of `downcast_raw` are available
- assert!(dispatch.downcast_ref::<WithContext>().is_some());
-}