rust-lang / rust-lang/rust-clippy
`expect_fun_call` recommends code which is not equivalent
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Clippy will suggest replacing:
Err::<(), _>("foo").expect(&format!("bar"))
with
Err:<(), _>("foo").unwrap_or_else(|_| panic!("bar"))
However, these are not equivalent. The first outputs foo: "bar", while the second will only output bar. Clippy could recommend doing the same formatting as expect, now we're literally recommending replacing expect with the exact body of that function. While it does of course avoid a single string allocation, it seems like a very aggressive lint to have on by default to avoid a case that is insignificant performance-wise for the vast majority of programs. format! should be white listed here IMO
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the expect_fun_call lint implementation and its existing tests. Reproduce the shown expect and unwrap_or_else outputs, then define the desired handling for format! and add a regression test demonstrating equivalent output before updating the recommendation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100