]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/move-fragments-2.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / test / compile-fail / move-fragments-2.rs
1 // Copyright 2014-2015 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 // Test that we correctly compute the move fragments for a fn.
12 //
13 // Note that the code below is not actually incorrect; the
14 // `rustc_move_fragments` attribute is a hack that uses the error
15 // reporting mechanisms as a channel for communicating from the
16 // internals of the compiler.
17
18 // These are checking that enums are tracked; note that their output
19 // paths include "downcasts" of the path to a particular enum.
20
21 #![feature(rustc_attrs)]
22
23 use self::Lonely::{Zero, One, Two};
24
25 pub struct D { d: isize }
26 impl Drop for D { fn drop(&mut self) { } }
27
28 pub enum Lonely<X,Y> { Zero, One(X), Two(X, Y) }
29
30 #[rustc_move_fragments]
31 pub fn test_match_partial(p: Lonely<D, D>) {
32 //~^ ERROR parent_of_fragments: `$(local p)`
33 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
34 match p {
35 Zero => {}
36 _ => {}
37 }
38 }
39
40 #[rustc_move_fragments]
41 pub fn test_match_full(p: Lonely<D, D>) {
42 //~^ ERROR parent_of_fragments: `$(local p)`
43 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
44 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::One)`
45 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Two)`
46 match p {
47 Zero => {}
48 One(..) => {}
49 Two(..) => {}
50 }
51 }
52
53 #[rustc_move_fragments]
54 pub fn test_match_bind_one(p: Lonely<D, D>) {
55 //~^ ERROR parent_of_fragments: `$(local p)`
56 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
57 //~| ERROR parent_of_fragments: `($(local p) as Lonely::One)`
58 //~| ERROR moved_leaf_path: `($(local p) as Lonely::One).#0`
59 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Two)`
60 //~| ERROR assigned_leaf_path: `$(local data)`
61 match p {
62 Zero => {}
63 One(data) => {}
64 Two(..) => {}
65 }
66 }
67
68 #[rustc_move_fragments]
69 pub fn test_match_bind_many(p: Lonely<D, D>) {
70 //~^ ERROR parent_of_fragments: `$(local p)`
71 //~| ERROR assigned_leaf_path: `($(local p) as Lonely::Zero)`
72 //~| ERROR parent_of_fragments: `($(local p) as Lonely::One)`
73 //~| ERROR moved_leaf_path: `($(local p) as Lonely::One).#0`
74 //~| ERROR assigned_leaf_path: `$(local data)`
75 //~| ERROR parent_of_fragments: `($(local p) as Lonely::Two)`
76 //~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#0`
77 //~| ERROR moved_leaf_path: `($(local p) as Lonely::Two).#1`
78 //~| ERROR assigned_leaf_path: `$(local left)`
79 //~| ERROR assigned_leaf_path: `$(local right)`
80 match p {
81 Zero => {}
82 One(data) => {}
83 Two(left, right) => {}
84 }
85 }
86
87 pub fn main() { }