rust-lang / rust-lang/rust-clippy
Lint for large error types
@Y-Nak is already working on this.
Since Feb 24, 2021.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warn when an error type (probably by detecting that it has impl std::error::Error and is publicly exported) is over some arbitrary threshold, suggesting boxing the inner data to reduce the size.
Categories (optional)
- Kind:
clippy::perf
Large error types result in a lot of redundant memory copying on the success path when the Ok value is small.
Drawbacks
None.
Example
struct Error {
data: [u8; 512],
}
impl std::error::Error for Error {}
Could be written as:
struct Error {
data: Box<[u8; 512]>,
}
impl std::error::Error for Error {}
Other
There are two existing related issues: https://github.com/rust-lang/rust-clippy/issues/4652 and https://github.com/rust-lang/rust-clippy/issues/3884. I think this is different because in those cases it detects when you use the error internally with a small success variant; whereas even if internally all usage is with large success variants, a user of the library may be mapping the success variant to something small, ending up hitting one of those lints in their usage and having to box the whole error; while it would be easier for all users if the size was reduced at the source.
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.
Assessment
This issue has not been assessed yet.