-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
tracing::instrument
triggers blocks_in_conditions
#12281
Comments
Needs either a call to is_from_proc_macro or in_external_macro. |
Did #12040 not also fix this? It added a call to |
Hello! I just came here to ask some questions. Thanks |
@okynos I can't see the linked page, but I ran clippy on your project and I assume you mean clippy linting on this In that case, it doesn't look related to the issue here, and as far as I can tell your case seems like an expected warning. The lint seems to be explicitly looking for that pattern (match expression with a closure containing a block), and wants you to move the |
Hi @y21, Thanks for your explanation. For those who comes with the same misunderstood or problem. The simplified message is that you shouldn't introduce
That contains code inside the match. I transform it into this:
|
All 500s are now `{"message": "some reason"}`. I implemented all the methods in the server impl with the new response as error, and in the trait just `or_else(|err| Ok(resp::InternalServerError(err))` so I didn't miss any places. Note that on 1.76, I'm seeing a lot of clippy errors due to tracing instrument: rust-lang/rust-clippy#12281
I'm a bit confused - #12173 seems related, and is not included in the rustc-1.76.0 sources, so I assumed it was a fix - however even after applying the patch it doesn't seem to prevent the warnings. |
It'd be good to have some kind of MCVE for this, because a simple async fn annotated with I'm surprised that #12040 and #12173 supposedly didn't fix it 🤔 |
Could this be functions that are also rewritten using other macros? Thinking about #[async_trait]
impl … for … {
#[tracing::instrument(…)
async fn foo() { … }
} blocks. Another place I saw this occuring is functions with |
I was able to produce a small repro: https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=b1dbfd2daf9f4a2cb6c79c46472b8f14 use async_trait::async_trait;
#[async_trait]
pub trait FooService {
async fn do_something(&self, r: i32) -> std::io::Result<i32>;
}
struct Foo {}
#[async_trait]
impl FooService for Foo {
#[tracing::instrument(skip(self), ret, err)]
async fn do_something(&self, _request: i32) -> std::io::Result<i32> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"some error",
))
}
} Clippy complains like this:
|
- agenix has not been updated (ryantm/agenix#241). - //tvix: regenerate protobuf files - //tvix:clippy: work around rust-lang/rust-clippy#12281 which exclusively causes false positives in our code at the moment. Change-Id: I38d2f4c0e6d1abc92be360b06f58e6d40e7732a3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11127 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
- agenix has not been updated (ryantm/agenix#241). - //tvix: regenerate protobuf files - //tvix:clippy: work around rust-lang/rust-clippy#12281 which exclusively causes false positives in our code at the moment. Change-Id: I38d2f4c0e6d1abc92be360b06f58e6d40e7732a3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11127 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
All 500s are now `{"message": "some reason"}`. I implemented all the methods in the server impl with the new response as error, and in the trait just `or_else(|err| Ok(resp::InternalServerError(err))` so I didn't miss any places. Note that on 1.76, I'm seeing a lot of clippy errors due to tracing instrument: rust-lang/rust-clippy#12281
All 500s are now `{"message": "some reason"}`. I implemented all the methods in the server impl with the new response as error, and in the trait just `or_else(|err| Ok(resp::InternalServerError(err))` so I didn't miss any places. Note that on 1.76, I'm seeing a lot of clippy errors due to tracing instrument: rust-lang/rust-clippy#12281
Yup. I think at the very least we shouldn't get clippy issues for code in our dependencies. |
Can we disable this lint by default?? |
In case anyone else is wondering, the fix for this should get released in the 1.80 release of rust/clippy. |
But it didn't, right? |
Still happens in my project using 1.80. as well. However, looking at the changelog, only commits up until May 30th were included, and the fix for this landed June 8th. So 1.81 presumably? |
Yes, the fix will be in 1.81. 1.80 branched on June 7th and the referenced PR was merged on June 8th. releases.rs can be useful for this. |
v1.81.0 resolved the problem for me |
Summary
Basically #12016 (comment)
Since 1.76.0, any
async fn
impl that is decorated with#[tracing::instrument(..)]
will trigger https://rust-lang.github.io/rust-clippy/master/index.html#/blocks_in_conditionsLint Name
blocks_in_conditions
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
no warnings
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: