Skip to content

Commit e05d1c8

Browse files
authored
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 7d80af7 commit e05d1c8

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

tracing-core/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ extern crate alloc;
173173
///
174174
/// For example:
175175
/// ```rust
176-
/// # #[macro_use]
177-
/// # extern crate tracing_core;
178-
/// use tracing_core::callsite;
176+
/// use tracing_core::{callsite, identify_callsite};
179177
/// # use tracing_core::{Metadata, collect::Interest};
180178
/// # fn main() {
181179
/// pub struct MyCallsite {
@@ -209,9 +207,8 @@ macro_rules! identify_callsite {
209207
///
210208
/// /// For example:
211209
/// ```rust
212-
/// # #[macro_use]
213-
/// # extern crate tracing_core;
214210
/// # use tracing_core::{callsite::Callsite, collect::Interest};
211+
/// use tracing_core::metadata;
215212
/// use tracing_core::metadata::{Kind, Level, Metadata};
216213
/// # fn main() {
217214
/// # pub struct MyCallsite { }

tracing/src/macros.rs

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

tracing/src/span.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
//! The `enter` method enters a span, returning a [guard] that exits the span
6363
//! when dropped
6464
//! ```
65-
//! # #[macro_use] extern crate tracing;
66-
//! # use tracing::Level;
65+
//! # use tracing::{Level, span};
6766
//! let my_var: u64 = 5;
6867
//! let my_span = span!(Level::TRACE, "my_span", my_var);
6968
//!
@@ -88,8 +87,7 @@
8887
//! `in_scope` takes a closure or function pointer and executes it inside the
8988
//! span.
9089
//! ```
91-
//! # #[macro_use] extern crate tracing;
92-
//! # use tracing::Level;
90+
//! # use tracing::{Level, span};
9391
//! let my_var: u64 = 5;
9492
//! let my_span = span!(Level::TRACE, "my_span", my_var = &my_var);
9593
//!
@@ -122,8 +120,7 @@
122120
//! as long as the longest-executing span in its subtree.
123121
//!
124122
//! ```
125-
//! # #[macro_use] extern crate tracing;
126-
//! # use tracing::Level;
123+
//! # use tracing::{Level, span};
127124
//! // this span is considered the "root" of a new trace tree:
128125
//! span!(Level::INFO, "root").in_scope(|| {
129126
//! // since we are now inside "root", this span is considered a child
@@ -143,8 +140,7 @@
143140
//! the `span!` macro. For example:
144141
//!
145142
//! ```rust
146-
//! # #[macro_use] extern crate tracing;
147-
//! # use tracing::Level;
143+
//! # use tracing::{Level, span};
148144
//! // Create, but do not enter, a span called "foo".
149145
//! let foo = span!(Level::INFO, "foo");
150146
//!
@@ -186,8 +182,6 @@
186182
//! _closed_. Consider, for example, a future which has an associated
187183
//! span and enters that span every time it is polled:
188184
//! ```rust
189-
//! # extern crate tracing;
190-
//! # extern crate futures;
191185
//! # use futures::{Future, Poll, Async};
192186
//! struct MyFuture {
193187
//! // data
@@ -227,8 +221,7 @@
227221
//! that handle "closes" the span, since the capacity to enter it no longer
228222
//! exists. For example:
229223
//! ```
230-
//! # #[macro_use] extern crate tracing;
231-
//! # use tracing::Level;
224+
//! # use tracing::{Level, span};
232225
//! {
233226
//! span!(Level::TRACE, "my_span").in_scope(|| {
234227
//! // perform some work in the context of `my_span`...
@@ -261,8 +254,7 @@
261254
//! construct one span and perform the entire loop inside of that span, like:
262255
//!
263256
//! ```rust
264-
//! # #[macro_use] extern crate tracing;
265-
//! # use tracing::Level;
257+
//! # use tracing::{Level, span};
266258
//! # let n = 1;
267259
//! let span = span!(Level::TRACE, "my_loop");
268260
//! let _enter = span.enter();
@@ -273,8 +265,7 @@
273265
//! ```
274266
//! Or, should we create a new span for each iteration of the loop, as in:
275267
//! ```rust
276-
//! # #[macro_use] extern crate tracing;
277-
//! # use tracing::Level;
268+
//! # use tracing::{Level, span};
278269
//! # let n = 1u64;
279270
//! for i in 0..n {
280271
//! let span = span!(Level::TRACE, "my_loop", iteration = i);
@@ -721,8 +712,7 @@ impl Span {
721712
/// # Examples
722713
///
723714
/// ```
724-
/// #[macro_use] extern crate tracing;
725-
/// # use tracing::Level;
715+
/// # use tracing::{span, Level};
726716
/// let span = span!(Level::INFO, "my_span");
727717
/// let guard = span.enter();
728718
///
@@ -737,7 +727,7 @@ impl Span {
737727
/// Guards need not be explicitly dropped:
738728
///
739729
/// ```
740-
/// #[macro_use] extern crate tracing;
730+
/// # use tracing::trace_span;
741731
/// fn my_function() -> String {
742732
/// // enter a span for the duration of this function.
743733
/// let span = trace_span!("my_function");
@@ -759,7 +749,7 @@ impl Span {
759749
/// entered:
760750
///
761751
/// ```
762-
/// #[macro_use] extern crate tracing;
752+
/// # use tracing::{info, info_span};
763753
/// let span = info_span!("my_great_span");
764754
///
765755
/// {
@@ -1073,8 +1063,7 @@ impl Span {
10731063
/// # Examples
10741064
///
10751065
/// ```
1076-
/// # #[macro_use] extern crate tracing;
1077-
/// # use tracing::Level;
1066+
/// # use tracing::{trace, span, Level};
10781067
/// let my_span = span!(Level::TRACE, "my_span");
10791068
///
10801069
/// my_span.in_scope(|| {

0 commit comments

Comments
 (0)