PageRenderTime 70ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/compile-fail/borrowck-move-error-with-note.rs

https://github.com/paulstansifer/rust
Rust | 63 lines | 44 code | 9 blank | 10 comment | 1 complexity | 595638621b58ed814c3e936229187480 MD5 | raw file
Possible License(s): 0BSD, Apache-2.0, MIT, AGPL-1.0
  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. #![feature(box_syntax)]
  11. enum Foo {
  12. Foo1(Box<u32>, Box<u32>),
  13. Foo2(Box<u32>),
  14. Foo3,
  15. }
  16. fn blah() {
  17. let f = &Foo::Foo1(box 1, box 2);
  18. match *f { //~ ERROR cannot move out of
  19. Foo::Foo1(num1, //~ NOTE attempting to move value to here
  20. num2) => (), //~ NOTE and here
  21. Foo::Foo2(num) => (), //~ NOTE and here
  22. Foo::Foo3 => ()
  23. }
  24. }
  25. struct S {
  26. f: String,
  27. g: String
  28. }
  29. impl Drop for S {
  30. fn drop(&mut self) { println!("{}", self.f); }
  31. }
  32. fn move_in_match() {
  33. match (S {f: "foo".to_string(), g: "bar".to_string()}) {
  34. S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait
  35. f: _s, //~ NOTE attempting to move value to here
  36. g: _t //~ NOTE and here
  37. } => {}
  38. }
  39. }
  40. // from issue-8064
  41. struct A {
  42. a: Box<isize>,
  43. }
  44. fn free<T>(_: T) {}
  45. fn blah2() {
  46. let a = &A { a: box 1 };
  47. match a.a { //~ ERROR cannot move out of
  48. n => { //~ NOTE attempting to move value to here
  49. free(n)
  50. }
  51. }
  52. free(a)
  53. }
  54. fn main() {}