@@ -65,20 +65,13 @@ macro_rules! impl_error_chain_processed {
65
65
/// - a backtrace, generated when the error is created.
66
66
/// - an error chain, used for the implementation of `Error::cause()`.
67
67
#[ derive( Debug ) ]
68
- pub struct $error_name(
69
- // The members must be `pub` for `links`.
70
- /// The kind of the error.
71
- pub $error_kind_name,
72
- /// Contains the error chain and the backtrace.
73
- #[ doc( hidden) ]
74
- pub $crate:: State ,
75
- ) ;
68
+ pub struct $error_name( pub Box <( $error_kind_name, $crate:: State ) >) ;
76
69
77
70
impl $crate:: ChainedError for $error_name {
78
71
type ErrorKind = $error_kind_name;
79
72
80
73
fn new( kind: $error_kind_name, state: $crate:: State ) -> $error_name {
81
- $error_name( kind, state)
74
+ $error_name( Box :: new ( ( kind, state) ) )
82
75
}
83
76
84
77
fn from_kind( kind: Self :: ErrorKind ) -> Self {
@@ -120,10 +113,10 @@ macro_rules! impl_error_chain_processed {
120
113
impl $error_name {
121
114
/// Constructs an error from a kind, and generates a backtrace.
122
115
pub fn from_kind( kind: $error_kind_name) -> $error_name {
123
- $error_name(
116
+ $error_name( Box :: new ( (
124
117
kind,
125
118
$crate:: State :: default ( ) ,
126
- )
119
+ ) ) )
127
120
}
128
121
129
122
/// Constructs a chained error from another error and a kind, and generates a backtrace.
@@ -140,15 +133,15 @@ macro_rules! impl_error_chain_processed {
140
133
-> $error_name
141
134
where K : Into <$error_kind_name>
142
135
{
143
- $error_name(
136
+ $error_name( Box :: new ( (
144
137
kind. into( ) ,
145
138
$crate:: State :: new:: <$error_name>( error, ) ,
146
- )
139
+ ) ) )
147
140
}
148
141
149
142
/// Returns the kind of the error.
150
143
pub fn kind( & self ) -> & $error_kind_name {
151
- & self . 0
144
+ & ( self . 0 ) . 0
152
145
}
153
146
154
147
/// Iterates over the error chain.
@@ -158,7 +151,7 @@ macro_rules! impl_error_chain_processed {
158
151
159
152
/// Returns the backtrace associated with this error.
160
153
pub fn backtrace( & self ) -> Option <& $crate:: Backtrace > {
161
- self . 1 . backtrace( )
154
+ ( self . 0 ) . 1 . backtrace( )
162
155
}
163
156
164
157
/// Extends the error chain with a new entry.
@@ -170,7 +163,7 @@ macro_rules! impl_error_chain_processed {
170
163
/// A short description of the error.
171
164
/// This method is identical to [`Error::description()`](https://doc.rust-lang.org/nightly/std/error/trait.Error.html#tymethod.description)
172
165
pub fn description( & self ) -> & str {
173
- self . 0 . description( )
166
+ ( self . 0 ) . 0 . description( )
174
167
}
175
168
}
176
169
@@ -181,10 +174,10 @@ macro_rules! impl_error_chain_processed {
181
174
182
175
#[ allow( unknown_lints, unused_doc_comment) ]
183
176
fn cause( & self ) -> Option <& :: std:: error:: Error > {
184
- match self . 1 . next_error {
177
+ match ( self . 0 ) . 1 . next_error {
185
178
Some ( ref c) => Some ( & * * c) ,
186
179
None => {
187
- match self . 0 {
180
+ match ( self . 0 ) . 0 {
188
181
$(
189
182
$( #[ $meta_foreign_links] ) *
190
183
$error_kind_name:: $foreign_link_variant( ref foreign_err) => {
@@ -200,18 +193,19 @@ macro_rules! impl_error_chain_processed {
200
193
201
194
impl :: std:: fmt:: Display for $error_name {
202
195
fn fmt( & self , f: & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result {
203
- :: std:: fmt:: Display :: fmt( & self . 0 , f)
196
+ :: std:: fmt:: Display :: fmt( & ( self . 0 ) . 0 , f)
204
197
}
205
198
}
206
199
207
200
$(
208
201
$( #[ $meta_links] ) *
209
202
impl From <$link_error_path> for $error_name {
210
203
fn from( e: $link_error_path) -> Self {
211
- $error_name(
204
+ let e = * e. 0 ;
205
+ $error_name( Box :: new( (
212
206
$error_kind_name:: $link_variant( e. 0 ) ,
213
207
e. 1 ,
214
- )
208
+ ) ) )
215
209
}
216
210
}
217
211
) *
@@ -245,7 +239,6 @@ macro_rules! impl_error_chain_processed {
245
239
}
246
240
}
247
241
248
-
249
242
// The ErrorKind type
250
243
// --------------
251
244
@@ -303,7 +296,7 @@ macro_rules! impl_error_chain_processed {
303
296
304
297
impl From <$error_name> for $error_kind_name {
305
298
fn from( e: $error_name) -> Self {
306
- e . 0
299
+ ( e . 0 ) . 0
307
300
}
308
301
}
309
302
@@ -425,13 +418,13 @@ macro_rules! impl_extract_backtrace {
425
418
fn extract_backtrace( e: & ( :: std:: error:: Error + Send + ' static ) )
426
419
-> Option <$crate:: InternalBacktrace > {
427
420
if let Some ( e) = e. downcast_ref:: <$error_name>( ) {
428
- return Some ( e . 1 . backtrace. clone( ) ) ;
421
+ return Some ( ( e . 0 ) . 1 . backtrace. clone( ) ) ;
429
422
}
430
423
$(
431
424
$( #[ $meta_links] ) *
432
425
{
433
426
if let Some ( e) = e. downcast_ref:: <$link_error_path>( ) {
434
- return Some ( e . 1 . backtrace. clone( ) ) ;
427
+ return Some ( ( e . 0 ) . 1 . backtrace. clone( ) ) ;
435
428
}
436
429
}
437
430
) *
0 commit comments