3
3
// - replace `impl Error` by `impl Item::description`
4
4
// - $imeta
5
5
6
+ // Because of the `#[macro_export(local_inner_macros)]` usage on `impl_error_chain_kind` that macro
7
+ // will only look inside this crate for macros to invoke. So using `stringify` or `write` from
8
+ // the standard library will fail. Thus we here create simple wrappers for them that are not
9
+ // exported as `local_inner_macros`, and thus they can in turn use the standard library macros.
6
10
#[ macro_export]
11
+ macro_rules! stringify_internal {
12
+ ( $( $t: tt) * ) => { stringify!( $( $t) * ) }
13
+ }
14
+ #[ macro_export]
15
+ macro_rules! write_internal {
16
+ ( $dst: expr, $( $arg: tt) * ) => ( write!( $dst, $( $arg) * ) )
17
+ }
18
+
19
+ #[ macro_export( local_inner_macros) ]
7
20
#[ doc( hidden) ]
8
21
macro_rules! impl_error_chain_kind {
9
22
( $( #[ $meta: meta] ) *
@@ -272,18 +285,18 @@ macro_rules! impl_error_chain_kind {
272
285
{ display( $self_: tt) -> ( $( $exprs: tt ) * ) $( $tail: tt ) * }
273
286
) => {
274
287
|impl_error_chain_kind!( IDENT $self_) : & $name, f: & mut :: std:: fmt:: Formatter | {
275
- write !( f, $( $exprs ) * )
288
+ write_internal !( f, $( $exprs ) * )
276
289
}
277
290
} ;
278
291
( FIND_DISPLAY_IMPL $name: ident $item: ident: $imode: tt
279
292
{ display( $pattern: expr) $( $tail: tt ) * }
280
293
) => {
281
- |_, f: & mut :: std:: fmt:: Formatter | { write !( f, $pattern) }
294
+ |_, f: & mut :: std:: fmt:: Formatter | { write_internal !( f, $pattern) }
282
295
} ;
283
296
( FIND_DISPLAY_IMPL $name: ident $item: ident: $imode: tt
284
297
{ display( $pattern: expr, $( $exprs: tt ) * ) $( $tail: tt ) * }
285
298
) => {
286
- |_, f: & mut :: std:: fmt:: Formatter | { write !( f, $pattern, $( $exprs ) * ) }
299
+ |_, f: & mut :: std:: fmt:: Formatter | { write_internal !( f, $pattern, $( $exprs ) * ) }
287
300
} ;
288
301
( FIND_DISPLAY_IMPL $name: ident $item: ident: $imode: tt
289
302
{ $t: tt $( $tail: tt ) * }
@@ -296,7 +309,7 @@ macro_rules! impl_error_chain_kind {
296
309
{ }
297
310
) => {
298
311
|self_: & $name, f: & mut :: std:: fmt:: Formatter | {
299
- write !( f, "{}" , self_. description( ) )
312
+ write_internal !( f, "{}" , self_. description( ) )
300
313
}
301
314
} ;
302
315
( FIND_DESCRIPTION_IMPL $item: ident: $imode: tt $me: ident $fmt: ident
@@ -317,7 +330,7 @@ macro_rules! impl_error_chain_kind {
317
330
[ $( $var: ident ) ,* ]
318
331
{ }
319
332
) => {
320
- stringify !( $item)
333
+ stringify_internal !( $item)
321
334
} ;
322
335
( ITEM_BODY $( #[ $imeta: meta] ) * $item: ident: UNIT
323
336
) => { } ;
0 commit comments