-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Macro-generated code triggers suspicious-else-formatting #6249
Comments
I can sadly not reproduce that currently by using the simple The lint it self comes from |
If I'm not mistaken |
@rustbot claim |
This issue originates from the use of The
The first point is also the reason why this could happen with every lint as it bypasses our check if the code was generated via a macro. I would therefor think that this and potential other false positives from the |
I came into this bug and reproduced it by the code below. #![deny(clippy::suspicious_else_formatting)]
#[tracing::instrument]
async fn get(key: &str) -> String {
if key.is_empty() {
panic!()
} else {
todo!()
}
}
Versions:
|
@Nugine I have the same issue due to instruments, the weird part is, that it fails on our CI but not locally: https://github.com/gameroasters/atlasserver/runs/3779641152?check_suite_focus=true |
Our CI 166 also failed today. But CI 164 succeeded. There is no commit during this week. The CI toolchain is locked to Try to update your lockfile and toolchain. |
@Nugine right on, I did not have the tracing-attributes update locally yet, thanks for the hint! |
## Motivation Apparently, using `quote_spanned!` can trigger a Clippy bug where the text `else`, even inside a comment, _may_ cause the `suspicious_else_formatting` lint to be triggered incorrectly (see rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249). This causes the lint to fire in some cases when the `#[instrument]` attribute is used on `async fn`s. See issue #1613 for details. ## Solution It turns out that some of the uses of `quote_spanned!` in the `tracing-attributes` code generation are not needed. We really only need `quote_spanned!` when actually interpolating the user provided code into a block, not in the `tracing-attributes` code that inserts the generated code for producing the span etc. Replacing some of these `quote_spanned!` uses with the normal `quote!` macro still generates correct location diagnostics for errors in the user code, but fixes the incorrect clippy lint. I've added a few test cases that should reproduce the bug. Fixes #1613
## Motivation Apparently, using `quote_spanned!` can trigger a Clippy bug where the text `else`, even inside a comment, _may_ cause the `suspicious_else_formatting` lint to be triggered incorrectly (see rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249). This causes the lint to fire in some cases when the `#[instrument]` attribute is used on `async fn`s. See issue #1613 for details. ## Solution It turns out that some of the uses of `quote_spanned!` in the `tracing-attributes` code generation are not needed. We really only need `quote_spanned!` when actually interpolating the user provided code into a block, not in the `tracing-attributes` code that inserts the generated code for producing the span etc. Replacing some of these `quote_spanned!` uses with the normal `quote!` macro still generates correct location diagnostics for errors in the user code, but fixes the incorrect clippy lint. I've added a few test cases that should reproduce the bug. Fixes #1613 Signed-off-by: Eliza Weisman <[email protected]>
## Motivation Apparently, using `quote_spanned!` can trigger a Clippy bug where the text `else`, even inside a comment, _may_ cause the `suspicious_else_formatting` lint to be triggered incorrectly (see rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249). This causes the lint to fire in some cases when the `#[instrument]` attribute is used on `async fn`s. See issue #1613 for details. ## Solution It turns out that some of the uses of `quote_spanned!` in the `tracing-attributes` code generation are not needed. We really only need `quote_spanned!` when actually interpolating the user provided code into a block, not in the `tracing-attributes` code that inserts the generated code for producing the span etc. Replacing some of these `quote_spanned!` uses with the normal `quote!` macro still generates correct location diagnostics for errors in the user code, but fixes the incorrect clippy lint. I've added a few test cases that should reproduce the bug. Fixes #1613 Signed-off-by: Eliza Weisman <[email protected]>
## Motivation Apparently, using `quote_spanned!` can trigger a Clippy bug where the text `else`, even inside a comment, _may_ cause the `suspicious_else_formatting` lint to be triggered incorrectly (see rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249). This causes the lint to fire in some cases when the `#[instrument]` attribute is used on `async fn`s. See issue #1613 for details. ## Solution It turns out that some of the uses of `quote_spanned!` in the `tracing-attributes` code generation are not needed. We really only need `quote_spanned!` when actually interpolating the user provided code into a block, not in the `tracing-attributes` code that inserts the generated code for producing the span etc. Replacing some of these `quote_spanned!` uses with the normal `quote!` macro still generates correct location diagnostics for errors in the user code, but fixes the incorrect clippy lint. I've added a few test cases that should reproduce the bug. Fixes #1613 Signed-off-by: Eliza Weisman <[email protected]>
# 0.1.17 (October 1, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([#1614]) [#1617]: #1617 [#1616]: #1616 [#1614]: #1614
# 0.1.17 (October 1, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([#1614]) [#1617]: #1617 [#1616]: #1616 [#1614]: #1614
# 0.1.18 (October 5, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([#1614]) [#1617]: #1617 [#1616]: #1616 [#1614]: #1614
I might have an idea how to avoid FPs like these in exchange for some false negatives. 🙃 @rustbot claim once again ^^ |
This comment has been minimized.
This comment has been minimized.
My idea sadly didn't work out. #7707 also did some work with another approach, that seems promising. I'm closing this in the hopes that it's fixed 🙃 |
# 0.1.18 (October 5, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([tokio-rs#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([tokio-rs#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([tokio-rs#1614]) [tokio-rs#1617]: tokio-rs#1617 [tokio-rs#1616]: tokio-rs#1616 [tokio-rs#1614]: tokio-rs#1614
I tried this code:
(added some context because indentation level might matter? or maybe it's just entirely unformatted macro output)
I expected to see this happen: No warnings
Instead, this happened:
Meta
(will fill this in once I can reproduce on a local computer again, right now fails on CI, probably
clippy 0.0.212 (ffa2e7a 2020-10-24)
)The text was updated successfully, but these errors were encountered: