-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Make tokio-macros attributes more IDE friendly #4162
Conversation
impl LGTM. Could you add a short comment about why this trick is necessary? (because this is not a common pattern) |
There is an alternative to the above implementation, which seems even better: First, move this entire thing into a new function that returns a tokio/tokio-macros/src/entry.rs Lines 193 to 281 in f0cb360
Then, if the call to the method fails, we simply run the rest of the macro using a dummy config such as This way, the macro output is much closer to what it would be without the error. |
That is definitely an even better approach 👍 |
It seems like the |
Please avoid force pushing the PR. It makes it difficult for me to see what has changed since I last looked at the PR. |
Sorry, a habit from another repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. If it also passes CI, then we can merge it.
@Veykril Did you try whether your change actually makes rust-analyzer happy? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this improvement
Hey! This is still happening, unfortunately! rust version pub struct Environment {
pub name: String,
}
use example::Environment;
#[tokio::test]
async fn my_test() {
let mut env = Environment {
name: String::from("example")
};
} and [package]
name = "example"
version = "0.1.0"
edition = "2024"
[dependencies]
tokio = { version = "1.44.1", features = ["full"] } Trying to access // Recursive expansion of test macro
// ==================================
#[::core::prelude::v1::test]
fn my_test() {
let body = async {
let mut env = Environment {
name: String::from("example"),
};
};
let mut body = body;
#[allow(unused_mut)]
let mut body = unsafe { tokio::macros::support::Pin::new_unchecked(&mut body) };
let body: ::core::pin::Pin<&mut dyn ::core::future::Future<Output = ()>> = body;
#[allow(
clippy::expect_used,
clippy::diverging_sub_expression,
clippy::needless_return
)]
{
return tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(body);
}
} The completion works under the async block where |
Motivation
Fixes #4154
Solution
As outlined in the aforementioned issue, in case the attribute fails its expansion for whatever reason, it now emits the input item alongside the
compile_error!
macro invocation to keep the item alive for IDE analysis.