Skip to content

Formatting float ranges may result in invalid code #6869

@ur-fault

Description

@ur-fault

Formatting float ranges with lower bound specified without decimal part leads to invalid Rust code.

Summary

I tried to format this code:

fn main() {
    let x = 0.5;

    match x {
        1. .. => println!("{x} >= 1"),
        _ => println!("{x} < 1"),
    }
}

Expected behavior

Nothing to happen, since the code is already formatted correctly.

Actual behavior

rustfmt formatted 1. .. as 1....

Configuration

Just default options.

Reproduction Steps

Just format the code.

Meta

rustfmt --version:

rustfmt 1.9.0-nightly (7af3402cda 2026-04-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-matchesArea: match arms, patterns, blocks, etcC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEF-impacts-stable-default-formatExpected formatting impact: affects stable default format configuration (caution)I-invalid-codeIssue: formatting causes compile-pass code to compile-failS-has-mcveStatus: a Minimal Complete and Verifiable Example has been found for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions