Skip to content

Commit

Permalink
docs: remove #[macro_use] extern crate (#1737)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hawkw committed Dec 2, 2021
1 parent 8a38ca5 commit e528e4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
7 changes: 2 additions & 5 deletions tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ extern crate alloc;
///
/// For example:
/// ```rust
/// # #[macro_use]
/// # extern crate tracing_core;
/// use tracing_core::callsite;
/// use tracing_core::{callsite, identify_callsite};
/// # use tracing_core::{Metadata, subscriber::Interest};
/// # fn main() {
/// pub struct MyCallsite {
Expand Down Expand Up @@ -160,9 +158,8 @@ macro_rules! identify_callsite {
///
/// /// For example:
/// ```rust
/// # #[macro_use]
/// # extern crate tracing_core;
/// # use tracing_core::{callsite::Callsite, subscriber::Interest};
/// use tracing_core::metadata;
/// use tracing_core::metadata::{Kind, Level, Metadata};
/// # fn main() {
/// # pub struct MyCallsite { }
Expand Down
4 changes: 1 addition & 3 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,7 @@ macro_rules! error_span {
// ///
// /// For example, the following does not compile:
// /// ```rust,compile_fail
// /// # #[macro_use]
// /// # extern crate tracing;
// /// # use tracing::Level;
// /// # use tracing::{Level, event};
// /// # fn main() {
// /// event!(Level::INFO, foo = 5, bad_field, bar = "hello")
// /// #}
Expand Down
27 changes: 9 additions & 18 deletions tracing/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
//! as long as the longest-executing span in its subtree.
//!
//! ```
//! # #[macro_use] extern crate tracing;
//! # use tracing::Level;
//! # use tracing::{Level, span};
//! // this span is considered the "root" of a new trace tree:
//! span!(Level::INFO, "root").in_scope(|| {
//! // since we are now inside "root", this span is considered a child
Expand All @@ -157,8 +156,7 @@
//! the `span!` macro. For example:
//!
//! ```rust
//! # #[macro_use] extern crate tracing;
//! # use tracing::Level;
//! # use tracing::{Level, span};
//! // Create, but do not enter, a span called "foo".
//! let foo = span!(Level::INFO, "foo");
//!
Expand Down Expand Up @@ -200,8 +198,6 @@
//! _closed_. Consider, for example, a future which has an associated
//! span and enters that span every time it is polled:
//! ```rust
//! # extern crate tracing;
//! # extern crate futures;
//! # use futures::{Future, Poll, Async};
//! struct MyFuture {
//! // data
Expand Down Expand Up @@ -241,8 +237,7 @@
//! that handle "closes" the span, since the capacity to enter it no longer
//! exists. For example:
//! ```
//! # #[macro_use] extern crate tracing;
//! # use tracing::Level;
//! # use tracing::{Level, span};
//! {
//! span!(Level::TRACE, "my_span").in_scope(|| {
//! // perform some work in the context of `my_span`...
Expand Down Expand Up @@ -275,8 +270,7 @@
//! construct one span and perform the entire loop inside of that span, like:
//!
//! ```rust
//! # #[macro_use] extern crate tracing;
//! # use tracing::Level;
//! # use tracing::{Level, span};
//! # let n = 1;
//! let span = span!(Level::TRACE, "my_loop");
//! let _enter = span.enter();
Expand All @@ -287,8 +281,7 @@
//! ```
//! Or, should we create a new span for each iteration of the loop, as in:
//! ```rust
//! # #[macro_use] extern crate tracing;
//! # use tracing::Level;
//! # use tracing::{Level, span};
//! # let n = 1u64;
//! for i in 0..n {
//! let span = span!(Level::TRACE, "my_loop", iteration = i);
Expand Down Expand Up @@ -722,8 +715,7 @@ impl Span {
/// # Examples
///
/// ```
/// #[macro_use] extern crate tracing;
/// # use tracing::Level;
/// # use tracing::{span, Level};
/// let span = span!(Level::INFO, "my_span");
/// let guard = span.enter();
///
Expand All @@ -738,7 +730,7 @@ impl Span {
/// Guards need not be explicitly dropped:
///
/// ```
/// #[macro_use] extern crate tracing;
/// # use tracing::trace_span;
/// fn my_function() -> String {
/// // enter a span for the duration of this function.
/// let span = trace_span!("my_function");
Expand All @@ -760,7 +752,7 @@ impl Span {
/// entered:
///
/// ```
/// #[macro_use] extern crate tracing;
/// # use tracing::{info, info_span};
/// let span = info_span!("my_great_span");
///
/// {
Expand Down Expand Up @@ -1070,8 +1062,7 @@ impl Span {
/// # Examples
///
/// ```
/// # #[macro_use] extern crate tracing;
/// # use tracing::Level;
/// # use tracing::{trace, span, Level};
/// let my_span = span!(Level::TRACE, "my_span");
///
/// my_span.in_scope(|| {
Expand Down

0 comments on commit e528e4a

Please sign in to comment.