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
use remove_macro_call;
let mut n = 2;
reorder_statements!
// 2*2+2 = 6
assert_eq!;
// The new variable shadows the old one
let mut n = 2;
n += 2;
n *= 2;
// (2+2)*2 = 8
assert_eq!;
// The new variable shadows the old one
let mut n = 2;
reorder_statements!
// (2+2)*2 = 8
assert_eq!;
However, with cfg_attr
attribute 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
use unconst_trait_impl;
use ;
use remove_macro_call;
// Since ZST is both Eq and and PartialEq, it has structural match
// https://github.com/rust-lang/rust/issues/63438
;
unconst_trait_impl!
// 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.
unconst_trait_impl!
Note: In the real code, the example above could be replaced with a simpler version relying on cfg_aliases
crate.
Real-world examples:
You can learn more about const_trait_impl
here: