From fefe5837221783119441a1e661c5a3aae895d857 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Sun, 21 Nov 2021 15:19:38 -0800 Subject: [PATCH] chore: remove *all* `extern crate` statements (#1738) Depends on #1737 This branch removes all remaining `extern crate` statements. Most of these are in old code and were not removed when updating to Rust 2018. Whoops! Our MSRV no longer requires `extern crate`, so we don't need these. The exception is `extern crate` statements for `std` and `alloc`, which are still the way these libraries are included explicitly when building for `no_std` platforms. In some cases, the tests had to explicitly import the `span!` and `event!` macros at every use, because their names conflict with the `span` and `event` modules in the test support code. Oh well. Signed-off-by: Eliza Weisman --- tracing-core/src/callsite.rs | 2 +- tracing-core/src/lib.rs | 9 +- tracing-core/src/subscriber.rs | 3 +- tracing-serde/README.md | 4 - tracing/benches/subscriber.rs | 3 - tracing/src/level_filters.rs | 2 +- tracing/src/lib.rs | 3 - tracing/test-log-support/src/lib.rs | 1 - .../test-log-support/tests/log_no_trace.rs | 6 +- .../test-log-support/tests/log_with_trace.rs | 6 +- .../span_activity_filtered_separately.rs | 6 +- .../tests/span_lifecycle_can_be_enabled.rs | 6 +- .../tests/span_lifecycle_defaults_off.rs | 6 +- .../tests/span_lifecycle_is_trace.rs | 6 +- .../tests/test.rs | 5 +- tracing/tests/event.rs | 27 ++--- .../filter_caching_is_lexically_scoped.rs | 4 +- ...s_are_not_reevaluated_for_the_same_span.rs | 5 +- ...re_reevaluated_for_different_call_sites.rs | 4 +- tracing/tests/macros.rs | 7 +- tracing/tests/span.rs | 111 +++++++++--------- tracing/tests/subscriber.rs | 13 +- 22 files changed, 93 insertions(+), 146 deletions(-) diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index e840c58595..d0acae41de 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -12,7 +12,7 @@ use crate::{ subscriber::Interest, }; -lazy_static! { +crate::lazy_static! { static ref REGISTRY: Mutex = Mutex::new(Registry { callsites: Vec::new(), dispatchers: Vec::new(), diff --git a/tracing-core/src/lib.rs b/tracing-core/src/lib.rs index 14d0f0854e..5c5a31d3d1 100644 --- a/tracing-core/src/lib.rs +++ b/tracing-core/src/lib.rs @@ -225,14 +225,11 @@ macro_rules! metadata { }; } -// std uses lazy_static from crates.io +// when `std` is enabled, use the `lazy_static` crate from crates.io #[cfg(feature = "std")] -#[macro_use] -extern crate lazy_static; +pub(crate) use lazy_static::lazy_static; -// no_std uses vendored version of lazy_static 1.4.0 (4216696) with spin -// This can conflict when included in a project already using std lazy_static -// Remove this module when cargo enables specifying dependencies for no_std +// Facade module: `no_std` uses spinlocks, `std` uses the mutexes in the standard library #[cfg(not(feature = "std"))] #[macro_use] mod lazy_static; diff --git a/tracing-core/src/subscriber.rs b/tracing-core/src/subscriber.rs index 212e876062..11695e5382 100644 --- a/tracing-core/src/subscriber.rs +++ b/tracing-core/src/subscriber.rs @@ -246,8 +246,7 @@ pub trait Subscriber: 'static { /// but values for them won't be recorded at this time. /// /// ```rust,ignore - /// #[macro_use] - /// extern crate tracing; + /// # use tracing::span; /// /// let mut span = span!("my_span", foo = 3, bar, baz); /// diff --git a/tracing-serde/README.md b/tracing-serde/README.md index 5282199e29..09cda49a80 100644 --- a/tracing-serde/README.md +++ b/tracing-serde/README.md @@ -53,10 +53,6 @@ tracing-serde = "0.1" Next, add this to your crate: ```rust -#[macro_use] -extern crate tracing; -extern crate tracing_serde; - use tracing_serde::AsSerde; ``` diff --git a/tracing/benches/subscriber.rs b/tracing/benches/subscriber.rs index 0595d64222..c6418010f4 100644 --- a/tracing/benches/subscriber.rs +++ b/tracing/benches/subscriber.rs @@ -1,6 +1,3 @@ -extern crate criterion; -extern crate tracing; - use criterion::{black_box, criterion_group, criterion_main, Criterion}; use tracing::Level; diff --git a/tracing/src/level_filters.rs b/tracing/src/level_filters.rs index cfacee2efe..6052a1a65e 100644 --- a/tracing/src/level_filters.rs +++ b/tracing/src/level_filters.rs @@ -65,7 +65,7 @@ pub use tracing_core::{metadata::ParseLevelFilterError, LevelFilter}; /// [module-level documentation]: ../index.html#compile-time-filters pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL; -cfg_if! { +cfg_if::cfg_if! { if #[cfg(all(not(debug_assertions), feature = "release_max_level_off"))] { const MAX_LEVEL: LevelFilter = LevelFilter::OFF; } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_error"))] { diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index 5f96fc3576..c6e6fbe8fc 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -882,9 +882,6 @@ #[cfg(not(feature = "std"))] extern crate alloc; -#[macro_use] -extern crate cfg_if; - #[cfg(feature = "log")] #[doc(hidden)] pub use log; diff --git a/tracing/test-log-support/src/lib.rs b/tracing/test-log-support/src/lib.rs index 7e76428892..e63257445f 100644 --- a/tracing/test-log-support/src/lib.rs +++ b/tracing/test-log-support/src/lib.rs @@ -1,4 +1,3 @@ -extern crate log; use log::{LevelFilter, Log, Metadata, Record}; use std::sync::{Arc, Mutex}; diff --git a/tracing/test-log-support/tests/log_no_trace.rs b/tracing/test-log-support/tests/log_no_trace.rs index 2e71896e08..206e9b577c 100644 --- a/tracing/test-log-support/tests/log_no_trace.rs +++ b/tracing/test-log-support/tests/log_no_trace.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate tracing; -extern crate test_log_support; - use test_log_support::Test; -use tracing::Level; +use tracing::{error, info, span, trace, warn, Level}; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/test-log-support/tests/log_with_trace.rs b/tracing/test-log-support/tests/log_with_trace.rs index d2d5b2cf81..c32cb79e93 100644 --- a/tracing/test-log-support/tests/log_with_trace.rs +++ b/tracing/test-log-support/tests/log_with_trace.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate tracing; -extern crate test_log_support; - use test_log_support::Test; -use tracing::Level; +use tracing::{error, info, span, trace, warn, Level}; pub struct NopSubscriber; diff --git a/tracing/test-log-support/tests/span_activity_filtered_separately.rs b/tracing/test-log-support/tests/span_activity_filtered_separately.rs index 3f28822c40..32bc00d96a 100644 --- a/tracing/test-log-support/tests/span_activity_filtered_separately.rs +++ b/tracing/test-log-support/tests/span_activity_filtered_separately.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate tracing; -extern crate test_log_support; - use test_log_support::Test; -use tracing::Level; +use tracing::{error, info, span, trace, warn, Level}; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/test-log-support/tests/span_lifecycle_can_be_enabled.rs b/tracing/test-log-support/tests/span_lifecycle_can_be_enabled.rs index ee099c0966..8ff515f9fe 100644 --- a/tracing/test-log-support/tests/span_lifecycle_can_be_enabled.rs +++ b/tracing/test-log-support/tests/span_lifecycle_can_be_enabled.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate tracing; -extern crate test_log_support; - use test_log_support::Test; -use tracing::Level; +use tracing::{error, info, span, trace, warn, Level}; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/test-log-support/tests/span_lifecycle_defaults_off.rs b/tracing/test-log-support/tests/span_lifecycle_defaults_off.rs index a966569cbb..ab1cb24ffa 100644 --- a/tracing/test-log-support/tests/span_lifecycle_defaults_off.rs +++ b/tracing/test-log-support/tests/span_lifecycle_defaults_off.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate tracing; -extern crate test_log_support; - use test_log_support::Test; -use tracing::Level; +use tracing::{error, info, span, trace, warn, Level}; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/test-log-support/tests/span_lifecycle_is_trace.rs b/tracing/test-log-support/tests/span_lifecycle_is_trace.rs index 62ac7194a6..b94560cfa4 100644 --- a/tracing/test-log-support/tests/span_lifecycle_is_trace.rs +++ b/tracing/test-log-support/tests/span_lifecycle_is_trace.rs @@ -1,9 +1,5 @@ -#[macro_use] -extern crate tracing; -extern crate test_log_support; - use test_log_support::Test; -use tracing::Level; +use tracing::{error, info, span, trace, warn, Level}; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/test_static_max_level_features/tests/test.rs b/tracing/test_static_max_level_features/tests/test.rs index 419dd28ef0..6bbbc16ce5 100644 --- a/tracing/test_static_max_level_features/tests/test.rs +++ b/tracing/test_static_max_level_features/tests/test.rs @@ -1,9 +1,6 @@ -#[macro_use] -extern crate tracing; - use std::sync::{Arc, Mutex}; use tracing::span::{Attributes, Record}; -use tracing::{span, Event, Id, Level, Metadata, Subscriber}; +use tracing::{debug, error, info, span, trace, warn, Collect, Event, Id, Level, Metadata}; struct State { last_level: Mutex>, diff --git a/tracing/tests/event.rs b/tracing/tests/event.rs index 4b30032dbe..93f9c07f28 100644 --- a/tracing/tests/event.rs +++ b/tracing/tests/event.rs @@ -5,17 +5,16 @@ // The alternative would be for each of these tests to be defined in a separate // file, which is :( #![cfg(feature = "std")] - -#[macro_use] -extern crate tracing; mod support; use self::support::*; use tracing::{ + debug, error, field::{debug, display}, + info, subscriber::with_default, - Level, + trace, warn, Level, }; macro_rules! event_without_message { @@ -150,7 +149,7 @@ fn one_with_everything() { .run_with_handle(); with_default(subscriber, || { - event!( + tracing::event!( target: "whatever", Level::ERROR, { foo = 666, bar = false, like_a_butterfly = 42.0 }, @@ -176,7 +175,7 @@ fn moved_field() { .run_with_handle(); with_default(subscriber, || { let from = "my event"; - event!(Level::INFO, foo = display(format!("hello from {}", from))) + tracing::event!(Level::INFO, foo = display(format!("hello from {}", from))) }); handle.assert_finished(); @@ -197,7 +196,7 @@ fn dotted_field_name() { .done() .run_with_handle(); with_default(subscriber, || { - event!(Level::INFO, foo.bar = true, foo.baz = false); + tracing::event!(Level::INFO, foo.bar = true, foo.baz = false); }); handle.assert_finished(); @@ -219,7 +218,7 @@ fn borrowed_field() { with_default(subscriber, || { let from = "my event"; let mut message = format!("hello from {}", from); - event!(Level::INFO, foo = display(&message)); + tracing::event!(Level::INFO, foo = display(&message)); message.push_str(", which happened!"); }); @@ -281,7 +280,7 @@ fn display_shorthand() { .done() .run_with_handle(); with_default(subscriber, || { - event!(Level::TRACE, my_field = %"hello world"); + tracing::event!(Level::TRACE, my_field = %"hello world"); }); handle.assert_finished(); @@ -301,7 +300,7 @@ fn debug_shorthand() { .done() .run_with_handle(); with_default(subscriber, || { - event!(Level::TRACE, my_field = ?"hello world"); + tracing::event!(Level::TRACE, my_field = ?"hello world"); }); handle.assert_finished(); @@ -322,7 +321,7 @@ fn both_shorthands() { .done() .run_with_handle(); with_default(subscriber, || { - event!(Level::TRACE, display_field = %"hello world", debug_field = ?"hello world"); + tracing::event!(Level::TRACE, display_field = %"hello world", debug_field = ?"hello world"); }); handle.assert_finished(); @@ -338,8 +337,8 @@ fn explicit_child() { .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); - event!(parent: foo.id(), Level::TRACE, "bar"); + let foo = tracing::span!(Level::TRACE, "foo"); + tracing::event!(parent: foo.id(), Level::TRACE, "bar"); }); handle.assert_finished(); @@ -359,7 +358,7 @@ fn explicit_child_at_levels() { .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); + let foo = tracing::span!(Level::TRACE, "foo"); trace!(parent: foo.id(), "a"); debug!(parent: foo.id(), "b"); info!(parent: foo.id(), "c"); diff --git a/tracing/tests/filter_caching_is_lexically_scoped.rs b/tracing/tests/filter_caching_is_lexically_scoped.rs index 9b997a0c6b..27096cb3c9 100644 --- a/tracing/tests/filter_caching_is_lexically_scoped.rs +++ b/tracing/tests/filter_caching_is_lexically_scoped.rs @@ -7,12 +7,10 @@ #[cfg(not(feature = "std"))] extern crate std; -#[macro_use] -extern crate tracing; mod support; use self::support::*; -use tracing::Level; +use tracing::{span, Level}; use std::sync::{ atomic::{AtomicUsize, Ordering}, diff --git a/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs b/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs index 53e11ef448..9d2ef6e0b7 100644 --- a/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs +++ b/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs @@ -5,13 +5,10 @@ // threads with shared global state lets them interfere with each other #[cfg(not(feature = "std"))] extern crate std; - -#[macro_use] -extern crate tracing; mod support; use self::support::*; -use tracing::Level; +use tracing::{span, Level}; use std::sync::{ atomic::{AtomicUsize, Ordering}, diff --git a/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs b/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs index 5675e4e678..432848c87a 100644 --- a/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs +++ b/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs @@ -6,12 +6,10 @@ #[cfg(not(feature = "std"))] extern crate std; -#[macro_use] -extern crate tracing; +use tracing::{span, Level}; mod support; use self::support::*; -use tracing::Level; use std::sync::{ atomic::{AtomicUsize, Ordering}, diff --git a/tracing/tests/macros.rs b/tracing/tests/macros.rs index 445d17aa43..420319d373 100644 --- a/tracing/tests/macros.rs +++ b/tracing/tests/macros.rs @@ -1,8 +1,9 @@ #![deny(warnings)] -use tracing::Level; +use tracing::{ + callsite, debug, debug_span, error, error_span, event, info, info_span, span, trace, + trace_span, warn, warn_span, Level, +}; -#[macro_use] -extern crate tracing; // Tests that macros work across various invocation syntax. // // These are quite repetitive, and _could_ be generated by a macro. However, diff --git a/tracing/tests/span.rs b/tracing/tests/span.rs index c784a96069..4f6a642bdb 100644 --- a/tracing/tests/span.rs +++ b/tracing/tests/span.rs @@ -3,8 +3,6 @@ // with the standard lib disabled. #![cfg(feature = "std")] -#[macro_use] -extern crate tracing; mod support; use self::support::*; @@ -23,7 +21,7 @@ fn handles_to_the_same_span_are_equal() { // won't enter any spans in this test, so the subscriber won't actually // expect to see any spans. with_default(subscriber::mock().run(), || { - let foo1 = span!(Level::TRACE, "foo"); + let foo1 = tracing::span!(Level::TRACE, "foo"); let foo2 = foo1.clone(); // Two handles that point to the same span are equal. assert_eq!(foo1, foo2); @@ -36,8 +34,8 @@ fn handles_to_different_spans_are_not_equal() { with_default(subscriber::mock().run(), || { // Even though these spans have the same name and fields, they will have // differing metadata, since they were created on different lines. - let foo1 = span!(Level::TRACE, "foo", bar = 1u64, baz = false); - let foo2 = span!(Level::TRACE, "foo", bar = 1u64, baz = false); + let foo1 = tracing::span!(Level::TRACE, "foo", bar = 1u64, baz = false); + let foo2 = tracing::span!(Level::TRACE, "foo", bar = 1u64, baz = false); assert_ne!(foo1, foo2); }); @@ -49,7 +47,7 @@ fn handles_to_different_spans_with_the_same_metadata_are_not_equal() { // Every time time this function is called, it will return a _new // instance_ of a span with the same metadata, name, and fields. fn make_span() -> Span { - span!(Level::TRACE, "foo", bar = 1u64, baz = false) + tracing::span!(Level::TRACE, "foo", bar = 1u64, baz = false) } with_default(subscriber::mock().run(), || { @@ -75,7 +73,7 @@ fn spans_always_go_to_the_subscriber_that_tagged_them() { let subscriber2 = subscriber::mock().run(); let foo = with_default(subscriber1, || { - let foo = span!(Level::TRACE, "foo"); + let foo = tracing::span!(Level::TRACE, "foo"); foo.in_scope(|| {}); foo }); @@ -100,7 +98,7 @@ fn spans_always_go_to_the_subscriber_that_tagged_them_even_across_threads() { .done() .run(); let foo = with_default(subscriber1, || { - let foo = span!(Level::TRACE, "foo"); + let foo = tracing::span!(Level::TRACE, "foo"); foo.in_scope(|| {}); foo }); @@ -126,7 +124,7 @@ fn dropping_a_span_calls_drop_span() { .done() .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo"); + let span = tracing::span!(Level::TRACE, "foo"); span.in_scope(|| {}); drop(span); }); @@ -145,8 +143,8 @@ fn span_closes_after_event() { .done() .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "foo").in_scope(|| { - event!(Level::DEBUG, {}, "my event!"); + tracing::span!(Level::TRACE, "foo").in_scope(|| { + tracing::event!(Level::DEBUG, {}, "my tracing::event!"); }); }); @@ -167,10 +165,10 @@ fn new_span_after_event() { .done() .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "foo").in_scope(|| { - event!(Level::DEBUG, {}, "my event!"); + tracing::span!(Level::TRACE, "foo").in_scope(|| { + tracing::event!(Level::DEBUG, {}, "my tracing::event!"); }); - span!(Level::TRACE, "bar").in_scope(|| {}); + tracing::span!(Level::TRACE, "bar").in_scope(|| {}); }); handle.assert_finished(); @@ -187,8 +185,8 @@ fn event_outside_of_span() { .done() .run_with_handle(); with_default(subscriber, || { - debug!("my event!"); - span!(Level::TRACE, "foo").in_scope(|| {}); + tracing::debug!("my tracing::event!"); + tracing::span!(Level::TRACE, "foo").in_scope(|| {}); }); handle.assert_finished(); @@ -201,7 +199,7 @@ fn cloning_a_span_calls_clone_span() { .clone_span(span::mock().named("foo")) .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo"); + let span = tracing::span!(Level::TRACE, "foo"); // Allow the "redundant" `.clone` since it is used to call into the `.clone_span` hook. #[allow(clippy::redundant_clone)] let _span2 = span.clone(); @@ -219,7 +217,7 @@ fn drop_span_when_exiting_dispatchers_context() { .drop_span(span::mock().named("foo")) .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo"); + let span = tracing::span!(Level::TRACE, "foo"); let _span2 = span.clone(); drop(span); }); @@ -242,7 +240,7 @@ fn clone_and_drop_span_always_go_to_the_subscriber_that_tagged_the_span() { let subscriber2 = subscriber::mock().done().run(); let foo = with_default(subscriber1, || { - let foo = span!(Level::TRACE, "foo"); + let foo = tracing::span!(Level::TRACE, "foo"); foo.in_scope(|| {}); foo }); @@ -268,7 +266,7 @@ fn span_closes_when_exited() { .done() .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); + let foo = tracing::span!(Level::TRACE, "foo"); foo.in_scope(|| {}); @@ -289,9 +287,9 @@ fn enter() { .done() .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); + let foo = tracing::span!(Level::TRACE, "foo"); let _enter = foo.enter(); - debug!("dropping guard..."); + tracing::debug!("dropping guard..."); }); handle.assert_finished(); @@ -308,8 +306,8 @@ fn entered() { .done() .run_with_handle(); with_default(subscriber, || { - let _span = span!(Level::TRACE, "foo").entered(); - debug!("dropping guard..."); + let _span = tracing::span!(Level::TRACE, "foo").entered(); + tracing::debug!("dropping guard..."); }); handle.assert_finished(); @@ -326,9 +324,9 @@ fn entered_api() { .done() .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo").entered(); + let span = tracing::span!(Level::TRACE, "foo").entered(); let _derefs_to_span = span.id(); - debug!("exiting span..."); + tracing::debug!("exiting span..."); let _: Span = span.exit(); }); @@ -353,7 +351,7 @@ fn moved_field() { .run_with_handle(); with_default(subscriber, || { let from = "my span"; - let span = span!( + let span = tracing::span!( Level::TRACE, "foo", bar = display(format!("hello from {}", from)) @@ -376,7 +374,7 @@ fn dotted_field_name() { .done() .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "foo", fields.bar = true); + tracing::span!(Level::TRACE, "foo", fields.bar = true); }); handle.assert_finished(); @@ -402,7 +400,7 @@ fn borrowed_field() { with_default(subscriber, || { let from = "my span"; let mut message = format!("hello from {}", from); - let span = span!(Level::TRACE, "foo", bar = display(&message)); + let span = tracing::span!(Level::TRACE, "foo", bar = display(&message)); span.in_scope(|| { message.insert_str(10, " inside"); }); @@ -449,8 +447,8 @@ fn move_field_out_of_struct() { x: 3.234, y: -1.223, }; - let foo = span!(Level::TRACE, "foo", x = debug(pos.x), y = debug(pos.y)); - let bar = span!(Level::TRACE, "bar", position = debug(pos)); + let foo = tracing::span!(Level::TRACE, "foo", x = debug(pos.x), y = debug(pos.y)); + let bar = tracing::span!(Level::TRACE, "bar", position = debug(pos)); foo.in_scope(|| {}); bar.in_scope(|| {}); }); @@ -473,7 +471,7 @@ fn float_values() { .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo", x = 3.234, y = -1.223); + let foo = tracing::span!(Level::TRACE, "foo", x = 3.234, y = -1.223); foo.in_scope(|| {}); }); @@ -504,7 +502,7 @@ fn add_field_after_new_span() { .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo", bar = 5, baz = false); + let span = tracing::span!(Level::TRACE, "foo", bar = 5, baz = false); span.record("baz", &true); span.in_scope(|| {}) }); @@ -532,7 +530,7 @@ fn add_fields_only_after_new_span() { .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo", bar = _, baz = _); + let span = tracing::span!(Level::TRACE, "foo", bar = _, baz = _); span.record("bar", &5); span.record("baz", &true); span.in_scope(|| {}) @@ -565,7 +563,7 @@ fn record_new_value_for_field() { .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo", bar = 5, baz = false); + let span = tracing::span!(Level::TRACE, "foo", bar = 5, baz = false); span.record("baz", &true); span.in_scope(|| {}) }); @@ -600,7 +598,7 @@ fn record_new_values_for_fields() { .run_with_handle(); with_default(subscriber, || { - let span = span!(Level::TRACE, "foo", bar = 4, baz = false); + let span = tracing::span!(Level::TRACE, "foo", bar = 4, baz = false); span.record("bar", &5); span.record("baz", &true); span.in_scope(|| {}) @@ -623,7 +621,7 @@ fn new_span_with_target_and_log_level() { .run_with_handle(); with_default(subscriber, || { - span!(target: "app_span", Level::DEBUG, "foo"); + tracing::span!(target: "app_span", Level::DEBUG, "foo"); }); handle.assert_finished(); @@ -638,7 +636,7 @@ fn explicit_root_span_is_root() { .run_with_handle(); with_default(subscriber, || { - span!(parent: None, Level::TRACE, "foo"); + tracing::span!(parent: None, Level::TRACE, "foo"); }); handle.assert_finished(); @@ -656,8 +654,8 @@ fn explicit_root_span_is_root_regardless_of_ctx() { .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "foo").in_scope(|| { - span!(parent: None, Level::TRACE, "bar"); + tracing::span!(Level::TRACE, "foo").in_scope(|| { + tracing::span!(parent: None, Level::TRACE, "bar"); }) }); @@ -674,8 +672,8 @@ fn explicit_child() { .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); - span!(parent: foo.id(), Level::TRACE, "bar"); + let foo = tracing::span!(Level::TRACE, "foo"); + tracing::span!(parent: foo.id(), Level::TRACE, "bar"); }); handle.assert_finished(); @@ -695,12 +693,12 @@ fn explicit_child_at_levels() { .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); - trace_span!(parent: foo.id(), "a"); - debug_span!(parent: foo.id(), "b"); - info_span!(parent: foo.id(), "c"); - warn_span!(parent: foo.id(), "d"); - error_span!(parent: foo.id(), "e"); + let foo = tracing::span!(Level::TRACE, "foo"); + tracing::trace_span!(parent: foo.id(), "a"); + tracing::debug_span!(parent: foo.id(), "b"); + tracing::info_span!(parent: foo.id(), "c"); + tracing::warn_span!(parent: foo.id(), "d"); + tracing::error_span!(parent: foo.id(), "e"); }); handle.assert_finished(); @@ -719,8 +717,9 @@ fn explicit_child_regardless_of_ctx() { .run_with_handle(); with_default(subscriber, || { - let foo = span!(Level::TRACE, "foo"); - span!(Level::TRACE, "bar").in_scope(|| span!(parent: foo.id(), Level::TRACE, "baz")) + let foo = tracing::span!(Level::TRACE, "foo"); + tracing::span!(Level::TRACE, "bar") + .in_scope(|| tracing::span!(parent: foo.id(), Level::TRACE, "baz")) }); handle.assert_finished(); @@ -735,7 +734,7 @@ fn contextual_root() { .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "foo"); + tracing::span!(Level::TRACE, "foo"); }); handle.assert_finished(); @@ -757,8 +756,8 @@ fn contextual_child() { .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "foo").in_scope(|| { - span!(Level::TRACE, "bar"); + tracing::span!(Level::TRACE, "foo").in_scope(|| { + tracing::span!(Level::TRACE, "bar"); }) }); @@ -779,7 +778,7 @@ fn display_shorthand() { .done() .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "my_span", my_field = %"hello world"); + tracing::span!(Level::TRACE, "my_span", my_field = %"hello world"); }); handle.assert_finished(); @@ -799,7 +798,7 @@ fn debug_shorthand() { .done() .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "my_span", my_field = ?"hello world"); + tracing::span!(Level::TRACE, "my_span", my_field = ?"hello world"); }); handle.assert_finished(); @@ -820,7 +819,7 @@ fn both_shorthands() { .done() .run_with_handle(); with_default(subscriber, || { - span!(Level::TRACE, "my_span", display_field = %"hello world", debug_field = ?"hello world"); + tracing::span!(Level::TRACE, "my_span", display_field = %"hello world", debug_field = ?"hello world"); }); handle.assert_finished(); diff --git a/tracing/tests/subscriber.rs b/tracing/tests/subscriber.rs index 26e88c1a4c..6da764bea0 100644 --- a/tracing/tests/subscriber.rs +++ b/tracing/tests/subscriber.rs @@ -5,9 +5,6 @@ // The alternative would be for each of these tests to be defined in a separate // file, which is :( #![cfg(feature = "std")] - -#[macro_use] -extern crate tracing; use tracing::{ field::display, span::{Attributes, Id, Record}, @@ -34,7 +31,7 @@ fn event_macros_dont_infinite_loop() { fn enabled(&self, meta: &Metadata<'_>) -> bool { assert!(meta.fields().iter().any(|f| f.name() == "foo")); - event!(Level::TRACE, bar = false); + tracing::event!(Level::TRACE, bar = false); true } @@ -48,7 +45,7 @@ fn event_macros_dont_infinite_loop() { fn event(&self, event: &Event<'_>) { assert!(event.metadata().fields().iter().any(|f| f.name() == "foo")); - event!(Level::TRACE, baz = false); + tracing::event!(Level::TRACE, baz = false); } fn enter(&self, _: &Id) {} @@ -57,7 +54,7 @@ fn event_macros_dont_infinite_loop() { } with_default(TestSubscriber, || { - event!(Level::TRACE, foo = false); + tracing::event!(Level::TRACE, foo = false); }) } @@ -81,7 +78,7 @@ fn boxed_subscriber() { with_default(subscriber, || { let from = "my span"; - let span = span!( + let span = tracing::span!( Level::TRACE, "foo", bar = format_args!("hello from {}", from) @@ -119,7 +116,7 @@ fn arced_subscriber() { // Test using a clone of the `Arc`ed subscriber with_default(subscriber.clone(), || { let from = "my span"; - let span = span!( + let span = tracing::span!( Level::TRACE, "foo", bar = format_args!("hello from {}", from)