| 1 |
#![allow(clippy::extra_unused_type_parameters)] |
| 2 |
|
| 3 |
use std::io; |
| 4 |
use thiserror::Error; |
| 5 |
|
| 6 |
#[derive(Error, Debug)] |
| 7 |
#[error("...")] |
| 8 |
pub struct ErrorStruct { |
| 9 |
#[from] |
| 10 |
source: io::Error, |
| 11 |
} |
| 12 |
|
| 13 |
#[derive(Error, Debug)] |
| 14 |
#[error("...")] |
| 15 |
pub struct ErrorStructOptional { |
| 16 |
#[from] |
| 17 |
source: Option<io::Error>, |
| 18 |
} |
| 19 |
|
| 20 |
#[derive(Error, Debug)] |
| 21 |
#[error("...")] |
| 22 |
pub struct ErrorTuple(#[from] io::Error); |
| 23 |
|
| 24 |
#[derive(Error, Debug)] |
| 25 |
#[error("...")] |
| 26 |
pub struct ErrorTupleOptional(#[from] Option<io::Error>); |
| 27 |
|
| 28 |
#[derive(Error, Debug)] |
| 29 |
#[error("...")] |
| 30 |
pub enum ErrorEnum { |
| 31 |
Test { |
| 32 |
#[from] |
| 33 |
source: io::Error, |
| 34 |
}, |
| 35 |
} |
| 36 |
|
| 37 |
#[derive(Error, Debug)] |
| 38 |
#[error("...")] |
| 39 |
pub enum ErrorEnumOptional { |
| 40 |
Test { |
| 41 |
#[from] |
| 42 |
source: Option<io::Error>, |
| 43 |
}, |
| 44 |
} |
| 45 |
|
| 46 |
#[derive(Error, Debug)] |
| 47 |
#[error("...")] |
| 48 |
pub enum Many { |
| 49 |
Any(#[from] anyhow::Error), |
| 50 |
Io(#[from] io::Error), |
| 51 |
} |
| 52 |
|
| 53 |
fn assert_impl<T: From<io::Error>>() {} |
| 54 |
|
| 55 |
#[test] |
| 56 |
fn test_from() { |
| 57 |
assert_impl::<ErrorStruct>(); |
| 58 |
assert_impl::<ErrorStructOptional>(); |
| 59 |
assert_impl::<ErrorTuple>(); |
| 60 |
assert_impl::<ErrorTupleOptional>(); |
| 61 |
assert_impl::<ErrorEnum>(); |
| 62 |
assert_impl::<ErrorEnumOptional>(); |
| 63 |
assert_impl::<Many>(); |
| 64 |
} |