`Error` impls seem to require unneccessary bounds
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
When trying to use the errors in certain ways, I get errors with certain error frameworks because simple things will not enable the `Error` impls such as
```
impl Error for SizeError
where
Src: Deref
Dst: KnownLayout+ ?Sized
```
Are these bounds really needed? It causes issues where I can't propogate errors in simple cases:
```rust
use std::error::Error;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned, LE, U32};
#[derive(
Debug, Clone, Copy, Hash, PartialEq, Eq, FromBytes, IntoBytes, KnownLayout, Immutable, Unaligned,
)]
#[repr(C)]
pub struct Test {
pub test: U32,
}
fn impls_err(_err: impl Error) {}
fn main() {
let mut buf = vec![0u8; 32];
let buf = &mut buf;
impls_err(Test::ref_from_bytes(&buf[..4]).unwrap_err().map_src(drop));
}
```
which gives the error
```
error[E0277]: the trait bound `(): Deref` is not satisfied
--> src/main.rs:19:15
|
19 | impls_err(Test::ref_from_bytes(&buf[..4]).unwrap_err().map_src(drop));
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deref` is not implemented for `()`, which is required by `ConvertError, SizeError<(), Test>, Infallible>: std::error::Error`
| |
| required by a bound introduced by this call
|
= help: the trait `std::error::Error` is implemented for `ConvertError`
= note: required for `AlignmentError<(), Test>` to implement `std::fmt::Display`
= note: required for `ConvertError, SizeError<(), Test>, Infallible>` to implement `std::error::Error`
note: required by a bound in `impls_err`
--> src/main.rs:13:25
|
13 | fn impls_err(_err: impl Error) {}
| ^^^^^ required by this bound in `impls_err`
```
There are other impls that have the same problem
Contributor guide
Assessment
This issue has not been assessed yet.