Skip to content

0e+10 is invalid whereas 00e+10 is valid #40408

Description

@qnighy

I found this line in the lexer prevents 0e+10 to be parsed as a float, whereas 00e+10 is allowed anyway. Is this a bug or an intended behavior?

This is a code I tested on Rust Playground:

fn main() {
  // OK
  println!("{}", 0);
  // OK
  println!("{}", 00e+10);
  // Parse Error
  println!("{}", 0e+10);
}

It seems natural that both of them are banned or both of them are allowed.

Activity

  1. nagisa commented on Mar 10, 2017

    @nagisa
    Member

    It is a bug.

  2. nagisa commented on Mar 10, 2017

    @nagisa
    Member

    IIRC at least.

  3. nagisa commented on Mar 11, 2017

    @nagisa
    Member

    This is the relevant section in the reference: https://doc.rust-lang.org/reference.html#floating-point-literals

    It says:

    A floating-point literal has one of two forms:

    • A decimal literal followed by a period character U+002E (.). This is optionally followed by another decimal literal, with an optional exponent.
    • A single decimal literal followed by an exponent.

    and

    A decimal literal starts with a decimal digit and continues with any mixture of decimal digits and underscores.

    i.e.

    LIT_DECIMAL := DEC_DIGIT (DEC_DIGIT | "_")+
    EXPONENT := /* snip */
    LIT_FLOAT_FORM1 := LIT_DECIMAL "." [LIT_DECIMAL [EXPONENT]]
    LIT_FLOAT_FORM2 := LIT_DECIMAL EXPONENT
    LIT_FLOAT := LIT_FLOAT_FORM1 | LIT_FLOAT_FORM2
    

    so all forms should parse.

  4. added 3 commits that reference this issue on Mar 18, 2017
  5. added a commit that references this issue on Mar 19, 2017
  6. qnighy commented on Apr 28, 2017

    @qnighy
    ContributorAuthor

    I'm going to close this issue, because #40589 fixed it.

  7. added 3 commits that reference this issue on Feb 5, 2025
  8. added a commit that references this issue on Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions