Skip to content

regression: tagged-box macro fails on :ty pattern when a later pattern would match #146417

@cuviper

Description

@cuviper

Found in 1.90-beta crater run #145758, e.g. https://crater-reports.s3.amazonaws.com/beta-1.90-3/beta-2025-08-22/reg/caro-0.7.1/log.txt

[INFO] [stdout] error: expected `;` or `]`, found `:`
[INFO] [stdout]    --> /opt/rustwide/cargo-home/registry/src/index.crates.io-1949cf8c6b5b557f/tagged-box-0.1.1/src/tagged_box.rs:484:17
[INFO] [stdout]     |
[INFO] [stdout] 484 | impl_fmt!(impl[T: TaggableInner] TaggedBox<T> => LowerHex, UpperHex, Binary, Octal);
[INFO] [stdout]     |                 ^ expected `;` or `]`
[INFO] [stdout]     |
[INFO] [stdout]    ::: /opt/rustwide/cargo-home/registry/src/index.crates.io-1949cf8c6b5b557f/tagged-box-0.1.1/src/lib.rs:213:6
[INFO] [stdout]     |
[INFO] [stdout] 213 |     ($ty:ty => $($fmt:ident),+) => {
[INFO] [stdout]     |      ------ while parsing argument for this `ty` macro fragment
[INFO] [stdout]     |
[INFO] [stdout]     = note: you might have meant to write a slice or array type

Code

Here's an isolated reproducer (playground):

macro_rules! foo {
    ($ty:ty) => { dbg!("ty") };
    (impl [foo] $ty:ty) => { "foo" };
    (impl [T: Foo] $ty:ty) => { "T: Foo" };
}

fn main() {
    dbg!(foo!(i32));
    dbg!(foo!(impl [foo] i32));
    dbg!(foo!(impl [T: Foo] i32));
}

I expected to see this happen: builds and prints the 3 different strings

Instead, this happened:

error: expected a trait, found type
 --> src/main.rs:9:20
  |
2 |     ($ty:ty) => { dbg!("ty") };
  |      ------ while parsing argument for this `ty` macro fragment
...
9 |     dbg!(foo!(impl [foo] i32));
  |                    ^^^^^

error: expected `;` or `]`, found `:`
  --> src/main.rs:10:22
   |
 2 |     ($ty:ty) => { dbg!("ty") };
   |      ------ while parsing argument for this `ty` macro fragment
...
10 |     dbg!(foo!(impl [T: Foo] i32));
   |                      ^ expected `;` or `]`
   |
   = note: you might have meant to write a slice or array type

Version it worked on

It most recently worked on: 1.89

Version with regression

rustc --version --verbose:

rustc 1.90.0-beta.7 (fb918cec0 2025-08-29)
binary: rustc
commit-hash: fb918cec013920472f6975b2009b0339d9e8cc9c
commit-date: 2025-08-29
host: x86_64-unknown-linux-gnu
release: 1.90.0-beta.7
LLVM version: 20.1.8

Bisecting identified d41e12f, of which I suspect the [const] Trait #139858, i.e. trying to parse the :ty as an impl [const] Trait here.

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-criticalCritical priorityS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions