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

Clippy Uneeded Return #13467

Closed
cycle-five opened this issue Sep 27, 2024 · 2 comments · Fixed by #13464
Closed

Clippy Uneeded Return #13467

cycle-five opened this issue Sep 27, 2024 · 2 comments · Fixed by #13464
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@cycle-five
Copy link

Summary

⋊> lothrop@archimedes ⋊> ~/s/c/v0.3.14 on v0.3.14 ↑ cargo clippy --fix --bin "crack-voting" (base) 07:58:15
Checking crack-voting v0.3.14 (/home/lothrop/src/cracktunes.worktrees/v0.3.14/crack-voting)
warning: failed to automatically apply fixes suggested by rustc to crate crack_voting

after fixes were automatically applied the compiler reported errors within these files:

  • crack-voting/src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the --broken-code flag

The following errors were reported:
error[E0599]: no method named awaitrun found for opaque type impl std::future::Future<Output = ()> in the current scope
--> crack-voting/src/main.rs:7:11
|
7 | run().awaitrun().await;
| ^^^^^^^^ method not found in impl Future<Output = ()>

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0599.
Original diagnostics will follow.

warning: unneeded return statement
--> crack-voting/src/main.rs:7:16
|
7 | run().await;
| ^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
= note: #[warn(clippy::needless_return)] on by default
help: remove return
|
7 | run().awaitrun().await;
| ~~~~~~~~~~~~

warning: crack-voting (bin "crack-voting") generated 1 warning (run cargo clippy --fix --bin "crack-voting" to apply 1 suggestion)
Finished dev profile [unoptimized + debuginfo] target(s) in 2.87s

Reproducer

I tried this code:

<code>

I expected to see this happen:

Instead, this happened:

Version

No response

Additional Labels

No response

@cycle-five cycle-five added the C-bug Category: Clippy is not doing the correct thing label Sep 27, 2024
@barafael
Copy link

@barafael
Copy link

Duplicates #13458

@bors bors closed this as completed in 8e60f14 Oct 10, 2024
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Oct 18, 2024
Don't warn on proc macro generated code in `needless_return`

Fixes rust-lang#13458
Fixes rust-lang#13457
Fixes rust-lang#13467
Fixes rust-lang#13479
Fixes rust-lang#13481
Fixes rust-lang#13526
Fixes rust-lang#13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants