Skip to content

Float patterns: an arm with -0.0 is skipped when the guard of an earlier 0.0 arm fails (wrong arm since 1.79) #165311

Description

@leeewee

I tried this code:

#![forbid(unsafe_code)]

#[inline(never)]
fn f(x: f64, b: bool) -> u8 {
    match x {
        0.0 if b => 1,
        -0.0 => 2, // must match whenever x == -0.0, i.e. for x = 0.0 and x = -0.0
        _ => 3,
    }
}

fn main() {
    let r0 = f(0.0, false);
    let r1 = f(-0.0, false);
    println!("f(0.0, false) = {r0}, f(-0.0, false) = {r1}  (expected 2, 2)");
    assert_eq!((r0, r1), (2, 2), "wrong match arm");
}

Expected: 2, 2.

Actual: 3, 3, and the assertion fails.

Likely regressor (by reading the diff; not bisected): #122459 "match lowering: sort Eq candidates in the failure case too" (merged 2024-03-31, released in 1.79).

  • Before: the arm was (TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val }) if test_val == case_val => Success. A candidate with a different constant was left unsorted, so it was still tried after a failed guard.
  • After: if test_val == case_val { Success } else { Failure }.

LLM disclosure: found by an LLM-driven analysis.

Meta

rustc 1.99.0 (b940084d7 2026-09-28)
rustc 1.100.0-beta.5 (8ea38001b 2026-10-13)
rustc 1.101.0-nightly (92ffebece 2026-10-28)

Activity

  1. added
    C-bug
    on Nov 2, 2026
  2. added
    needs-triage
    on Nov 2, 2026
  3. Jules-Bertholet commented on Nov 2, 2026

    @Jules-Bertholet
    Contributor

    @rustbot label A-patterns A-floating-point I-miscompile regression-from-stable-to-stable

    @Nadrieril

  4. added
    A-floating-point
    A-patterns
    I-miscompile
    regression-from-stable-to-stable
    I-prioritize
    on Nov 2, 2026
  5. Jules-Bertholet commented on Nov 2, 2026

    @Jules-Bertholet
    Contributor

    Bisection confirms an April Fool's regression:

    ********************************************************************************
    Regression in nightly-2024-04-01
    ********************************************************************************
    
    get_commits_between returning commits, len: 15
      commit[0] 2024-03-30: Auto merge of #99322 - GKFX:const-int-parse, r=Mark-Simulacrum
      commit[1] 2024-03-30: Auto merge of #123085 - tgross35:f16-f128-step4.0-libs-basic-impls, r=Amanieu
      commit[2] 2024-03-30: Auto merge of #3432 - RalfJung:gc-stress, r=RalfJung
      commit[3] 2024-03-30: Auto merge of #3434 - RalfJung:stacked-borrows-cache-consistency, r=RalfJung
      commit[4] 2024-03-31: Auto merge of #123181 - stepancheg:pointee-metadata-debug, r=the8472,Amanieu
      commit[5] 2024-03-31: Auto merge of #122459 - Nadrieril:sort-eq, r=oli-obk
      commit[6] 2024-03-31: Auto merge of #123233 - devnexen:thread_get_name_bsd, r=joboet
      commit[7] 2024-03-31: Auto merge of #3435 - rust-lang:rustup-2024-03-31, r=saethlin
      commit[8] 2024-03-31: Auto merge of #123236 - klensy:tracing-tree-bump, r=Mark-Simulacrum
      commit[9] 2024-03-31: Auto merge of #123258 - lnicola:sync-from-ra, r=lnicola
      commit[10] 2024-03-31: Auto merge of #123264 - matthiaskrgr:rollup-smyy7j9, r=matthiaskrgr
      commit[11] 2024-03-31: Auto merge of #123246 - Kobzol:tarball-reproducible, r=Mark-Simulacrum
      commit[12] 2024-03-31: Auto merge of #121851 - michaelwoerister:mcp-533-effective-vis, r=cjgillot
      commit[13] 2024-03-31: Auto merge of #123266 - RalfJung:catch-panic, r=workingjubilee
      commit[14] 2024-03-31: Auto merge of #123299 - workingjubilee:rollup-2z8amaj, r=workingjubilee
    
  6. removed
    needs-triage
    on Nov 2, 2026
  7. Nadrieril commented on Nov 2, 2026

    @Nadrieril
    Member

    Welp, I see myself in there, gotta be #122459

  8. removed
    I-prioritize
    on Nov 2, 2026
  9. rustbot commented on Nov 2, 2026

    @rustbot
    Collaborator

    Assigning P-medium (discussion on Zulip)

  10. added
    P-medium
    on Nov 2, 2026
  11. added
    S-found-by-fuzzing
    on Nov 3, 2026
  12. added 3 commits that reference this issue on Nov 24, 2026
    37ef5ea
    fb9521e
    083e743
  13. added a commit that references this issue on Nov 24, 2026
    f80d53d
  14. added a commit that references this issue on Nov 25, 2026
    71f4149
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

    A-floating-pointA-patternsC-bugI-miscompileP-mediumS-found-by-fuzzingregression-from-stable-to-stable

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions