Skip to content

struct order of eval is (still) not well #23112

Closed
@pnkfelix

Description

Executive summary:

This code fails in its assertion:

struct S { f0: String, _f1: u32 }

pub fn main() {
    const HI: &'static str = "Hello, world!";
    let s = HI.to_string();
    let s = S {
        f0: s.to_string(),
        ..S {
            f0: s,
            _f1: 23
        }
    };
    assert_eq!(HI, s.f0);
}

playpen link


Longer fun story:

You might think from our test suite that struct literal order of evaluation is being tested.

E.g. there are the two tests:

However, misbehavior I witnessed on my filling-drop work (namely, usize overflows, which I believe were signaled solely due to the recently landed arithmetic overflow work) led me to investigate these tests more closely.

Neither of them have assert! nor assert_eq! calls!

So essentially all we are testing in these two tests is that

  1. the borrow checker does not complain, and
  2. the resulting code does not segfault at runtime!

I.e., Very weak testing! (And also, totally bogus dynamic semantics.)

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions