Skip to content

Tracking issue for illegal_floating_point_constant_pattern compatibility lint #36890

Closed
@petrochenkov

Description

@petrochenkov

This is the summary issue for the illegal_floating_point_constant_pattern
future-compatibility warning and other related errors. The goal of
this page is describe why this change was made and how you can fix
code that is affected by it. It also provides a place to ask questions
or register a complaint if you feel the change should not be made. For
more information on the policy around future-compatibility warnings,
see our breaking change policy guidelines.

What is the warning for?

Rust 1.0 accepted a number of patterns -- and in particular accepted constant in patterns --
in a broader range of situations that was originally intended. RFC 1445 spelled out
some restrictions on what kinds of constants can be used in patterns, at least until the
final semantics are affirmatively decided. Among the changes was the ruling that floating
point values should not be usable in patterns.

This means that a match like this:

match foo() {
    3.0 => ...,
    _ => ...
}

should be written to:

match foo() {
    x if x == 3.0 => ...,
    _ => ...
}

Among other things, this clarifies that the semantics are the same as == normally uses. So e.g. 0 and -0 compare equal, and NaN compares unequal to everything (including itself).

When will this warning become a hard error?

At the beginning of each 6-week release cycle, the Rust compiler team
will review the set of outstanding future compatibility warnings and
nominate some of them for Final Comment Period. Toward the end of
the cycle, we will review any comments and make a final determination
whether to convert the warning into a hard error or remove it
entirely.

Current status

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.B-unstableBlocker: Implemented in the nightly compiler and unstable.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions