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: suppress clippy::suspicious_else without nop let #1614

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,6 @@ fn gen_block(
__tracing_attr_span = #span;
__tracing_attr_guard = __tracing_attr_span.enter();
}
// pacify clippy::suspicious_else_formatting
let _ = ();
);

if err {
Expand All @@ -583,8 +581,17 @@ fn gen_block(
}

quote_spanned!(block.span()=>
#span
#block
// Because `quote` produces a stream of tokens _without_ whitespace, the
// `if` and the block will appear directly next to each other. This
// generates a clippy lint about suspicious `if/else` formatting.
// Therefore, suppress the lint inside the generated code...
#[allow(clippy::suspicious_else_formatting)]
{
#span
// ...but turn the lint back on inside the function body.
#[warn(clippy::suspicious_else_formatting)]
#block
}
)
}

Expand Down
3 changes: 3 additions & 0 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ async fn test_async_fn(polls: usize) -> Result<(), ()> {
future.await
}

#[instrument]
async fn test_async_fn_empty() {}

#[test]
fn async_fn_only_enters_for_polls() {
let (collector, handle) = collector::mock()
Expand Down
6 changes: 6 additions & 0 deletions tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ fn err() -> Result<u8, TryFromIntError> {
u8::try_from(1234)
}

#[instrument(err)]
fn err_suspicious_else() -> Result<u8, TryFromIntError> {
{}
u8::try_from(1234)
}

#[test]
fn test() {
let span = span::mock().named("err");
Expand Down