Nightly broke quote_tokens!(..., -1i32)?


I have some code which uses rustc_internal macros for code generation.

This code:

let val: i32 = ...;
quote_tokens!(ctxt, $val => $scope :: $tok,)

was working perfectly to generate branches of a match statement. However, since last night, if val = -1i32, then this fails with: "error: unexpected token: -1i32". It works fine if val is positive.

I can work around this by avoiding explicitly mentioning the constant -1:

quote_tokens!(ctxt, x if x == ($scope :: $tok as i32) => $scope :: $tok,)

This seems like a regression…


Looks like this is the result of I presume this means that quote_tokens!(ctx, -1i32) should be generating an AST for a unary-negation operator with the constant - but perhaps that doesn’t work in a pattern matching context?


Can rustc -Z ast-json or ast-json-noexpand be of any help to you?


Yep, I’ll take care of it on monday. Sorry about that. Do you have a fully contained example (playpen maybe?) that I could use as a testcase?


Thanks! I don’t have a standalone testcase on hand. I’ll see if I can put one together.


This is a run time error, not a compile-time one, so I don’t think that would help much.


if you have a crate I can extract a minimal example myself


It’s xdrgen on, and at github at (prior to my workaround hacks).


Oh, I think I found it… Contrary to what I thought, the compiler did in fact create signed ast literals… the circumstances are confusing to me, but apparently it did in matches, but only if those matches were created by quote_tokens.