33// - replace `impl Error` by `impl Item::description`
44// - $imeta
55
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.
610#[ 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) ]
720#[ doc( hidden) ]
821macro_rules! impl_error_chain_kind {
922 ( $( #[ $meta: meta] ) *
@@ -272,18 +285,18 @@ macro_rules! impl_error_chain_kind {
272285 { display( $self_: tt) -> ( $( $exprs: tt ) * ) $( $tail: tt ) * }
273286 ) => {
274287 |impl_error_chain_kind!( IDENT $self_) : & $name, f: & mut :: std:: fmt:: Formatter | {
275- write !( f, $( $exprs ) * )
288+ write_internal !( f, $( $exprs ) * )
276289 }
277290 } ;
278291 ( FIND_DISPLAY_IMPL $name: ident $item: ident: $imode: tt
279292 { display( $pattern: expr) $( $tail: tt ) * }
280293 ) => {
281- |_, f: & mut :: std:: fmt:: Formatter | { write !( f, $pattern) }
294+ |_, f: & mut :: std:: fmt:: Formatter | { write_internal !( f, $pattern) }
282295 } ;
283296 ( FIND_DISPLAY_IMPL $name: ident $item: ident: $imode: tt
284297 { display( $pattern: expr, $( $exprs: tt ) * ) $( $tail: tt ) * }
285298 ) => {
286- |_, f: & mut :: std:: fmt:: Formatter | { write !( f, $pattern, $( $exprs ) * ) }
299+ |_, f: & mut :: std:: fmt:: Formatter | { write_internal !( f, $pattern, $( $exprs ) * ) }
287300 } ;
288301 ( FIND_DISPLAY_IMPL $name: ident $item: ident: $imode: tt
289302 { $t: tt $( $tail: tt ) * }
@@ -296,7 +309,7 @@ macro_rules! impl_error_chain_kind {
296309 { }
297310 ) => {
298311 |self_: & $name, f: & mut :: std:: fmt:: Formatter | {
299- write !( f, "{}" , self_. description( ) )
312+ write_internal !( f, "{}" , self_. description( ) )
300313 }
301314 } ;
302315 ( FIND_DESCRIPTION_IMPL $item: ident: $imode: tt $me: ident $fmt: ident
@@ -317,7 +330,7 @@ macro_rules! impl_error_chain_kind {
317330 [ $( $var: ident ) ,* ]
318331 { }
319332 ) => {
320- stringify !( $item)
333+ stringify_internal !( $item)
321334 } ;
322335 ( ITEM_BODY $( #[ $imeta: meta] ) * $item: ident: UNIT
323336 ) => { } ;
0 commit comments