Skip to content

"< is interpreted as a start of generic arguments for '_', not a comparison" #44406

Closed

Description

Playground link: https://play.rust-lang.org/?gist=e93b00dd6c33bf6bbcc035a7be501592&version=stable

macro_rules! foo {
    (
        $(
            bar: {
                $($rest:tt)+
            }
        )+
    ) => {
        $(
            bar($($rest)+);
        )+
    };
}

macro_rules! bar {
    (baz: $baz:expr,) => {};
}

fn main() {
    foo!{
        bar: {
            baz: true,
        }
    }
}
Compiling playground v0.0.1 (file:///playground)
error: expected identifier, found keyword `true`
  --> src/main.rs:24:18
   |
24 |             baz: true,
   |                  ^^^^

error: `<` is interpreted as a start of generic arguments for `true`, not a comparison
  --> src/main.rs:24:22
   |
24 |             baz: true,
   |                      -
   |                      |
   |                      not interpreted as comparison
   |                      interpreted as generic arguments
   |
help: if you want to compare the casted value then write:
   |
24 |             (baz: true),
   |             ^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Activity

  1. kennytm commented on Sep 8, 2017

    @kennytm
    Member

    I guess the problem is treating true as the name of a type. Simplified:

    macro_rules! foo {
        ($rest:tt) => {
            bar(baz: $rest)
        }
    }
    fn main() {
        foo!(true);
    }
    Look at this mess
    Standard Error
    
       Compiling playground v0.0.1 (file:///playground)
    error: expected identifier, found keyword `true`
     --> src/main.rs:8:10
      |
    8 |     foo!(true);
      |          ^^^^
    
    error: `<` is interpreted as a start of generic arguments for `true`, not a comparison
     --> src/main.rs:3:23
      |
    3 |           bar(baz: $rest)
      |                         -
      |                         |
      |  _______________________not interpreted as comparison
      | |
    4 | |     }
    5 | | }
    6 | |
    7 | | fn main() {
    8 | |     foo!(true);
      | |     -----------
      | |_____|_______|
      |       |       interpreted as generic arguments
      |       in this macro invocation
      |
    help: if you want to compare the casted value then write:
      |
    3 |         bar((baz: $rest)
    4 |     }
    5 | }
    6 | 
    7 | fn main() {
    8 |     foo!(true));
      |
    
    error: aborting due to 2 previous errors
    
    error: Could not compile `playground`.
    
    To learn more, run the command again with --verbose.
    

    cc @petrochenkov #43060

  2. added
    A-parserArea: The lexing & parsing of Rust source code to an AST
    on Sep 8, 2017
  3. self-assigned this
    on Sep 8, 2017
  4. petrochenkov commented on Sep 8, 2017

    @petrochenkov
    Contributor

    Thanks!
    #43060 does some shady things.
    I tried to come up with an example where it would fail, but without success, now here it is!

  5. added
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 8, 2017
  6. added a commit that references this issue on Feb 15, 2021
  7. added 2 commits that reference this issue on Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions