Skip to content

Commit

Permalink
tracing: remove Into<Option<Id>> impl for Span (#1003)
Browse files Browse the repository at this point in the history
* tracing: remove `Into<Option<Id>>` impl for `Span`

This doesn't work correctly, since the span is dropped when the function
returns, calling `try_close` on that span. We could remove the inner
value in this case, but then `try_close` will _never_ be called on that
ID, leaking the parent. If the span is dropped *after* the new span is
created, instead, everything will work correctly, because the subscriber
will have already increased its reference count (as it now has a
child). Thus, only `&Span` is valid here.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw authored Oct 1, 2020
1 parent 515255f commit 95d5511
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions tracing/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,22 +993,14 @@ impl Span {
/// # use tracing::{span, Id, Level, Span};
/// let span1 = span!(Level::INFO, "span_1");
/// let span2 = span!(Level::DEBUG, "span_2");
/// span2.follows_from(span1);
/// span2.follows_from(&span1);
/// ```
///
/// Setting a `follows_from` relationship with the current span:
/// ```
/// # use tracing::{span, Id, Level, Span};
/// let span = span!(Level::INFO, "hello!");
/// span.follows_from(Span::current());
/// ```
///
/// Setting a `follows_from` relationship with a `Span` reference:
/// ```
/// # use tracing::{span, Id, Level, Span};
/// let span = span!(Level::INFO, "hello!");
/// let curr = Span::current();
/// span.follows_from(&curr);
/// span.follows_from(&Span::current());
/// ```
///
/// Setting a `follows_from` relationship with an `Id`:
Expand Down Expand Up @@ -1145,12 +1137,6 @@ impl<'a> Into<Option<Id>> for &'a Span {
}
}

impl Into<Option<Id>> for Span {
fn into(self) -> Option<Id> {
self.inner.as_ref().map(Inner::id)
}
}

impl Drop for Span {
fn drop(&mut self) {
if let Some(Inner {
Expand Down

0 comments on commit 95d5511

Please sign in to comment.