]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/use-after-move-implicity-coerced-object.rs
librustc: Don't allow use after move of implicitly coerced object. Fixes #11481.
[rust.git] / src / test / compile-fail / use-after-move-implicity-coerced-object.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 struct Number {
12     n: i64
13 }
14
15 impl ToStr for Number {
16     fn to_str(&self) -> ~str {
17         self.n.to_str()
18     }
19 }
20
21 struct List {
22     list: ~[~ToStr]
23 }
24
25 impl List {
26     fn push(&mut self, n: ~ToStr) {
27         self.list.push(n);
28     }
29 }
30
31 fn main() {
32     let n = ~Number { n: 42 };
33     let mut l = ~List { list: ~[] };
34     l.push(n);
35     //^~ NOTE: `n` moved here because it has type `~Number`, which is non-copyable (perhaps you meant to use clone()?)
36     let x = n.to_str(); //~ ERROR: use of moved value: `n`
37 }