Skip to content

Reserved float literals are accepted #533

@ehuss

Description

@ehuss

Binary, octal, and hex literals immediately followed by a . (and then not followed by . _ or XID_Start) are reserved and generate a parse error, but proc-macro2 is accepting them (generally as three separate tokens).

use std::str::FromStr;

fn main() {
    for input in [
        "0b101.010",
        "0x567.89",
        "0o123.45",
    ] {
        println!("{:?}", proc_macro2::TokenStream::from_str(input));
    }
}

outputs:

Ok(TokenStream [Literal { lit: 0b101 }, Punct { char: '.', spacing: Alone }, Literal { lit: 010 }])
Ok(TokenStream [Literal { lit: 0x567 }, Punct { char: '.', spacing: Alone }, Literal { lit: 89 }])
Ok(TokenStream [Literal { lit: 0o123 }, Punct { char: '.', spacing: Alone }, Literal { lit: 45 }])

but I would expect it to be a parse error.

Checked here in the compiler. It parses them as floats, and then later checks the base.

Using proc-macro2 1.0.106.

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