Attribute macro that removes a call of a function-like macro

In a vaccum, remove_macro_call [attribute] is fairly useless because unconditional application of #[remove_macro_call] [attribute] to either declarative or procedural function-like macros yields the same result as writing only the code inside of the enclosing punctuation (parentheses, braces, or square brackets).

Example

```rust use removemacrocall::removemacrocall;

macrorules! reorderstatements { ($s1:stmt; $s2:stmt;) => { $s2; $s1; }; }

let mut n = 2; reorder_statements! { n += 2; n *= 2; }

// 2*2+2 = 6 assert_eq!(n, 6);

// The new variable shadows the old one let mut n = 2;

n += 2; n *= 2;

// (2+2)*2 = 8 assert_eq!(n, 8);

// The new variable shadows the old one let mut n = 2;

[removemacrocall]

reorder_statements! { n += 2; n *= 2; }

// (2+2)*2 = 8 assert_eq!(n, 8); ```

However, with cfg_attr remove_macro_call allows one to remove macro calls conditionally. One important application of such combination is providing support for stable toolchain while also providing functionality relying on Nightly features.

Example

```rust, ignore

![cfgattr(feature = "consttraitimpl", feature(consttrait_impl))]

![cfgattr(feature = "constdefaultimpls", feature(constdefault_impls))]

![cfgattr(feature = "constfntraitbound", feature(constfntrait_bound))]

[cfg(not(all(

feature = "const_trait_impl",
feature = "const_default_impls",
feature = "const_fn_trait_bound"

)))] use consttraitimpl::unconsttraitimpl; use core::{default::Default, marker::PhantomData};

[cfg(all(

feature = "const_trait_impl",
feature = "const_default_impls",
feature = "const_fn_trait_bound"

))] use removemacrocall::removemacrocall;

// Since ZST is both Eq and and PartialEq, it has structural match // https://github.com/rust-lang/rust/issues/63438

[derive(Clone, Debug, Hash, Eq, Ord, PartialEq, PartialOrd, Copy)]

pub struct ZST(PhantomData);

pub trait TraitName {}

[cfg_attr(

all(
    feature = "const_trait_impl",
    feature = "const_default_impls",
    feature = "const_fn_trait_bound"
),
remove_macro_call

)] unconsttraitimpl! { impl const TraitName for ZST {} }

// With cargo build --features const_trait_impl, const_default_impls, const_fn_trait_bound // or with `cargo build --all-features, the code below is expanded as is. Otherwise, // it gets "unconsted" to be supported by stable toolchain.

[cfg_attr(

all(
    feature = "const_trait_impl",
    feature = "const_default_impls",
    feature = "const_fn_trait_bound"
),
remove_macro_call

)] unconsttraitimpl! { impl const Default for ZST { fn default() -> Self { ZST(Default::default()) } } } ```

Note: In the real code, the example above could be replaced with a simpler version relying on cfg_aliases crate.

You can learn more about const_trait_impl here: * GitHub * crates.io

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.