]> git.proxmox.com Git - rustc.git/blob - vendor/thiserror/tests/test_error.rs
fab934d7893f76bc8d42819f4ecdd102c365235a
[rustc.git] / vendor / thiserror / tests / test_error.rs
1 #![allow(dead_code)]
2
3 use std::fmt::{self, Display};
4 use std::io;
5 use thiserror::Error;
6
7 macro_rules! unimplemented_display {
8 ($ty:ty) => {
9 impl Display for $ty {
10 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
11 unimplemented!()
12 }
13 }
14 };
15 }
16
17 #[derive(Error, Debug)]
18 struct BracedError {
19 msg: String,
20 pos: usize,
21 }
22
23 #[derive(Error, Debug)]
24 struct TupleError(String, usize);
25
26 #[derive(Error, Debug)]
27 struct UnitError;
28
29 #[derive(Error, Debug)]
30 struct WithSource {
31 #[source]
32 cause: io::Error,
33 }
34
35 #[derive(Error, Debug)]
36 struct WithAnyhow {
37 #[source]
38 cause: anyhow::Error,
39 }
40
41 #[derive(Error, Debug)]
42 enum EnumError {
43 Braced {
44 #[source]
45 cause: io::Error,
46 },
47 Tuple(#[source] io::Error),
48 Unit,
49 }
50
51 unimplemented_display!(BracedError);
52 unimplemented_display!(TupleError);
53 unimplemented_display!(UnitError);
54 unimplemented_display!(WithSource);
55 unimplemented_display!(WithAnyhow);
56 unimplemented_display!(EnumError);