-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't