Skip to content

Option<f64>::Some behaves incorrectly in 64-bit host #9730

@lifthrasiir

Description

@lifthrasiir

Minimal example:

fn f() { assert!(false); }
struct A(f64);
struct B { x: Option<A> }
fn main() { let mut t = B { x: None }; t.x = Some(A(100.0)); println(fmt!("%?", t.x)); }

This should print Some(A(100f64)), but in 64-bit host (to be exact, x86_64-unknown-linux-gnu) this results in Some(A(0f64)) and behaves like that. Confirmed in 0.8 and (AFAIK) pre-0.9.

Notes:

  • The function f is nothing to do with the example, but it somehow prohibits the inlining of Some().
  • Only f64 triggers this bug. f32 or i64 does not.
  • Only tuple-like struct exhibits this bug. struct A { y: f64 } or enum A { A(f64) } does not, and the latter can be used a workaround for this bug.

It bears some resemblance with #9719 but the connection is unclear.

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