# Macro rules application in attributes

**URL:** <https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722>\
**Category:** language design\
**Created:** [November 16, 2025, 12:23pm UTC](https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722 "2025-11-16T12:23:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alrz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alrz/32/3907_2.png) [@alrz](https://internals.rust-lang.org/u/alrz)\
**Post date:** [November 16, 2025, 12:23pm UTC](https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722/1 "2025-11-16T12:23:13Z")

</div>

I find `macro_rules!` easier to work with compared to proc macros and I've seen many instances of this pattern:

```rust
macro_rules! rewrite {
	...
}

rewrite! {
  struct T { }
}

```

However, I think the attribute syntax is preferable when it comes to processing declarations:

```rust
#[rewrite]
struct T {}

```

Today, this is easy to work around: either define `rewrite` as `proc_macro_attribute` and wrap the input, or define a general proc macro `#[macro(rewrite)]` to be used for any macro rules which works but there will be some boilerplate to manage.

The idea is to make it possible to apply macro rules directly to items:

```rust
#[rewrite!]
struct T {}

```

So that you can match any kind of items in the rules one by one and rewrite.

---

<div class="post-metadata">

**Author:** ![SkiFire13](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/skifire13/32/7579_2.png) [@SkiFire13](https://internals.rust-lang.org/u/SkiFire13)\
**Post date:** [November 16, 2025, 12:38pm UTC](https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722/2 "2025-11-16T12:38:24Z")

</div>

Have you seen the RFC [3697-declarative-attribute-macros - The Rust RFC Book](https://rust-lang.github.io/rfcs/3697-declarative-attribute-macros.html)? The RFC [3698-declarative-derive-macros - The Rust RFC Book](https://rust-lang.github.io/rfcs/3698-declarative-derive-macros.html) might also be of interest to you.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kpreid/32/8484_2.png) [@kpreid](https://internals.rust-lang.org/u/kpreid)\
**Post date:** [November 16, 2025, 12:42pm UTC](https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722/3 "2025-11-16T12:42:48Z")

</div>

`#![feature(macro_attr)]`, the unstable implementation of that RFC, is usable on nightly right now.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [November 16, 2025, 9:22pm UTC](https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722/4 "2025-11-16T21:22:06Z")

</div>

> [@alrz](#):
>
> However, I think the attribute syntax is preferable when it comes to processing declarations

TBH, I think that's only true when it leaves the item alone, just adding new items.

If it's rewriting it to be something different, I'd rather the proc macros were also enclosing.

---

<div class="post-metadata">

**Author:** ![alrz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alrz/32/3907_2.png) [@alrz](https://internals.rust-lang.org/u/alrz)\
**Post date:** [November 27, 2025, 12:05am UTC](https://internals.rust-lang.org/t/macro-rules-application-in-attributes/23722/5 "2025-11-27T00:05:59Z")

</div>

This does seem like a personal preference, that's why I suggested to reuse macro syntax (with an exclamation mark) to also distinguish between macros and attributes.
