1 #![allow(clippy::mixed_attributes_style)]
2
3 use thiserror::Error;
4
5 pub use std::error::Error;
6
7 #[test]
test_allow_attributes()8 fn test_allow_attributes() {
9 #![deny(clippy::allow_attributes)]
10
11 #[derive(Error, Debug)]
12 #[error("...")]
13 pub struct MyError(#[from] anyhow::Error);
14
15 let _: MyError;
16 }
17
18 #[test]
test_unused_qualifications()19 fn test_unused_qualifications() {
20 #![deny(unused_qualifications)]
21
22 // Expansion of derive(Error) macro can't know whether something like
23 // std::error::Error is already imported in the caller's scope so it must
24 // suppress unused_qualifications.
25
26 #[derive(Error, Debug)]
27 #[error("...")]
28 pub struct MyError;
29
30 let _: MyError;
31 }
32
33 #[test]
test_needless_lifetimes()34 fn test_needless_lifetimes() {
35 #![allow(dead_code)]
36 #![deny(clippy::needless_lifetimes)]
37
38 #[derive(Error, Debug)]
39 #[error("...")]
40 pub enum MyError<'a> {
41 A(#[from] std::io::Error),
42 B(&'a ()),
43 }
44
45 let _: MyError;
46 }
47
48 #[test]
test_deprecated()49 fn test_deprecated() {
50 #![deny(deprecated)]
51
52 #[derive(Error, Debug)]
53 #[deprecated]
54 #[error("...")]
55 pub struct DeprecatedStruct;
56
57 #[derive(Error, Debug)]
58 #[error("{message} {}", .message)]
59 pub struct DeprecatedStructField {
60 #[deprecated]
61 message: String,
62 }
63
64 #[derive(Error, Debug)]
65 #[deprecated]
66 pub enum DeprecatedEnum {
67 #[error("...")]
68 Variant,
69 }
70
71 #[derive(Error, Debug)]
72 pub enum DeprecatedVariant {
73 #[deprecated]
74 #[error("...")]
75 Variant,
76 }
77
78 #[derive(Error, Debug)]
79 pub enum DeprecatedFrom {
80 #[error(transparent)]
81 Variant(
82 #[from]
83 #[allow(deprecated)]
84 DeprecatedStruct,
85 ),
86 }
87
88 #[allow(deprecated)]
89 let _: DeprecatedStruct;
90 #[allow(deprecated)]
91 let _: DeprecatedStructField;
92 #[allow(deprecated)]
93 let _ = DeprecatedEnum::Variant;
94 #[allow(deprecated)]
95 let _ = DeprecatedVariant::Variant;
96 }
97