On Tue, Mar 12, 2013 at 01:07:07PM -0400, Jack Lloyd wrote:
> If two or more struct initializers have side effects, is the order
> that they run defined?

I'm pretty sure it is, because it's actually part of the type system.
See src/test/run-pass/struct-order-of-eval-2.rs:

  struct S { f0: ~str, f1: ~str }

  pub fn main() {
      let s = ~"Hello, world!";
      let _s = S { f1: str::from_slice(s), f0: s };
  }

That compiles, but swap the order of the field initializers and:

  struct-order-of-eval-2.rs:15:44: 15:45 error: use of moved value: `s`
  struct-order-of-eval-2.rs:15     let _s = S { f0: s, f1: str::from_slice(s) };
                                                                           ^
  struct-order-of-eval-2.rs:15:21: 15:22 note: `s` moved here because it has 
type ~str, which is moved by default (use `copy` to override)
  struct-order-of-eval-2.rs:15     let _s = S { f0: s, f1: str::from_slice(s) };
                                                    ^
So it's important that the first program not be turned into the second
program after the type checking is done.

--Jed

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to