# Why can't pat\_param be followed by a colon in macro\_rules?

**URL:** https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394
**Category:** language design
**Created:** [June 12, 2026, 10:23pm UTC](https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394 "2026-06-12T22:23:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![QuaternionsRock](https://avatars.discourse-cdn.com/v4/letter/q/edb3f5/32.png) [@QuaternionsRock](https://internals.rust-lang.org/u/QuaternionsRock)
#### Post date: [June 12, 2026, 10:23pm UTC](https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394/1 "2026-06-12T22:23:01Z")

</div>

I wrote [this macro](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e3444e2698319bbe0e718cd819e6be38) only to discover that `pat_param` fragments (otherwise known as [PatternNoTopAlt](https://doc.rust-lang.org/reference/patterns.html#grammar-PatternNoTopAlt)s cannot be followed by `:`s. As far as I can tell, PatternNoTopAlts cannot be terminated by a `:`. I get that there are potential forward compatibility concerns, but it is also my understanding that [StructPatternField](https://doc.rust-lang.org/reference/patterns.html#railroad-StructPatternField)s make the prospect of adding type annotations to patterns quite awkward, and I figured that the ability to match something as integral as a [`let` statement](https://doc.rust-lang.org/reference/statements.html#let-statements) would be a higher priority.

Are there any other uses of `:` in patterns being considered?

---

<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: [June 13, 2026, 12:58am UTC](https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394/2 "2026-06-13T00:58:44Z")

</div>

Given that `pat_param` is in parameters (duh) which are followed by `:` always, this seems at least plausible? I don't think we'd want to do it for `pat` in general, but for `pat_param` maybe?

---

<div class="post-metadata">

### Author: ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)
#### Post date: [June 13, 2026, 4:42am UTC](https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394/3 "2026-06-13T04:42:34Z")

</div>

My suspicion is it's a holdover from when `pat_param` was split off from `pat`, which itself (at the time) needed to handle type ascription.

---

<div class="post-metadata">

### Author: ![ekuber](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ekuber/32/1646_2.png) [@ekuber](https://internals.rust-lang.org/u/ekuber)
#### Post date: [June 13, 2026, 10:20pm UTC](https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394/4 "2026-06-13T22:20:45Z")

</div>

I would also like it if we _didn't_ lift this restriction, because I'd like to reuse top-level pattern type ascription as the syntax to obtain access to anonymous enum variants:

```rust
fn foo() -> A | B { todo!() }

match foo() {
    x: A => {}
    x: B => {}
}

```

---

<div class="post-metadata">

### Author: ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)
#### Post date: [June 13, 2026, 11:39pm UTC](https://internals.rust-lang.org/t/why-cant-pat-param-be-followed-by-a-colon-in-macro-rules/24394/5 "2026-06-13T23:39:44Z")

</div>

Yes, absolutely. But for `pat_param` specifically, I don't see any argument for keeping the restriction given that it is literally designed to be followed by `:`.
