Description
@ngg ran into some weird bugs and made an awesome reduction which boils down to:
#[proc_macro]
pub fn buggy_macro(_: TokenStream) -> TokenStream {
TokenNode::Literal(Literal::i32(-1)).into()
}
It turns out that when expanding this rustc will print out:
error: int literal is too large
Originating from here I think that this is actually a misdiagnosed error in the sense that the parse is failing because the string is "-1"
which isn't parseable as a u128
, but the current code assumes that it can only fail due to overflow. Generally this is correct because the parser never feeds minus signs to this function!
So the broader issue here I believe is that Literal::i32
can't actually exist. Our parser, as-is today, (and tokenizer?) dictates that the source string -1
is lexed as two tokens, the minus and then the 1
. This means that Literal::i32
pretending it can only be one token isn't actually right!
Should we remove Literal::i32
and all other signed functions? If so should we also panic on negative floats? If not, should we refactor the AST to support literal tokens with negative integers?
cc @jseyfried, @dtolnay, @nrc