Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit c238b9d

Browse files
authored
Merge pull request #253 from faern/fix-new-macro-import-style
Fix new macro import style
2 parents f1a467e + e6d0b2c commit c238b9d

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/error_chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ macro_rules! impl_error_chain_cause_or_source {
6969

7070
/// Prefer to use `error_chain` instead of this macro.
7171
#[doc(hidden)]
72-
#[macro_export]
72+
#[macro_export(local_inner_macros)]
7373
macro_rules! impl_error_chain_processed {
7474
// Default values for `types`.
7575
(
@@ -408,7 +408,7 @@ macro_rules! impl_error_chain_processed {
408408

409409
/// Internal macro used for reordering of the fields.
410410
#[doc(hidden)]
411-
#[macro_export]
411+
#[macro_export(local_inner_macros)]
412412
macro_rules! error_chain_processing {
413413
(
414414
({}, $b:tt, $c:tt, $d:tt)
@@ -461,7 +461,7 @@ macro_rules! error_chain_processing {
461461
}
462462

463463
/// Macro for generating error types and traits. See crate level documentation for details.
464-
#[macro_export]
464+
#[macro_export(local_inner_macros)]
465465
macro_rules! error_chain {
466466
( $( $block_name:ident { $( $block_content:tt )* } )* ) => {
467467
error_chain_processing! {

src/impl_error_chain_kind.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
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)]
821
macro_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
) => { };

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ macro_rules! bail {
788788
/// ```
789789
///
790790
/// See documentation for `bail!` macro for further details.
791-
#[macro_export]
791+
#[macro_export(local_inner_macros)]
792792
macro_rules! ensure {
793793
($cond:expr, $e:expr) => {
794794
if !($cond) {

0 commit comments

Comments
 (0)