-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Clippy warns "unneeded return
statement" for #[tokio::{main,test}]
fns on latest nightly
#6869
Comments
As always, this is a clippy bug that warns code generated by external macros (upstream report: rust-lang/rust-clippy#13457). |
Thanks for the reference. I also found that the |
Yeah, I would accept a PR to add the corresponding |
I've put up a PR for clippy, but as was pointed out on the PR (rust-lang/rust-clippy#13464 (comment)) I do wonder if there's a reason for why tokio doesn't use tokio/tokio-macros/src/entry.rs Lines 403 to 404 in 2c14f88
That should tell clippy that it's from a macro expansion and avoid linting but still maintains the input location so rustc points type errors at |
Nit: I think you might've meant I didn't look at the tokio-macros code in detail, but I think there's another place that uses |
I would accept a PR that adjusts the span as long as it does not worsen diagnostics.
I think call_site is fine and what from_expansion can't handle correctly is the generated code using the span from the input.
tokio-macros is a crate that has been existed before located_at stabilized, and no one was interested in working on replacing existing spans with a potential alternative while checking that changes would not cause regressions. |
Not that it matters but AFAIK both
This does not produce a clippy warning#[proc_macro]
pub fn foo(ts: TokenStream) -> TokenStream {
let input = ts.into_iter().next().unwrap().span();
let sp = proc_macro2::Span::call_site().located_at(input.into());
quote::quote_spanned!(sp=> fn f() -> i32 { return 42 }).into()
}
I believe the only change is that at the end of the diagnostic it will say "the error originates from the macro tokio::main" or something like that, which it didn't before. I don't think it's that significant though. But it means that tokio won't get clippy warnings anymore in its proc macro |
Ah good point, my bad, I think the problem is that we can't naively forward user spans without providing any distinguishable context? |
Version
tokio 1.40.0
rust toolchain 1.83.0-nightly (9e394f551 2024-09-25)
Platform
Linux invar 6.10.10 #1-NixOS SMP PREEMPT_DYNAMIC Thu Sep 12 09:13:13 UTC 2024 x86_64 GNU/Linux
Description
I tried this code:
with
When running
cargo clippy --tests -- -Dclippy::needless_return
I expected to see this happen: [no warnings]
Instead, this happened:
By expanding macros via
cargo rustc -- -Zunpretty=expanded
, the warning seens correct: the generated code contains a needless "return" expression at trailing position, and there is no explicit#[allow(..)]
. It seems thereturn
here can be trivially removed?It also reproduces on
#[tokio::test]
.The text was updated successfully, but these errors were encountered: