Skip to content

Commit

Permalink
chore: remove *all* extern crate statements (#1738)
Browse files Browse the repository at this point in the history
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 <eliza@buoyant.io>
  • Loading branch information
hawkw committed Dec 19, 2021
1 parent f186c2e commit fefe583
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 146 deletions.
2 changes: 1 addition & 1 deletion tracing-core/src/callsite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
subscriber::Interest,
};

lazy_static! {
crate::lazy_static! {
static ref REGISTRY: Mutex<Registry> = Mutex::new(Registry {
callsites: Vec::new(),
dispatchers: Vec::new(),
Expand Down
9 changes: 3 additions & 6 deletions tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
///
Expand Down
4 changes: 0 additions & 4 deletions tracing-serde/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```

Expand Down
3 changes: 0 additions & 3 deletions tracing/benches/subscriber.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate criterion;
extern crate tracing;

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tracing::Level;

Expand Down
2 changes: 1 addition & 1 deletion tracing/src/level_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))] {
Expand Down
3 changes: 0 additions & 3 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tracing/test-log-support/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate log;
use log::{LevelFilter, Log, Metadata, Record};
use std::sync::{Arc, Mutex};

Expand Down
6 changes: 1 addition & 5 deletions tracing/test-log-support/tests/log_no_trace.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
6 changes: 1 addition & 5 deletions tracing/test-log-support/tests/log_with_trace.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
6 changes: 1 addition & 5 deletions tracing/test-log-support/tests/span_lifecycle_is_trace.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 1 addition & 4 deletions tracing/test_static_max_level_features/tests/test.rs
Original file line number Diff line number Diff line change
@@ -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<Option<Level>>,
Expand Down
27 changes: 13 additions & 14 deletions tracing/tests/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 },
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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!");
});

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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");
Expand Down
4 changes: 1 addition & 3 deletions tracing/tests/filter_caching_is_lexically_scoped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
7 changes: 4 additions & 3 deletions tracing/tests/macros.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading

0 comments on commit fefe583

Please sign in to comment.