Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributes: fix #[instrument(err)] with mutable parameters #1167

Merged
merged 6 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ fn gen_body(
quote_spanned!(block.span()=>
let __tracing_attr_span = #span;
let __tracing_attr_guard = __tracing_attr_span.enter();
let f = move || #return_type { #block };
match f() {
match move || #return_type { #block }() {
hawkw marked this conversation as resolved.
Show resolved Hide resolved
Ok(x) => Ok(x),
Err(e) => {
tracing::error!(error = %e);
Expand Down
54 changes: 54 additions & 0 deletions tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,57 @@ fn test_async() {
});
handle.assert_finished();
}

#[instrument(err)]
fn err_mut(out: &mut u8) -> Result<(), TryFromIntError> {
*out = u8::try_from(1234)?;
Ok(())
}

#[test]
fn test_mut() {
let span = span::mock().named("err_mut");
let (collector, handle) = collector::mock()
.new_span(span.clone())
.enter(span.clone())
.event(event::mock().at_level(Level::ERROR))
.exit(span.clone())
.drop_span(span)
.done()
.run_with_handle();
with_default(collector, || err_mut(&mut 0).ok());
handle.assert_finished();
}

#[instrument(err)]
async fn err_mut_async(polls: usize, out: &mut u8) -> Result<(), TryFromIntError> {
let future = PollN::new_ok(polls);
tracing::trace!(awaiting = true);
future.await.ok();
*out = u8::try_from(1234)?;
Ok(())
}

#[test]
fn test_mut_async() {
let span = span::mock().named("err_mut_async");
let (collector, handle) = collector::mock()
.new_span(span.clone())
.enter(span.clone())
.event(
event::mock()
.with_fields(field::mock("awaiting").with_value(&true))
.at_level(Level::TRACE),
)
.exit(span.clone())
.enter(span.clone())
.event(event::mock().at_level(Level::ERROR))
.exit(span.clone())
.drop_span(span)
.done()
.run_with_handle();
with_default(collector, || {
block_on_future(async { err_mut_async(2, &mut 0).await }).ok();
});
handle.assert_finished();
}