]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-visible-private-types.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / test / compile-fail / lint-visible-private-types.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 #![feature(struct_variant)]
12 #![deny(visible_private_types)]
13 #![allow(dead_code)]
14 #![crate_type="lib"]
15
16 struct Private<T>;
17 pub struct Public<T>;
18
19 impl Private<Public<int>> {
20     pub fn a(&self) -> Private<int> { fail!() }
21     fn b(&self) -> Private<int> { fail!() }
22
23     pub fn c() -> Private<int> { fail!() }
24     fn d() -> Private<int> { fail!() }
25 }
26 impl Private<int> {
27     pub fn e(&self) -> Private<int> { fail!() }
28     fn f(&self) -> Private<int> { fail!() }
29 }
30
31 impl Public<Private<int>> {
32     pub fn a(&self) -> Private<int> { fail!() }
33     fn b(&self) -> Private<int> { fail!() }
34
35     pub fn c() -> Private<int> { fail!() } //~ ERROR private type in exported type signature
36     fn d() -> Private<int> { fail!() }
37 }
38 impl Public<int> {
39     pub fn e(&self) -> Private<int> { fail!() } //~ ERROR private type in exported type signature
40     fn f(&self) -> Private<int> { fail!() }
41 }
42
43 pub fn x(_: Private<int>) {} //~ ERROR private type in exported type signature
44
45 fn y(_: Private<int>) {}
46
47
48 pub struct Foo {
49     x: Private<int>, //~ ERROR private type in exported type signature
50     priv y: Private<int>
51 }
52
53 struct Bar {
54     x: Private<int>,
55 }
56
57 pub enum Baz {
58     Baz1(Private<int>), //~ ERROR private type in exported type signature
59     Baz2 {
60         x: Private<int>, //~ ERROR private type in exported type signature
61         priv y: Private<int>
62     },
63
64     priv Baz3(Private<int>),
65     priv Baz4 {
66         x: Private<int>,
67     }
68 }
69
70 enum Qux {
71     Qux1(Private<int>),
72     Qux2 {
73         x: Private<int>,
74     }
75 }
76
77 pub trait PubTrait {
78     fn foo(&self) -> Private<int> { fail!( )} //~ ERROR private type in exported type signature
79     fn bar(&self) -> Private<int>; //~ ERROR private type in exported type signature
80     fn baz() -> Private<int>; //~ ERROR private type in exported type signature
81 }
82
83 impl PubTrait for Public<int> {
84     fn bar(&self) -> Private<int> { fail!() }
85     fn baz() -> Private<int> { fail!() }
86 }
87 impl PubTrait for Public<Private<int>> {
88     fn bar(&self) -> Private<int> { fail!() }
89     fn baz() -> Private<int> { fail!() }
90 }
91
92 impl PubTrait for Private<int> {
93     fn bar(&self) -> Private<int> { fail!() }
94     fn baz() -> Private<int> { fail!() }
95 }
96 impl PubTrait for (Private<int>,) {
97     fn bar(&self) -> Private<int> { fail!() }
98     fn baz() -> Private<int> { fail!() }
99 }
100
101
102 trait PrivTrait {
103     fn foo(&self) -> Private<int> { fail!( )}
104     fn bar(&self) -> Private<int>;
105 }
106 impl PrivTrait for Private<int> {
107     fn bar(&self) -> Private<int> { fail!() }
108 }
109 impl PrivTrait for (Private<int>,) {
110     fn bar(&self) -> Private<int> { fail!() }
111 }
112
113 pub trait ParamTrait<T> {
114     fn foo() -> T;
115 }
116
117 impl ParamTrait<Private<int>> //~ ERROR private type in exported type signature
118    for Public<int> {
119     fn foo() -> Private<int> { fail!() }
120 }
121
122 impl ParamTrait<Private<int>> for Private<int> {
123     fn foo() -> Private<int> { fail!( )}
124 }
125
126 impl<T: ParamTrait<Private<int>>>  //~ ERROR private type in exported type signature
127      ParamTrait<T> for Public<i8> {
128     fn foo() -> T { fail!() }
129 }