Skip to content
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

semicolon-if-nothing-returned false positive with tokio macro #7438

Closed
flisky opened this issue Jul 6, 2021 · 7 comments · Fixed by tokio-rs/tokio#4067
Closed

semicolon-if-nothing-returned false positive with tokio macro #7438

flisky opened this issue Jul 6, 2021 · 7 comments · Fixed by tokio-rs/tokio#4067
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion

Comments

@flisky
Copy link

flisky commented Jul 6, 2021

Lint name: semicolon-if-nothing-returned

I tried this code:

#[tokio::test]
async fn test_ok() {
    assert!(true);
}

Instead, this happened:

   |
nn |         assert!(true);
   |         ^^^^^^^^^^^^^^ help: add a `;` here: `assert!(true);;`
   |
   = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned

Meta

  • cargo clippy -V: clippy 0.1.55 (952fdf2a 2021-07-05)
  • rustc -Vv:
rustc 1.55.0-nightly (952fdf2a1 2021-07-05)
binary: rustc
commit-hash: 952fdf2a1119affa1b37bcacb0c49cf9f0168ac8
commit-date: 2021-07-05
host: x86_64-apple-darwin
release: 1.55.0-nightly
LLVM version: 12.0.1
@flisky flisky added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 6, 2021
@giraffate
Copy link
Contributor

I tried it on the playground, but couldn't reproduce that warning. Can you provide reproduction on the playground?

@flisky
Copy link
Author

flisky commented Jul 12, 2021

Sorry, I cannot reproduce this on playground, either. However, it's reproduced on a simple cargo project -

  • create a project: cargo new semicolon
  • add tokio dependency: tokio = { version = "*", features = ["macros", "rt-multi-thread", "time"] }
  • add the following to main.rs:
#![warn(clippy::semicolon_if_nothing_returned)]

#[tokio::main]
async fn main() {
    assert!(true);
}

output:

warning: consider adding a `;` to the last statement for consistent formatting
 --> src/main.rs:5:5
  |
5 |     assert!(true);
  |     ^^^^^^^^^^^^^^ help: add a `;` here: `assert!(true);;`
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::semicolon_if_nothing_returned)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned

warning: `assert!(true)` will be optimized out by the compiler
 --> src/main.rs:5:5
  |
5 |     assert!(true);
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::assertions_on_constants)]` on by default
  = help: remove it
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
  = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 2 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 1.11s

@giraffate
Copy link
Contributor

Thanks, I can reproduce it!

$ rustc -V
rustc 1.55.0-nightly (7a16cfcff 2021-07-11)
$ cargo clippy -V
clippy 0.1.55 (7a16cfcf 2021-07-11)

@giraffate
Copy link
Contributor

Reproduction on the playground.

@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Jul 13, 2021
@c0va23
Copy link

c0va23 commented Aug 24, 2021

I face with same issue when update tokio-macros from version 1.1.0 to 1.2.0 or 1.3.0.

$ cargo clippy --version
clippy 0.1.54 (a178d03 2021-07-26)

c0va23 added a commit to c0va23/tokio that referenced this issue Aug 24, 2021
Since clippy 0.1.54 macros tokio::test and tokio::main trigger
clippy::semicolon_if_nothing_returned on func with () return type.

Adding semicolon to end generated func wrappers fix it.

Fixes: rust-lang/rust-clippy#7438
c0va23 added a commit to c0va23/tokio that referenced this issue Aug 24, 2021
Beginning from version 0.1.54 (or earlier)
`clippy::semicolon_if_nothing_returned` braked by macroses `tokio::test`
and `tokio::main` on functions without result type.

Adding semicolon into function wrappers fix it.

Fixes: rust-lang/rust-clippy#7438
c0va23 added a commit to c0va23/tokio that referenced this issue Aug 25, 2021
Beginning from version 0.1.54 (or earlier)
`clippy::semicolon_if_nothing_returned` braked by macroses `tokio::test`
and `tokio::main` on functions without result type.

Adding semicolon into function wrappers fix it.

Fixes: rust-lang/rust-clippy#7438
c0va23 added a commit to c0va23/tokio that referenced this issue Aug 25, 2021
Beginning from version 0.1.54 (or earlier)
`clippy::semicolon_if_nothing_returned` braked by macroses `tokio::test`
and `tokio::main` on functions without result type.

Adding semicolon into function wrappers fix it.

Fixes: rust-lang/rust-clippy#7438
@c0va23
Copy link

c0va23 commented Aug 25, 2021

The problem occurs because the macros tokio:: main and tokio::test wrap functions and the last expressions are always not terminated with a semicolon.

I will try to fix this problem on the tokio-macros side (tokio-rs/tokio#4067), but this problem is not specific to tokio. It looks like a fix on the clippy side is also necessary.

c0va23 added a commit to c0va23/tokio that referenced this issue Aug 25, 2021
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
c0va23 added a commit to c0va23/tokio that referenced this issue Aug 25, 2021
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
c0va23 added a commit to c0va23/tokio that referenced this issue Aug 25, 2021
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
@phansch phansch added the T-macros Type: Issues with macros and macro expansion label Aug 26, 2021
PurpleBooth added a commit to PurpleBooth/git-moves-together that referenced this issue Sep 1, 2021
@giraffate
Copy link
Contributor

I'm closing this because reproduction seemed to fixed.

If anyone have a problem related to this, new issue can be opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants