Skip to content

Commit 2dbac6e

Browse files
committed
tracing: revert "make valueset macro sanitary"
The change merged in #3382 caused a breaking change when released. This is because users of the tracing macros depend on being able to use a bare `debug` or `display` function within the macro itself, for example: ```rust tracing::info!(foo = debug(foo), bar = display(bar)); ``` This change reverts the breaking part of the original commit, which is removing the import statement from the `valueset!` macro. However, it leaves the change to use full module paths inside the macro. E.g. `$crate::field::debug`. This is best practice, and so worth keeping. This change also adds a nice warning comment above the import statement to try and avoid another break happening in the future (because this isn't the first time that this has happened). It also adds explicit tests for the use of bare `debug` and `display` usage with the same end.
1 parent cdaf661 commit 2dbac6e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

tracing/src/macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,6 +2971,9 @@ macro_rules! valueset {
29712971
($fields:expr, $($kvs:tt)+) => {
29722972
{
29732973
#[allow(unused_imports)]
2974+
// This import statement CANNOT be removed as it will break existing use cases.
2975+
// See #831, #2332, #3424 for the last times we tried.
2976+
use $crate::field::{debug, display, Value};
29742977
$fields.value_set_all($crate::valueset!(
29752978
@ { },
29762979
$($kvs)+

tracing/tests/macros.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn span() {
4242
span!(Level::DEBUG, "foo", bar.baz = %2);
4343
span!(Level::DEBUG, "foo");
4444
span!(Level::DEBUG, "bar",);
45+
span!(Level::DEBUG, "bar", foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
4546
}
4647

4748
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -58,6 +59,7 @@ fn trace_span() {
5859
trace_span!("foo", bar.baz = %2);
5960
trace_span!("bar");
6061
trace_span!("bar",);
62+
trace_span!("bar", foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
6163
}
6264

6365
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -74,6 +76,7 @@ fn debug_span() {
7476
debug_span!("foo", bar.baz = %2);
7577
debug_span!("bar");
7678
debug_span!("bar",);
79+
debug_span!("bar", foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
7780
}
7881

7982
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -90,6 +93,7 @@ fn info_span() {
9093
info_span!("foo", bar.baz = %2);
9194
info_span!("bar");
9295
info_span!("bar",);
96+
info_span!("bar", foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
9397
}
9498

9599
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -106,6 +110,7 @@ fn warn_span() {
106110
warn_span!("foo", bar.baz = %2);
107111
warn_span!("bar");
108112
warn_span!("bar",);
113+
warn_span!("bar", foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
109114
}
110115

111116
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -122,6 +127,7 @@ fn error_span() {
122127
error_span!("foo", bar.baz = %2);
123128
error_span!("bar");
124129
error_span!("bar",);
130+
error_span!("bar", foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
125131
}
126132

127133
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -452,6 +458,7 @@ fn event() {
452458
event!(Level::DEBUG, ?foo);
453459
event!(Level::DEBUG, %foo);
454460
event!(Level::DEBUG, foo);
461+
event!(Level::DEBUG, foo = display("foo"), quux = debug(::std::option::Option::Some(2)));
455462
}
456463

457464
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -621,9 +628,7 @@ fn trace() {
621628
trace!(target: "foo_events", %foo, true, "message");
622629
trace!(name: "foo", target: "foo_events", ?foo, true, "message");
623630
trace!(name: "foo", target: "foo_events", %foo, true, "message");
624-
let debug = "debug";
625-
let display = "display";
626-
trace!("{debug:?} {display:?}");
631+
trace!(foo = display("foo"), quux = debug(foo));
627632
}
628633

629634
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -691,9 +696,7 @@ fn debug() {
691696
debug!(target: "foo_events", %foo, true, "message");
692697
debug!(name: "foo", target: "foo_events", ?foo, true, "message");
693698
debug!(name: "foo", target: "foo_events", %foo, true, "message");
694-
let debug = "debug";
695-
let display = "display";
696-
debug!("{debug:?} {display:?}");
699+
debug!(foo = display("foo"), quux = debug(foo));
697700
}
698701

699702
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -761,9 +764,7 @@ fn info() {
761764
info!(target: "foo_events", %foo, true, "message");
762765
info!(name: "foo", target: "foo_events", ?foo, true, "message");
763766
info!(name: "foo", target: "foo_events", %foo, true, "message");
764-
let debug = "debug";
765-
let display = "display";
766-
info!("{debug:?} {display:?}");
767+
info!(foo = display("foo"), quux = debug(foo));
767768
}
768769

769770
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -831,9 +832,7 @@ fn warn() {
831832
warn!(target: "foo_events", %foo, true, "message");
832833
warn!(name: "foo", target: "foo_events", ?foo, true, "message");
833834
warn!(name: "foo", target: "foo_events", %foo, true, "message");
834-
let debug = "debug";
835-
let display = "display";
836-
warn!("{debug:?} {display:?}");
835+
warn!(foo = display("foo"), quux = debug(foo));
837836
}
838837

839838
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
@@ -901,9 +900,7 @@ fn error() {
901900
error!(target: "foo_events", %foo, true, "message");
902901
error!(name: "foo", target: "foo_events", ?foo, true, "message");
903902
error!(name: "foo", target: "foo_events", %foo, true, "message");
904-
let debug = "debug";
905-
let display = "display";
906-
error!("{debug:?} {display:?}");
903+
error!(foo = display("foo"), quux = debug(foo));
907904
}
908905

909906
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]

0 commit comments

Comments
 (0)