Skip to content

Commit c297a37

Browse files
committed
tracing-subscriber: Switch to unconditional no_std
1 parent 8738590 commit c297a37

File tree

22 files changed

+108
-64
lines changed

22 files changed

+108
-64
lines changed

tracing-subscriber/src/filter/directive.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::filter::level::{self, LevelFilter};
2-
#[cfg(not(feature = "smallvec"))]
3-
use alloc::vec;
4-
#[cfg(not(feature = "std"))]
2+
#[cfg(feature = "std")]
3+
use alloc::boxed::Box;
54
use alloc::{string::String, vec::Vec};
65

76
use core::{cmp::Ordering, fmt, iter::FromIterator, slice, str::FromStr};
@@ -126,7 +125,7 @@ impl<T> IntoIterator for DirectiveSet<T> {
126125
#[cfg(feature = "smallvec")]
127126
type IntoIter = smallvec::IntoIter<[T; 8]>;
128127
#[cfg(not(feature = "smallvec"))]
129-
type IntoIter = vec::IntoIter<T>;
128+
type IntoIter = alloc::vec::IntoIter<T>;
130129

131130
fn into_iter(self) -> Self::IntoIter {
132131
self.directives.into_iter()

tracing-subscriber/src/filter/env/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use super::{
33
EnvFilter, FromEnvError,
44
};
55
use crate::sync::RwLock;
6-
use std::env;
6+
use alloc::{
7+
format,
8+
string::{String, ToString},
9+
vec::Vec,
10+
};
11+
use std::{env, eprintln};
712
use thread_local::ThreadLocal;
813
use tracing::level_filters::STATIC_MAX_LEVEL;
914

tracing-subscriber/src/filter/env/directive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::filter::{
44
env::{field, FieldMap},
55
level::LevelFilter,
66
};
7+
use alloc::{borrow::ToOwned, string::String, vec::Vec};
78
use std::{cmp::Ordering, fmt, iter::FromIterator, str::FromStr};
89
use tracing_core::{span, Level, Metadata};
910

@@ -481,6 +482,7 @@ impl SpanMatcher {
481482
#[cfg(test)]
482483
mod test {
483484
use super::*;
485+
use alloc::{format, string::ToString, vec};
484486

485487
fn parse_directives(dirs: impl AsRef<str>) -> Vec<Directive> {
486488
dirs.as_ref()

tracing-subscriber/src/filter/env/field.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
use matchers::Pattern;
2-
use std::{
1+
use alloc::{
2+
borrow::ToOwned,
3+
boxed::Box,
4+
string::{String, ToString},
5+
sync::Arc,
6+
};
7+
use core::{
38
cmp::Ordering,
4-
error::Error,
59
fmt::{self, Write},
610
str::FromStr,
7-
sync::{
8-
atomic::{AtomicBool, Ordering::*},
9-
Arc,
10-
},
11+
sync::atomic::{AtomicBool, Ordering::*},
1112
};
13+
use matchers::Pattern;
14+
use std::error::Error;
1215

1316
use super::{FieldMap, LevelFilter};
1417
use tracing_core::field::{Field, Visit};
@@ -507,9 +510,7 @@ impl Visit for MatchVisitor<'_> {
507510
Some((ValueMatch::NaN, ref matched)) if value.is_nan() => {
508511
matched.store(true, Release);
509512
}
510-
Some((ValueMatch::F64(ref e), ref matched))
511-
if (value - *e).abs() < f64::EPSILON =>
512-
{
513+
Some((ValueMatch::F64(ref e), ref matched)) if (value - *e).abs() < f64::EPSILON => {
513514
matched.store(true, Release);
514515
}
515516
_ => {}
@@ -576,6 +577,8 @@ impl Visit for MatchVisitor<'_> {
576577
#[cfg(test)]
577578
mod tests {
578579
use super::*;
580+
use alloc::format;
581+
579582
#[derive(Debug)]
580583
#[allow(dead_code)]
581584
struct MyStruct {

tracing-subscriber/src/filter/env/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ use crate::{
1414
layer::{Context, Layer},
1515
sync::RwLock,
1616
};
17+
use alloc::{fmt, str::FromStr, vec::Vec};
18+
use core::cell::RefCell;
1719
use directive::ParseError;
18-
use std::{cell::RefCell, collections::HashMap, env, error::Error, fmt, str::FromStr};
20+
use std::{collections::HashMap, env, error::Error};
1921
use thread_local::ThreadLocal;
2022
use tracing_core::{
2123
callsite,
@@ -835,6 +837,8 @@ impl Error for FromEnvError {
835837
#[cfg(test)]
836838
mod tests {
837839
use super::*;
840+
use alloc::format;
841+
use std::println;
838842
use tracing_core::field::FieldSet;
839843
use tracing_core::*;
840844

tracing-subscriber/src/filter/layer_filters/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ use crate::{
3232
layer::{self, Context, Layer},
3333
registry,
3434
};
35-
use std::{
35+
use alloc::{boxed::Box, fmt, sync::Arc};
36+
use core::{
3637
any::TypeId,
3738
cell::{Cell, RefCell},
38-
fmt,
3939
marker::PhantomData,
4040
ops::Deref,
41-
sync::Arc,
42-
thread_local,
4341
};
42+
use std::thread_local;
4443
use tracing_core::{
4544
span,
4645
subscriber::{Interest, Subscriber},

tracing-subscriber/src/filter/targets.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::{
1313
},
1414
layer,
1515
};
16-
#[cfg(not(feature = "std"))]
1716
use alloc::string::String;
1817
use core::{
1918
fmt,
@@ -596,16 +595,17 @@ impl<'a> Iterator for Iter<'a> {
596595
#[cfg(test)]
597596
mod tests {
598597
use super::*;
598+
use alloc::{string::ToString, vec, vec::Vec};
599+
#[cfg(feature = "std")]
600+
use std::dbg;
599601

600-
feature! {
601-
#![not(feature = "std")]
602-
use alloc::{vec, vec::Vec, string::ToString};
603-
604-
// `dbg!` is only available with `libstd`; just nop it out when testing
605-
// with alloc only.
606-
macro_rules! dbg {
607-
($x:expr) => { $x }
608-
}
602+
// `dbg!` is only available with `libstd`; just nop it out when testing
603+
// with alloc only.
604+
#[cfg(not(feature = "std"))]
605+
macro_rules! dbg {
606+
($x:expr) => {
607+
$x
608+
};
609609
}
610610

611611
fn expect_parse(s: &str) -> Targets {
@@ -775,6 +775,8 @@ mod tests {
775775
// `println!` is only available with `libstd`.
776776
#[cfg(feature = "std")]
777777
fn size_of_filters() {
778+
use std::println;
779+
778780
fn print_sz(s: &str) {
779781
let filter = s.parse::<Targets>().expect("filter should parse");
780782
println!(

tracing-subscriber/src/fmt/fmt_layer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use crate::{
44
layer::{self, Context},
55
registry::{self, LookupSpan, SpanRef},
66
};
7+
use alloc::{fmt, format, string::String};
8+
use core::{any::TypeId, marker::PhantomData, ops::Deref};
79
use format::{FmtSpan, TimingDisplay};
8-
use std::{
9-
any::TypeId, cell::RefCell, env, fmt, io, marker::PhantomData, ops::Deref, time::Instant,
10-
};
10+
use std::{cell::RefCell, env, eprintln, io, thread_local, time::Instant};
1111
use tracing_core::{
1212
field,
1313
span::{Attributes, Current, Id, Record},
@@ -1257,6 +1257,7 @@ mod test {
12571257
time,
12581258
};
12591259
use crate::Registry;
1260+
use alloc::{string::ToString, vec, vec::Vec};
12601261
use format::FmtSpan;
12611262
use regex::Regex;
12621263
use tracing::subscriber::with_default;
@@ -1631,8 +1632,7 @@ mod test {
16311632
.with_timer(MockTime)
16321633
.with_span_events(FmtSpan::ACTIVE);
16331634

1634-
let (reloadable_layer, reload_handle) =
1635-
crate::reload::Layer::new(inner_layer);
1635+
let (reloadable_layer, reload_handle) = crate::reload::Layer::new(inner_layer);
16361636
let reload = reloadable_layer.with_subscriber(Registry::default());
16371637

16381638
with_default(reload, || {

tracing-subscriber/src/fmt/format/json.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ use crate::{
77
},
88
registry::LookupSpan,
99
};
10-
use serde::ser::{SerializeMap, Serializer as _};
11-
use serde_json::Serializer;
12-
use std::{
10+
use alloc::{
1311
collections::BTreeMap,
1412
fmt::{self, Write},
13+
format,
14+
string::String,
1515
};
16+
use serde::ser::{SerializeMap, Serializer as _};
17+
use serde_json::Serializer;
1618
use tracing_core::{
1719
field::{self, Field},
1820
span::Record,

tracing-subscriber/src/fmt/format/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use tracing_log::NormalizeEvent;
4848
#[cfg(feature = "ansi")]
4949
use nu_ansi_term::{Color, Style};
5050

51-
5251
mod escape;
5352
use escape::Escape;
5453

@@ -433,6 +432,8 @@ impl<'writer> Writer<'writer> {
433432
/// value implementing [`fmt::Write`] is a [`String`], it will contain
434433
/// the formatted output of [`Format::format_event`], which may then be
435434
/// used for other purposes.
435+
///
436+
/// [`String`]: alloc::string::String
436437
#[must_use]
437438
pub fn new(writer: &'writer mut impl fmt::Write) -> Self {
438439
Self {
@@ -1269,7 +1270,10 @@ impl field::Visit for DefaultVisitor<'_> {
12691270
),
12701271
)
12711272
} else {
1272-
self.record_debug(field, &format_args!("{}", Escape(&format_args!("{}", value))))
1273+
self.record_debug(
1274+
field,
1275+
&format_args!("{}", Escape(&format_args!("{}", value))),
1276+
)
12731277
}
12741278
}
12751279

@@ -1294,7 +1298,7 @@ impl field::Visit for DefaultVisitor<'_> {
12941298
"message" => {
12951299
// Escape ANSI characters to prevent malicious patterns (e.g., terminal injection attacks)
12961300
write!(self.writer, "{:?}", Escape(value))
1297-
},
1301+
}
12981302
name if name.starts_with("r#") => write!(
12991303
self.writer,
13001304
"{}{}{:?}",
@@ -1750,6 +1754,11 @@ impl Display for TimingDisplay {
17501754
#[cfg(test)]
17511755
pub(super) mod test {
17521756
use crate::fmt::{test::MockMakeWriter, time::FormatTime};
1757+
use alloc::{
1758+
borrow::ToOwned,
1759+
format,
1760+
string::{String, ToString},
1761+
};
17531762
use tracing::{
17541763
self,
17551764
dispatcher::{set_default, Dispatch},

0 commit comments

Comments
 (0)