Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
0xBACD opened this issue Jun 3, 2022 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@0xBACD
Copy link

0xBACD commented Jun 3, 2022

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.

@0xBACD 0xBACD added the C-bug Category: This is a bug. label Jun 3, 2022
@compiler-errors
Copy link
Member

In this position, std::fmt::Debug is not meant to be a type. It's meant to be a trait, which is parsed differently than a type.

Have you tried using the path macro fragment?

@0xBACD
Copy link
Author

0xBACD commented Jun 4, 2022

Yeah, it seems I just misread the reference. Actually it says that ty only matches to trait objects and impl trait so compiler behaviour here seems legit. Thank you, @compiler-errors!

@0xBACD 0xBACD closed this as completed Jun 4, 2022
@petrochenkov
Copy link
Contributor

FWIW, this will work once #96724 and subsequent PRs land (maybe not very soon).
std::fmt::Debug will be treated as just an "untyped" token stream then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants