Skip to content

rustc macro: unexpected compilation error when ty designator is used within where clause #97719

Closed
@0xBACD

Description

@0xBACD

This code doesn't seem to compile with the following error [playground]:

macro_rules! foo {
    ($t:ty) => {
        fn bar<T>(_: T) where T: $t {}
    }
}

foo!(std::fmt::Debug);
error: expected one of `!`, `(`, `,`, `?`, `for`, `{`, `~`, lifetime, or path, found `std::fmt::Debug`
 --> src/main.rs:3:34
  |
3 |         fn bar<T>(_: T) where T: $t {}
  |                                  ^^ expected one of 9 possible tokens
...
7 | foo!(std::fmt::Debug);
  | --------------------- in this macro invocation
  |
  = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)

There should be no error since ty designator stands for type, std::fmt::Debug is definitely a type and where clause accepts trait types.
This problem persists on any channel I've tested it - stable, beta and nightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions