Closed
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);
}
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:
- /~https://github.com/rust-lang/rust/blob/master/src/test/run-pass/struct-order-of-eval-1.rs
- /~https://github.com/rust-lang/rust/blob/master/src/test/run-pass/struct-order-of-eval-2.rs
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
- the borrow checker does not complain, and
- the resulting code does not segfault at runtime!
I.e., Very weak testing! (And also, totally bogus dynamic semantics.)