Allow numeric tokens containing 'e' that aren't exponents be passed to proc macros · Issue #111615 · rust-lang/rust (original) (raw)

I tried this code:

// This could also be a complex proc macro macro_rules! print_token { ($x:tt) => { println!("{}", stringify!($x)) } }

fn main() { print_token!(123aefg123); // ok, unknown suffix print_token!(123e123); // ok: float literal

print_token!(123ef3); // error:  expected at least one digit in exponent

}

I expected to see this happen: It should compile in print the token verbatim. If unkown/invalid suffix are OK, so should invalid float, because the macro DSL my use it for something else

Instead, this happened: Compilation error :

error: expected at least one digit in exponent
  --> src/main.rs:11:18
   |
11 |     print_token!(123ef3); // error:  expected at least one digit in exponent
   |                  ^^^^^^

(tested with Rust 1.69 as well as current nightly, this always has been a problem)

Context

This was discussed with @nnethercote and others last week and I wanted to make sure there is a track of this.

The usecase is so that Slint's color literal work in the slint! maco DSL.
Currently one can do color: #0e9 but not color:#0ea in the slint! macro. And Makepad DSL has to workaround the same issue.