-
-
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: fix wrong error messages #4067
Conversation
I'm not sure that this problem should be solved on the But this change made it possible to update 'tokio-macros' without disabling 'clippy::semicolon_if_nothing_returned' on my project. I will try to add tests for this problem. For now, I want to open a discussion to understand on which side the problem should be solved (clippy or tokio). |
Honestly, I would prefer if this was fixed on the clippy side. |
15e3972
to
244bc50
Compare
/* TODO(taiki-e): one of help messages still wrong | ||
help: consider using a semicolon here | ||
| | ||
16 | return Ok(());; | ||
| | ||
*/ | ||
return Ok(()); | ||
} | ||
|
||
#[tokio::main] | ||
async fn extra_semicolon() -> Result<(), ()> { | ||
/* TODO(taiki-e): help message still wrong | ||
help: try using a variant of the expected enum | ||
| | ||
29 | Ok(Ok(());) | ||
| | ||
29 | Err(Ok(());) | ||
| | ||
*/ |
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.
@taiki-e, i removed these todos, because maybe I fixed them. Correct me if I'm wrong.
I found tests in which it was planned to make similar changes. And I redid the PR. Instead of adding a semicolon if the function does not have a result type. I check whether the last expression in the function body had a semicolon, and if so, I check whether this expression was 'return'. |
244bc50
to
4206e37
Compare
Since this improves some existing bad error messages, I'm more positive for accepting this version. Can you add some tests that look like this? #[tokio::main]
async fn main() -> Result<(), ()> {
return Ok(());
}
#[tokio::main]
async fn main() -> Result<(), ()> {
loop {
}
} It's ok if they don't have great error messages. |
@Darksonn, I will add such tests and fix the fallen tests (locally I ran tests on the latest version of the changes and they passed, but they fell on CI). I think that it will still be necessary to correct the description of the PR, so that it better reflects the reason for these changes. |
4206e37
to
1664480
Compare
1664480
to
b8682d8
Compare
The macros `tokio::main` and `tokio::test` return invalid error messages if the function being wrapped has no return value. This was because the semicolon from the last statement was missing. Also, since version 0.1.54 (or earlier), `clippy::semicolon_if_nothing_returned` triggered false-negative when using the macros `tokio::test` and `tokio::main` on functions without a result type. We can copy the semicolon and the `return` keyword from the last statement from the body of the wrapped function. Fixes: rust-lang/rust-clippy#7438
b8682d8
to
9990139
Compare
@Darksonn, i add this tests and fix filed tests. And i update subject and description for PR and commit message. |
Ah, actually, I think the tests I wanted was more like this: #[tokio::main]
async fn main() {
return Ok(());
}
#[tokio::main]
async fn main() {
loop {
return Ok(());
}
} I wanted to see what the error messages were in these cases. Sorry about posting the wrong version. |
This test already exists tokio/tests-build/tests/fail/macros_type_mismatch.rs Lines 8 to 11 in 9990139
Second test tokio/tests-build/tests/pass/macros_main_loop.rs Lines 4 to 10 in 9990139
|
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 not sure what I wanted with the tests then. I must have confused myself. The PR looks good as is.
@Darksonn, thanks a lot for helping with this PR. |
Motivation
The macros
tokio::main
andtokio::test
return invalid error messages if the function being wrapped has no return value. This was because the semicolon from the last statement was missing.Also, since version 0.1.54 (or earlier),
clippy::semicolon_if_nothing_returned
triggered false-negative when using the macrostokio::test
andtokio::main
on functions without a result type.Fixes: rust-lang/rust-clippy#7438
Solution
We can copy the semicolon and the
return
keyword from the laststatement from the body of the wrapped function.