Skip to content

Commit

Permalink
Use #[macro_export(local_inner_macros)]
Browse files Browse the repository at this point in the history
This fixes issue #10, allowing importing the macros in Rust 2018
  • Loading branch information
nvzqz committed Nov 15, 2018
1 parent 8125bcb commit c2dd597
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/assert_eq_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() -> () = || {
Expand All @@ -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>;)+
Expand Down Expand Up @@ -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),+);
Expand Down
6 changes: 3 additions & 3 deletions src/assert_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
/// assert_fields!(Range<u32>, 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)]
Expand All @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/assert_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() -> () = || {
Expand All @@ -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),+ $(,)*) => {
{
Expand Down
6 changes: 3 additions & 3 deletions src/assert_obj_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;)+
Expand All @@ -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;)+
Expand Down
8 changes: 4 additions & 4 deletions src/const_assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),+ $(,)*) => {
Expand All @@ -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)]
Expand Down Expand Up @@ -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),+);
Expand Down

0 comments on commit c2dd597

Please sign in to comment.