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