Skip to content

Negative LitFloat seems to parse incorrectly in procedural macro #1085

@sagacity

Description

@sagacity

I have come across a weird issue in my procedural macro:

I parse a float, like so:

let float = syn::Lit::Float(syn::LitFloat::new("-10.0", Span::call_site()));

I would expect float to be: Float(LitFloat { token: - 10.0 }). However, it is Float(LitFloat { token: - 10 }) instead. This causes the code generated by my macro to miscompile, since -10 is not interpreted as a float.

Weirdly, this only happens when the parsing is done inside a procedural macro. If I do the parsing in a regular binary it works fine. I have no idea what is different about executing in a procedural macro that could cause this, and it also makes it quite hard to debug.

I have a reproduction case here. Run it with cargo run --example example and it will panic with the parsed float showing as: Float(LitFloat { token: - 10 }). I would have expected Float(LitFloat { token: - 10.0 }) instead.

I've tried this both on Rust 1.55.0 and the currently nightly, on MacOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions