Skip to content

Commit f186c2e

Browse files
committed
docs: remove #[macro_use] extern crate (#1737)
Some of the examples still include `#[macro_use] extern crate` statements for importing macros from `tracing` or `tracing-core`. On a recent nightly, this results in import conflicts with the implicit import of the documented crate in doctests: https://github.com/tokio-rs/tracing/runs/4279736243?check_suite_focus=true This commit removes all the `extern crate` statements from doctests. Our MSRV is new enough that `extern crate` is not required on any of the Rust versions we support. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
1 parent 6ede79c commit f186c2e

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

tracing-core/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ extern crate alloc;
124124
///
125125
/// For example:
126126
/// ```rust
127-
/// # #[macro_use]
128-
/// # extern crate tracing_core;
129-
/// use tracing_core::callsite;
127+
/// use tracing_core::{callsite, identify_callsite};
130128
/// # use tracing_core::{Metadata, subscriber::Interest};
131129
/// # fn main() {
132130
/// pub struct MyCallsite {
@@ -160,9 +158,8 @@ macro_rules! identify_callsite {
160158
///
161159
/// /// For example:
162160
/// ```rust
163-
/// # #[macro_use]
164-
/// # extern crate tracing_core;
165161
/// # use tracing_core::{callsite::Callsite, subscriber::Interest};
162+
/// use tracing_core::metadata;
166163
/// use tracing_core::metadata::{Kind, Level, Metadata};
167164
/// # fn main() {
168165
/// # pub struct MyCallsite { }

tracing/src/macros.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,7 @@ macro_rules! error_span {
575575
// ///
576576
// /// For example, the following does not compile:
577577
// /// ```rust,compile_fail
578-
// /// # #[macro_use]
579-
// /// # extern crate tracing;
580-
// /// # use tracing::Level;
578+
// /// # use tracing::{Level, event};
581579
// /// # fn main() {
582580
// /// event!(Level::INFO, foo = 5, bad_field, bar = "hello")
583581
// /// #}

tracing/src/span.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@
136136
//! as long as the longest-executing span in its subtree.
137137
//!
138138
//! ```
139-
//! # #[macro_use] extern crate tracing;
140-
//! # use tracing::Level;
139+
//! # use tracing::{Level, span};
141140
//! // this span is considered the "root" of a new trace tree:
142141
//! span!(Level::INFO, "root").in_scope(|| {
143142
//! // since we are now inside "root", this span is considered a child
@@ -157,8 +156,7 @@
157156
//! the `span!` macro. For example:
158157
//!
159158
//! ```rust
160-
//! # #[macro_use] extern crate tracing;
161-
//! # use tracing::Level;
159+
//! # use tracing::{Level, span};
162160
//! // Create, but do not enter, a span called "foo".
163161
//! let foo = span!(Level::INFO, "foo");
164162
//!
@@ -200,8 +198,6 @@
200198
//! _closed_. Consider, for example, a future which has an associated
201199
//! span and enters that span every time it is polled:
202200
//! ```rust
203-
//! # extern crate tracing;
204-
//! # extern crate futures;
205201
//! # use futures::{Future, Poll, Async};
206202
//! struct MyFuture {
207203
//! // data
@@ -241,8 +237,7 @@
241237
//! that handle "closes" the span, since the capacity to enter it no longer
242238
//! exists. For example:
243239
//! ```
244-
//! # #[macro_use] extern crate tracing;
245-
//! # use tracing::Level;
240+
//! # use tracing::{Level, span};
246241
//! {
247242
//! span!(Level::TRACE, "my_span").in_scope(|| {
248243
//! // perform some work in the context of `my_span`...
@@ -275,8 +270,7 @@
275270
//! construct one span and perform the entire loop inside of that span, like:
276271
//!
277272
//! ```rust
278-
//! # #[macro_use] extern crate tracing;
279-
//! # use tracing::Level;
273+
//! # use tracing::{Level, span};
280274
//! # let n = 1;
281275
//! let span = span!(Level::TRACE, "my_loop");
282276
//! let _enter = span.enter();
@@ -287,8 +281,7 @@
287281
//! ```
288282
//! Or, should we create a new span for each iteration of the loop, as in:
289283
//! ```rust
290-
//! # #[macro_use] extern crate tracing;
291-
//! # use tracing::Level;
284+
//! # use tracing::{Level, span};
292285
//! # let n = 1u64;
293286
//! for i in 0..n {
294287
//! let span = span!(Level::TRACE, "my_loop", iteration = i);
@@ -722,8 +715,7 @@ impl Span {
722715
/// # Examples
723716
///
724717
/// ```
725-
/// #[macro_use] extern crate tracing;
726-
/// # use tracing::Level;
718+
/// # use tracing::{span, Level};
727719
/// let span = span!(Level::INFO, "my_span");
728720
/// let guard = span.enter();
729721
///
@@ -738,7 +730,7 @@ impl Span {
738730
/// Guards need not be explicitly dropped:
739731
///
740732
/// ```
741-
/// #[macro_use] extern crate tracing;
733+
/// # use tracing::trace_span;
742734
/// fn my_function() -> String {
743735
/// // enter a span for the duration of this function.
744736
/// let span = trace_span!("my_function");
@@ -760,7 +752,7 @@ impl Span {
760752
/// entered:
761753
///
762754
/// ```
763-
/// #[macro_use] extern crate tracing;
755+
/// # use tracing::{info, info_span};
764756
/// let span = info_span!("my_great_span");
765757
///
766758
/// {
@@ -1070,8 +1062,7 @@ impl Span {
10701062
/// # Examples
10711063
///
10721064
/// ```
1073-
/// # #[macro_use] extern crate tracing;
1074-
/// # use tracing::Level;
1065+
/// # use tracing::{trace, span, Level};
10751066
/// let my_span = span!(Level::TRACE, "my_span");
10761067
///
10771068
/// my_span.in_scope(|| {

0 commit comments

Comments
 (0)