Skip to content

<$t:ty> falls victim to C++ >> ambiguity #37175

Closed
@durka

Description

@durka

Consider this macro:

macro_rules! m { (<$t:ty>) => { stringify!($t) } }

Unfortunately it can't deal with a type that ends in >:

m!(<Vec<i32>>)
error: no rules expected the token `>>`
 --> .cargo/.cargo/script-cache/expr-edcce559d98013ba/expr.rs:5:64
  |
5 | {macro_rules! m { (<$t:ty>) => { stringify!($t) } } m!(<Vec<i32>>)}
  |                                                                ^^

error: Could not compile `expr`.

Is it possible to fix this? It seems to me the macro parser should know it's parsing $t:ty and therefore >> can't be valid, so it should be split into two tokens.

cc @jseyfried

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions