]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/move-fragments-2.rs
Update compile fail tests to use isize.
[rust.git] / src / test / compile-fail / move-fragments-2.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 // 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 use self::Lonely::{Zero, One, Two};
22
23 pub struct D { d: isize }
24 impl Drop for D { fn drop(&mut self) { } }
25
26 pub enum Lonely<X,Y> { Zero, One(X), Two(X, Y) }
27
28 #[rustc_move_fragments]
29 pub fn test_match_partial(p: Lonely<D, D>) {
30     //~^ ERROR                 parent_of_fragments: `$(local p)`
31     //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)`
32     match p {
33         Zero(..) => {}
34         _ => {}
35     }
36 }
37
38 #[rustc_move_fragments]
39 pub fn test_match_full(p: Lonely<D, D>) {
40     //~^ ERROR                 parent_of_fragments: `$(local p)`
41     //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)`
42     //~| ERROR                  assigned_leaf_path: `($(local p) as One)`
43     //~| ERROR                  assigned_leaf_path: `($(local p) as Two)`
44     match p {
45         Zero(..) => {}
46         One(..) => {}
47         Two(..) => {}
48     }
49 }
50
51 #[rustc_move_fragments]
52 pub fn test_match_bind_one(p: Lonely<D, D>) {
53     //~^ ERROR                 parent_of_fragments: `$(local p)`
54     //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)`
55     //~| ERROR                 parent_of_fragments: `($(local p) as One)`
56     //~| ERROR                     moved_leaf_path: `($(local p) as One).#0`
57     //~| ERROR                  assigned_leaf_path: `($(local p) as Two)`
58     //~| ERROR                  assigned_leaf_path: `$(local data)`
59     match p {
60         Zero(..) => {}
61         One(data) => {}
62         Two(..) => {}
63     }
64 }
65
66 #[rustc_move_fragments]
67 pub fn test_match_bind_many(p: Lonely<D, D>) {
68     //~^ ERROR                 parent_of_fragments: `$(local p)`
69     //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)`
70     //~| ERROR                 parent_of_fragments: `($(local p) as One)`
71     //~| ERROR                     moved_leaf_path: `($(local p) as One).#0`
72     //~| ERROR                  assigned_leaf_path: `$(local data)`
73     //~| ERROR                 parent_of_fragments: `($(local p) as Two)`
74     //~| ERROR                     moved_leaf_path: `($(local p) as Two).#0`
75     //~| ERROR                     moved_leaf_path: `($(local p) as Two).#1`
76     //~| ERROR                  assigned_leaf_path: `$(local left)`
77     //~| ERROR                  assigned_leaf_path: `$(local right)`
78     match p {
79         Zero(..) => {}
80         One(data) => {}
81         Two(left, right) => {}
82     }
83 }
84
85 pub fn main() { }