Skip to content

needless_return doesn't trigger properly with anyhow! macro #10051

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

Closed
ComputerDruid opened this issue Dec 8, 2022 · 0 comments · Fixed by #10110
Closed

needless_return doesn't trigger properly with anyhow! macro #10051

ComputerDruid opened this issue Dec 8, 2022 · 0 comments · Fixed by #10110
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@ComputerDruid
Copy link
Contributor

Summary

needless_return fails to trigger on return Err(anyhow::anyhow!("failed to do things"));

This leads to weird situations where clippy will clean up one needless return but not another, for example https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b196ba185e8485558293b61fce4f7d7c . I saw this a fair bit when running clippy --fix across the fuchsia codebase, http://fxrev.dev/c/fuchsia/+/773265/2..3 shows me manually fixing up those cases.

Lint Name

needless_return

Reproducer

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0952e8cbe8416c99f9a5b1e7c44c1c56

pub fn example() -> Result<(), anyhow::Error> {
    return Err(anyhow::anyhow!("failed to do things"));
}

I expected to see this happen:

warning: unneeded `return` statement
 --> src/lib.rs:2:5
  |
2 |     return Err("failed to do things");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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`

Instead, this happened (no errors):

    Checking playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.40s

Version

rustc 1.67.0-nightly (822f8c22f 2022-11-02)
binary: rustc
commit-hash: 822f8c22f540b12f296d844ad5bf39aaa47bfeb4
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
@ComputerDruid ComputerDruid added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Dec 8, 2022
@bors bors closed this as completed in a85e480 Jan 1, 2023
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 I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant