Skip to content

tracing: add Instrumented::span_and_inner_pin_mut#3475

Open
sepointon wants to merge 1 commit intotokio-rs:mainfrom
sepointon:push-nsllmovmurzp
Open

tracing: add Instrumented::span_and_inner_pin_mut#3475
sepointon wants to merge 1 commit intotokio-rs:mainfrom
sepointon:push-nsllmovmurzp

Conversation

@sepointon
Copy link

This is useful for implementing poll-type functions on foreign traits.

Closes #2804.

There's some potential for bikeshedding about names; I don't care one way or another, and so I used the name that the internal code is already using on the projection type.

Most use cases probably won't need &mut Span as opposed to &Span, but the mutable reference is actually natural and fully general here: the inner value really does need to be a pinned mutable reference (because that's what's used in poll-type functions), so the Instrumented value also needs to be behind a mutable reference, so there's never an opportunity to create a second reference to the span while the reference to the inner value is held.

There's potential for a span_and_inner_pin_ref method, which also already exists on the projection type, but I don't know what the use case for exposing that is as opposed to using the existing methods (since mutable references and exclusivity aren't in play).

@sepointon sepointon requested review from a team, hawkw and hds as code owners February 12, 2026 08:56
@sepointon
Copy link
Author

Should I also be changing tracing_futures::Instrumented in parallel? #3456 has at least one other person confused about the state of play here.

This is useful for implementing poll-type functions on foreign traits.

Closes tokio-rs#2804.
@sepointon
Copy link
Author

I decided tracing_futures::Instrumented probably has a long-term future as a vehicle for trait impls unacceptable for core tracing, so it makes sense to add a parallel method to it.

I note that, with this PR, tracing_futures::Instrumented could be rewritten as a wrapper around tracing::Instrumented (since the whole point of this PR is to expose the necessary bits to implement poll-style foreign traits), which would remove the duplicated logic that's a divergence hazard and reduce the amount of unsafe code, but that's not something that has to happen in this PR and so it makes sense to defer as a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose simultaneous access to Span and Inner on Instrumented so that implementation of foreign traits are possible

1 participant