From c2dd5970b079b74cde07b3ee6bd93078382b5046 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Thu, 15 Nov 2018 14:56:16 -0500 Subject: [PATCH] Use #[macro_export(local_inner_macros)] This fixes issue #10, allowing importing the macros in Rust 2018 --- CHANGELOG.md | 3 +++ src/assert_eq_size.rs | 8 ++++---- src/assert_fields.rs | 6 +++--- src/assert_impl.rs | 6 +++--- src/assert_obj_safe.rs | 6 +++--- src/const_assert.rs | 8 ++++---- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b453c50..fbae3d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic Versioning]. ## [Unreleased] +### Fixed +- Macros that refer to other internal macros can now be imported when compiling +for Rust 2018 ([issue #10](https://github.com/nvzqz/static-assertions-rs/issues/10)) ## [0.3.0] - 2018-11-14 ### Changed diff --git a/src/assert_eq_size.rs b/src/assert_eq_size.rs index 1e06e32..6196ae7 100644 --- a/src/assert_eq_size.rs +++ b/src/assert_eq_size.rs @@ -51,14 +51,14 @@ /// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html /// [`u64`]: https://doc.rust-lang.org/std/primitive.u64.html /// [`u32`]: https://doc.rust-lang.org/std/primitive.u32.html -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! assert_eq_size { ($($xs:tt)+) => { _assert_eq_size!($($xs)+); }; } #[doc(hidden)] #[cfg(feature = "nightly")] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_eq_size { ($x:ty, $($xs:ty),+ $(,)*) => { const _: fn() -> () = || { @@ -69,7 +69,7 @@ macro_rules! _assert_eq_size { #[doc(hidden)] #[cfg(not(feature = "nightly"))] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_eq_size { ($x:ty, $($xs:ty),+ $(,)*) => { $(let _ = $crate::_core::mem::transmute::<$x, $xs>;)+ @@ -158,7 +158,7 @@ macro_rules! assert_eq_size_ptr { /// ``` /// /// [`Clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! assert_eq_size_val { ($x:expr, $($xs:expr),+ $(,)*) => { assert_eq_size_ptr!(&$x, $(&$xs),+); diff --git a/src/assert_fields.rs b/src/assert_fields.rs index 3597ef4..eb573b2 100644 --- a/src/assert_fields.rs +++ b/src/assert_fields.rs @@ -51,14 +51,14 @@ /// assert_fields!(Range, middle); /// # } /// ``` -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! assert_fields { ($($xs:tt)+) => { _assert_fields!($($xs)+); }; } #[doc(hidden)] #[cfg(feature = "nightly")] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_fields { ($t:path, $($f:ident),+) => { #[allow(unknown_lints, unneeded_field_pattern)] @@ -70,7 +70,7 @@ macro_rules! _assert_fields { #[doc(hidden)] #[cfg(not(feature = "nightly"))] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_fields { ($t:path, $($f:ident),+) => { #[allow(unknown_lints, unneeded_field_pattern)] diff --git a/src/assert_impl.rs b/src/assert_impl.rs index aa4d19d..356a326 100644 --- a/src/assert_impl.rs +++ b/src/assert_impl.rs @@ -43,14 +43,14 @@ /// [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html /// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html /// [blanket]: https://doc.rust-lang.org/book/second-edition/ch10-02-traits.html#using-trait-bounds-to-conditionally-implement-methods -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! assert_impl { ($($xs:tt)+) => { _assert_impl!($($xs)+); }; } #[doc(hidden)] #[cfg(feature = "nightly")] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_impl { ($x:ty, $($t:path),+ $(,)*) => { const _: fn() -> () = || { @@ -62,7 +62,7 @@ macro_rules! _assert_impl { #[doc(hidden)] #[cfg(not(feature = "nightly"))] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_impl { ($x:ty, $($t:path),+ $(,)*) => { { diff --git a/src/assert_obj_safe.rs b/src/assert_obj_safe.rs index 861959d..e245be7 100644 --- a/src/assert_obj_safe.rs +++ b/src/assert_obj_safe.rs @@ -75,14 +75,14 @@ /// ``` /// /// [object]: https://doc.rust-lang.org/book/2018-edition/ch17-02-trait-objects.html#object-safety-is-required-for-trait-objects -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! assert_obj_safe { ($($xs:tt)+) => { _assert_obj_safe!($($xs)+); }; } #[doc(hidden)] #[cfg(feature = "nightly")] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_obj_safe { ($($xs:ty),+ $(,)*) => { $(const _: Option<&$xs> = None;)+ @@ -91,7 +91,7 @@ macro_rules! _assert_obj_safe { #[doc(hidden)] #[cfg(not(feature = "nightly"))] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _assert_obj_safe { ($($xs:ty),+ $(,)*) => { $(let _: &$xs;)+ diff --git a/src/const_assert.rs b/src/const_assert.rs index 6cad307..f2d76a7 100644 --- a/src/const_assert.rs +++ b/src/const_assert.rs @@ -50,14 +50,14 @@ /// ``` /// /// [static_assert]: http://en.cppreference.com/w/cpp/language/static_assert -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! const_assert { ($($xs:tt)+) => { _const_assert!($($xs)+); }; } #[doc(hidden)] #[cfg(feature = "nightly")] -#[macro_export] +#[macro_export(local_inner_macros)] #[allow(dead_code)] macro_rules! _const_assert { ($($xs:expr),+ $(,)*) => { @@ -68,7 +68,7 @@ macro_rules! _const_assert { #[doc(hidden)] #[cfg(not(feature = "nightly"))] -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! _const_assert { ($($xs:expr),+ $(,)*) => { #[allow(unknown_lints, eq_op)] @@ -107,7 +107,7 @@ macro_rules! _const_assert { /// const_assert_eq!(4 + 4, 4 * 4); /// # } /// ``` -#[macro_export] +#[macro_export(local_inner_macros)] macro_rules! const_assert_eq { ($x:expr, $($xs:expr),+ $(,)*) => { const_assert!($($x == $xs),+);