]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/moves-sru-moved-field.rs
Imported Upstream version 0.6
[rustc.git] / src / test / compile-fail / moves-sru-moved-field.rs
1 type Noncopyable = ~fn();
2
3 struct Foo {
4 copied: int,
5 moved: ~int,
6 noncopyable: Noncopyable
7 }
8
9 fn test0(f: Foo, g: Noncopyable, h: Noncopyable) {
10 // just copy implicitly copyable fields from `f`, no moves:
11 let _b = Foo {moved: ~1, noncopyable: g, ..f};
12 let _c = Foo {moved: ~2, noncopyable: h, ..f};
13 }
14
15 fn test1(f: Foo, g: Noncopyable, h: Noncopyable) {
16 // copying move-by-default fields from `f`, so move:
17 let _b = Foo {noncopyable: g, ..f};
18 let _c = Foo {noncopyable: h, ..f}; //~ ERROR use of moved value: `f`
19 }
20
21 fn test2(f: Foo, g: Noncopyable) {
22 // move non-copyable field
23 let _b = Foo {copied: 22, moved: ~23, ..f};
24 let _c = Foo {noncopyable: g, ..f}; //~ ERROR use of moved value: `f`
25 }
26
27 fn main() {}