rust-lang / rust-lang/rust-clippy
New lint to validate that E in public Result<_, E> implements std::error::Error
Open
@Serial-ATA is already working on this.
Since Oct 12, 2021.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
For public functions that return a Result<_, E> where E is not (), it should warn if E does not implement std::error::Error. Inspired by https://github.com/rustls/rustls/pull/837.
When propagating errors across crate boundaries, you almost always want to be able to propagate errors, and usually this works best if the error type implements Error.
Categories (optional)
- Kind: style, I guess?
Drawbacks
More code to write; might not be useful in all contexts; might apply only in library code.
Example
#[derive(Debug)]
pub struct SignError(());
Could be written as:
#[derive(Debug)]
pub struct SignError(());
impl fmt::Display for SignError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("sign error")
}
}
impl StdError for SignError {}
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.