Skip to content

Breaking change in macro_rules ty fragment parsing in version 1.68 #107796

Closed
@zakarumych

Description

@zakarumych

I tried this code:

macro_rules! impl_primitive {
    ($ty:ty) => { impl_primitive!(impl $ty);};
    (impl $ty:ty) => { fn a(_: $ty) {} }
}

impl_primitive! { u8 }

link to playground

I expected to see this happen:
Macro is expanded to fn a(_: u8) {}

Instead, this happened:
On stable 1.67 it works as expected.
On beta 1.68 and nightly 1.69 it fails with the following error

error: expected a trait, found type
 --> src/lib.rs:6:19
  |
2 |     ($ty:ty) => { impl_primitive!(impl $ty);};
  |      ------ while parsing argument for this `ty` macro fragment
...
6 | impl_primitive! { u8 }
  |                   ^^

It is probably caused by ty fragment that now treats impl as a start of impl Trait type.
So makes sense. But breaks existing code :)

Metadata

Metadata

Labels

C-bugCategory: This is a bug.P-highHigh priorityregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions