Skip to content

Commit e821257

Browse files
committed
Add must use annotation to Span as in tokio-rs#3234.
1 parent 134f937 commit e821257

9 files changed

Lines changed: 243 additions & 242 deletions

File tree

tracing-mock/tests/span_ancestry.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn contextual_parent() {
2222

2323
with_default(collector, || {
2424
let _guard = tracing::info_span!("contextual parent").entered();
25-
tracing::info_span!("span");
25+
let _ = tracing::info_span!("span");
2626
});
2727

2828
handle.assert_finished();
@@ -45,7 +45,7 @@ fn contextual_parent_wrong_name() {
4545

4646
with_default(collector, || {
4747
let _guard = tracing::info_span!("another parent").entered();
48-
tracing::info_span!("span");
48+
let _ = tracing::info_span!("span");
4949
});
5050

5151
handle.assert_finished();
@@ -70,7 +70,7 @@ fn contextual_parent_wrong_id() {
7070
with_default(collector, || {
7171
let _span = tracing::info_span!("contextual parent");
7272
let _guard = tracing::info_span!("another parent").entered();
73-
tracing::info_span!("span");
73+
let _ = tracing::info_span!("span");
7474
});
7575

7676
handle.assert_finished();
@@ -94,7 +94,7 @@ fn contextual_parent_wrong_level() {
9494

9595
with_default(collector, || {
9696
let _guard = tracing::debug_span!("contextual parent").entered();
97-
tracing::info_span!("span");
97+
let _ = tracing::info_span!("span");
9898
});
9999

100100
handle.assert_finished();
@@ -111,7 +111,7 @@ fn expect_contextual_parent_actual_contextual_root() {
111111
let (collector, handle) = collector::mock().new_span(span).run_with_handle();
112112

113113
with_default(collector, || {
114-
tracing::info_span!("span");
114+
let _ = tracing::info_span!("span");
115115
});
116116

117117
handle.assert_finished();
@@ -132,7 +132,7 @@ fn expect_contextual_parent_actual_explicit_parent() {
132132

133133
with_default(collector, || {
134134
let span = tracing::info_span!("explicit parent");
135-
tracing::info_span!(parent: span.id(), "span");
135+
let _ = tracing::info_span!(parent: span.id(), "span");
136136
});
137137

138138
handle.assert_finished();
@@ -153,7 +153,7 @@ fn expect_contextual_parent_actual_explicit_root() {
153153

154154
with_default(collector, || {
155155
let _guard = tracing::info_span!("contextual parent").entered();
156-
tracing::info_span!(parent: None, "span");
156+
let _ = tracing::info_span!(parent: None, "span");
157157
});
158158

159159
handle.assert_finished();
@@ -168,7 +168,7 @@ fn contextual_root() {
168168
let (collector, handle) = collector::mock().new_span(span).run_with_handle();
169169

170170
with_default(collector, || {
171-
tracing::info_span!("span");
171+
let _ = tracing::info_span!("span");
172172
});
173173

174174
handle.assert_finished();
@@ -188,7 +188,7 @@ fn expect_contextual_root_actual_contextual_parent() {
188188

189189
with_default(collector, || {
190190
let _guard = tracing::info_span!("contextual parent").entered();
191-
tracing::info_span!("span");
191+
let _ = tracing::info_span!("span");
192192
});
193193

194194
handle.assert_finished();
@@ -208,7 +208,7 @@ fn expect_contextual_root_actual_explicit_parent() {
208208

209209
with_default(collector, || {
210210
let span = tracing::info_span!("explicit parent");
211-
tracing::info_span!(parent: span.id(), "span");
211+
let _ = tracing::info_span!(parent: span.id(), "span");
212212
});
213213

214214
handle.assert_finished();
@@ -228,7 +228,7 @@ fn expect_contextual_root_actual_explicit_root() {
228228

229229
with_default(collector, || {
230230
let _guard = tracing::info_span!("contextual parent").entered();
231-
tracing::info_span!(parent: None, "span");
231+
let _ = tracing::info_span!(parent: None, "span");
232232
});
233233

234234
handle.assert_finished();
@@ -247,7 +247,7 @@ fn explicit_parent() {
247247

248248
with_default(collector, || {
249249
let span = tracing::info_span!("explicit parent");
250-
tracing::info_span!(parent: span.id(), "span");
250+
let _ = tracing::info_span!(parent: span.id(), "span");
251251
});
252252

253253
handle.assert_finished();
@@ -270,7 +270,7 @@ fn explicit_parent_wrong_name() {
270270

271271
with_default(collector, || {
272272
let span = tracing::info_span!("another parent");
273-
tracing::info_span!(parent: span.id(), "span");
273+
let _ = tracing::info_span!(parent: span.id(), "span");
274274
});
275275

276276
handle.assert_finished();
@@ -294,7 +294,7 @@ fn explicit_parent_wrong_id() {
294294
with_default(collector, || {
295295
let _span = tracing::info_span!("explicit parent");
296296
let another_span = tracing::info_span!("another parent");
297-
tracing::info_span!(parent: another_span.id(), "span");
297+
let _ = tracing::info_span!(parent: another_span.id(), "span");
298298
});
299299

300300
handle.assert_finished();
@@ -316,7 +316,7 @@ fn explicit_parent_wrong_level() {
316316

317317
with_default(collector, || {
318318
let span = tracing::debug_span!("explicit parent");
319-
tracing::info_span!(parent: span.id(), "span");
319+
let _ = tracing::info_span!(parent: span.id(), "span");
320320
});
321321

322322
handle.assert_finished();
@@ -337,7 +337,7 @@ fn expect_explicit_parent_actual_contextual_parent() {
337337

338338
with_default(collector, || {
339339
let _guard = tracing::info_span!("contextual parent").entered();
340-
tracing::info_span!("span");
340+
let _ = tracing::info_span!("span");
341341
});
342342

343343
handle.assert_finished();
@@ -354,7 +354,7 @@ fn expect_explicit_parent_actual_contextual_root() {
354354
let (collector, handle) = collector::mock().new_span(span).run_with_handle();
355355

356356
with_default(collector, || {
357-
tracing::info_span!("span");
357+
let _ = tracing::info_span!("span");
358358
});
359359

360360
handle.assert_finished();
@@ -375,7 +375,7 @@ fn expect_explicit_parent_actual_explicit_root() {
375375

376376
with_default(collector, || {
377377
let _guard = tracing::info_span!("contextual parent").entered();
378-
tracing::info_span!(parent: None, "span");
378+
let _ = tracing::info_span!(parent: None, "span");
379379
});
380380

381381
handle.assert_finished();
@@ -395,7 +395,7 @@ fn explicit_root() {
395395

396396
with_default(collector, || {
397397
let _guard = tracing::info_span!("contextual parent").entered();
398-
tracing::info_span!(parent: None, "span");
398+
let _ = tracing::info_span!(parent: None, "span");
399399
});
400400

401401
handle.assert_finished();
@@ -415,7 +415,7 @@ fn expect_explicit_root_actual_contextual_parent() {
415415

416416
with_default(collector, || {
417417
let _guard = tracing::info_span!("contextual parent").entered();
418-
tracing::info_span!("span");
418+
let _ = tracing::info_span!("span");
419419
});
420420

421421
handle.assert_finished();
@@ -431,7 +431,7 @@ fn expect_explicit_root_actual_contextual_root() {
431431
let (collector, handle) = collector::mock().new_span(span).run_with_handle();
432432

433433
with_default(collector, || {
434-
tracing::info_span!("span");
434+
let _ = tracing::info_span!("span");
435435
});
436436

437437
handle.assert_finished();
@@ -451,7 +451,7 @@ fn expect_explicit_root_actual_explicit_parent() {
451451

452452
with_default(collector, || {
453453
let span = tracing::info_span!("explicit parent");
454-
tracing::info_span!(parent: span.id(), "span");
454+
let _ = tracing::info_span!(parent: span.id(), "span");
455455
});
456456

457457
handle.assert_finished();
@@ -466,7 +466,7 @@ fn explicit_and_contextual_root_is_explicit() {
466466
let (collector, handle) = collector::mock().new_span(span).run_with_handle();
467467

468468
with_default(collector, || {
469-
tracing::info_span!(parent: None, "span");
469+
let _ = tracing::info_span!(parent: None, "span");
470470
});
471471

472472
handle.assert_finished();

tracing-subscriber/tests/env_filter/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ fn same_name_spans() {
5353
.run_with_handle();
5454
let subscriber = subscriber.with(filter);
5555
with_default(subscriber, || {
56-
tracing::trace_span!("foo", bar = 1);
57-
tracing::trace_span!("foo", baz = 1);
56+
let _ = tracing::trace_span!("foo", bar = 1);
57+
let _ = tracing::trace_span!("foo", baz = 1);
5858
});
5959

6060
finished.assert_finished();
@@ -343,9 +343,9 @@ fn more_specific_dynamic_filter_more_verbose() {
343343
let subscriber = collector.with(filter);
344344

345345
with_default(subscriber, || {
346-
tracing::info_span!("enabled info");
347-
tracing::debug_span!("disabled debug");
348-
tracing::debug_span!("enabled debug", hello = &4_u64);
346+
let _ = tracing::info_span!("enabled info");
347+
let _ = tracing::debug_span!("disabled debug");
348+
let _ = tracing::debug_span!("enabled debug", hello = &4_u64);
349349

350350
// .only() doesn't work when we don't enter/exit spans
351351
tracing::info!("marker");
@@ -391,10 +391,10 @@ fn more_specific_dynamic_filter_less_verbose() {
391391
let subscriber = collector.with(filter);
392392

393393
with_default(subscriber, || {
394-
tracing::info_span!("enabled info");
395-
tracing::warn_span!("enabled hello=100 warn", hello = &100_u64);
396-
tracing::info_span!("disabled hello=4 info", hello = &4_u64);
397-
tracing::warn_span!("enabled hello=4 warn", hello = &4_u64);
394+
let _ = tracing::info_span!("enabled info");
395+
let _ = tracing::warn_span!("enabled hello=100 warn", hello = &100_u64);
396+
let _ = tracing::info_span!("disabled hello=4 info", hello = &4_u64);
397+
let _ = tracing::warn_span!("enabled hello=4 warn", hello = &4_u64);
398398

399399
// .only() doesn't work when we don't enter/exit spans
400400
tracing::info!("marker");

tracing-subscriber/tests/env_filter/per_subscriber.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fn same_name_spans() {
5252
.with(subscriber.with_filter(filter))
5353
.set_default();
5454

55-
tracing::trace_span!("foo", bar = 1);
56-
tracing::trace_span!("foo", baz = 1);
55+
let _ = tracing::trace_span!("foo", bar = 1);
56+
let _ = tracing::trace_span!("foo", baz = 1);
5757

5858
handle.assert_finished();
5959
}

tracing-subscriber/tests/same_len_filters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ fn same_num_fields_and_name_len() {
7373
.run_with_handle();
7474
let subscriber = subscriber.with(filter);
7575
with_default(subscriber, || {
76-
tracing::trace_span!("foo", bar = 1);
77-
tracing::trace_span!("baz", boz = 1);
76+
let _ = tracing::trace_span!("foo", bar = 1);
77+
let _ = tracing::trace_span!("baz", boz = 1);
7878
});
7979

8080
finished.assert_finished();

tracing-subscriber/tests/subscriber_filters/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ fn basic_subscriber_filters_spans() {
7171
.with(info_subscriber.with_filter(LevelFilter::INFO))
7272
.set_default();
7373

74-
tracing::trace_span!("hello trace");
75-
tracing::debug_span!("hello debug");
76-
tracing::info_span!("hello info");
74+
let _ = tracing::trace_span!("hello trace");
75+
let _ = tracing::debug_span!("hello debug");
76+
let _ = tracing::info_span!("hello info");
7777

7878
trace_handle.assert_finished();
7979
debug_handle.assert_finished();

tracing/src/span.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ pub trait AsId: crate::sealed::Sealed {
328328
/// span will silently do nothing. Thus, the handle can be used in the same
329329
/// manner regardless of whether or not the trace is currently being collected.
330330
#[derive(Clone)]
331+
#[must_use = "Once a span has been created, it should be entered."]
331332
pub struct Span {
332333
/// A handle used to enter the span when it is not executing.
333334
///

tracing/tests/macro_imports.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ use tracing::Level;
33
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
44
#[test]
55
fn prefixed_span_macros() {
6-
tracing::span!(Level::DEBUG, "foo");
7-
tracing::trace_span!("foo");
8-
tracing::debug_span!("foo");
9-
tracing::info_span!("foo");
10-
tracing::warn_span!("foo");
11-
tracing::error_span!("foo");
6+
let _ = tracing::span!(Level::DEBUG, "foo");
7+
let _ = tracing::trace_span!("foo");
8+
let _ = tracing::debug_span!("foo");
9+
let _ = tracing::info_span!("foo");
10+
let _ = tracing::warn_span!("foo");
11+
let _ = tracing::error_span!("foo");
1212
}
1313

1414
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
1515
#[test]
1616
fn prefixed_event_macros() {
17-
tracing::event!(Level::DEBUG, "foo");
18-
tracing::trace!("foo");
19-
tracing::debug!("foo");
20-
tracing::info!("foo");
21-
tracing::warn!("foo");
22-
tracing::error!("foo");
17+
let _ = tracing::event!(Level::DEBUG, "foo");
18+
let _ = tracing::trace!("foo");
19+
let _ = tracing::debug!("foo");
20+
let _ = tracing::info!("foo");
21+
let _ = tracing::warn!("foo");
22+
let _ = tracing::error!("foo");
2323
}

0 commit comments

Comments
 (0)