rust-lang / rust-lang/rust-clippy
result_large_err should be relative to the Ok variant
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The current description for the lint is:
A Result is at least as large as the Err-variant. While we expect that variant to be seldomly used, the compiler needs to reserve and move that much memory every single time.
This should not be a problem if the Ok variant size is larger or not that smaller.
Lint Name
result_large_err
Reproducer
My code looks like this:
struct SomeContext<T> {
outcome: T,
// more fields
}
type SomeResult = Result<SomeContext<Good>, SomeContext<Bad>>;
In my case I believe the Good type is actually larger than the Bad one, and it is more convenient to embed the outcome in its surrounding context than embedding the context in both Good and Bad types.
It also doesn't bring any value to reference/box the context to avoid embedding it for this specific use case, it just adds one more indirection.
Version
rustc 1.66.1 (90743e729 2023-01-10) (Fedora 1.66.1-1.fc37)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
release: 1.66.1
LLVM version: 15.0.6
Additional Labels
No response
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 result_large_err lint implementation and its tests, then run the provided Rust reproducer to observe the current warning. Update the lint behavior and description so the warning is relative to the Ok variant, and confirm the Good-larger-than-Bad case is handled as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100