-
-
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
macros: Improve IDE support #6968
base: master
Are you sure you want to change the base?
Conversation
I will send a fix tomorrow. |
What’s really blocking the CI is that, Current changes preserved async body as-is: #[tokio::main]
async fn test_with_semicolon_without_return_type() {
#![deny(clippy::semicolon_if_nothing_returned)]
#[deny(clippy::semicolon_if_nothing_returned)]
0;
} So would convert into: fn test_with_semicolon_without_return_type() {
let body = async {
#![deny(clippy::semicolon_if_nothing_returned)] // ❌
#[deny(clippy::semicolon_if_nothing_returned)]
0;
};
...
} I didn’t realize this, The previous implementation moved global inner attributes outside: #[deny(clippy::semicolon_if_nothing_returned)]
fn test_with_semicolon_without_return_type() {
let body = async {
#[deny(clippy::semicolon_if_nothing_returned)]
0;
};
...
} There are many ways to address this issue. |
If you believe the output changes are acceptable, you can update the outputs to make the tests pass. See But keep in mind that just because something is not explained in the documentation, that doesn't mean we can just change it. We don't want to break existing users of the macro. |
Speaking as a person who works on rust-analyzer:
|
Oh! It turns out span is used for type suggestion in return or end statements, so I'll revert the previous change. Seems like it also fix some code suggestion: #3766 |
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! Changes to parse_knobs and ItemFn looks generally good to me.
@@ -112,10 +112,28 @@ error: second test attribute is supplied, consider removing or changing the orde | |||
64 | #[std::prelude::rust_2021::test] | |||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |||
|
|||
error: second test attribute is supplied, consider removing or changing the order of your test attributes |
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.
It seems that the double tokio::test attribute are now allowed?
tokio/tests-build/tests/fail/macros_invalid_input.rs
Lines 67 to 68 in d08578f
#[tokio::test] | |
#[tokio::test] |
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.
[tokio::test]
attribute are now allowed ?
No user will receive a hard error as before. but the error message is slightly different.
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.
Hmm, which is the new warning for this test function? The old version of the stderr file has an error referring to L67, but the new version has no error referring to L67-L69, which this test function contains.
@@ -389,19 +390,118 @@ fn build_config( | |||
config.build() | |||
} | |||
|
|||
fn fn_without_args(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenStream { |
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.
I think this is wrong when code contains Self
keyword. (see also #6306 (comment))
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.
fn method(self) { ... }
fn method(self: ..) { ... }
Theself
keyword is considered a function argument. And will fallback to async closure. Here is a test case for it.
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.
I'm talking about Self
that starts with an uppercase letter, not all lowercase self
.
For example:
impl MyStruct {
#[tokio::main]
async fn func() {
let mut this = Self::defalt();
// ^^^^
// ...
}
}
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.
Aha! So in this case, we have to fallback to async block.
tokio-macros/src/entry.rs
Outdated
fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenStream { | ||
input.sig.asyncness = None; | ||
if is_test || input.sig.inputs.is_empty() && !has_self_keyword(input.body.clone().into_iter()) { |
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.
I think the cases where Self
is included in the return type, generics, or where clause will still be missed.
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.
I should be fine. We don't need to fallback to async block, If generics or return position contain Self
keyword.
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.
No. For example, the following conversion is incorrect:
impl MyStruct {
// From:
// #[tokio::main]
// async fn func() -> Self { todo!() }
//
// To:
fn func() -> Self {
async fn func() -> Self { todo!() }
let body = func();
// ...
}
}
error[E0401]: can't use `Self` from outer item
--> src/lib.rs:9:28
|
2 | impl MyStruct {
| ---- `Self` type implicitly declared here, by this `impl`
...
9 | async fn func() -> Self { todo!() }
| ^^^^
| |
| use of `Self` from outer item
| refer to the type directly here instead
This refectory improve performance and enhance better compatibility with IDEs.
Here is two examples,
Before: Note that there is no inlay hints for function arguments.
After: Fixed inlay hint hints problem.
channel(buffer: ..
,tokio::spawn(future: ..
Before: On syntax error.
Run Test | Debug
button dissipated. which is frustrating because the editor toggles back and forth while typing.After: It fix that.
It introduce two changes:
Removespaned
, Because as it's not meant to be used here.