1 // Copyright 2017 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.
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.
11 // This crate attempts to enumerate the various scenarios for how a
12 // type can define fields and methods with various visiblities and
15 // The basic stability pattern in this file has four cases:
16 // 1. no stability attribute at all
17 // 2. a stable attribute (feature "unit_test")
18 // 3. an unstable attribute that unit test declares (feature "unstable_declared")
19 // 4. an unstable attribute that unit test fails to declare (feature "unstable_undeclared")
21 // This file also covers four kinds of visibility: private,
22 // pub(module), pub(crate), and pub.
24 // However, since stability attributes can only be observed in
25 // cross-crate linkage scenarios, there is little reason to take the
26 // cross-product (4 stability cases * 4 visiblity cases), because the
27 // first three visibility cases cannot be accessed outside this crate,
28 // and therefore stability is only relevant when the visibility is pub
29 // to the whole universe.
31 // (The only reason to do so would be if one were worried about the
32 // compiler having some subtle bug where adding a stability attribute
33 // introduces a privacy violation. As a way to provide evidence that
34 // this is not occurring, I have put stability attributes on some
35 // non-pub fields, marked with SILLY below)
37 #![feature(staged_api)]
38 #![feature(pub_restricted)]
40 #![stable(feature = "unit_test", since = "0.0.0")]
42 #[stable(feature = "unit_test", since = "0.0.0")]
43 pub use m
::{Record, Trait, Tuple}
;
47 #[stable(feature = "unit_test", since = "0.0.0")]
49 #[stable(feature = "unit_test", since = "0.0.0")]
50 pub a_stable_pub
: i32,
51 #[unstable(feature = "unstable_declared", issue = "38412")]
52 pub a_unstable_declared_pub
: i32,
53 #[unstable(feature = "unstable_undeclared", issue = "38412")]
54 pub a_unstable_undeclared_pub
: i32,
55 #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY
56 pub(crate) b_crate
: i32,
57 #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY
59 #[stable(feature = "unit_test", since = "0.0.0")] // SILLY
64 #[stable(feature = "unit_test", since = "1.0.0")]
66 #[stable(feature = "unit_test", since = "0.0.0")]
68 #[unstable(feature = "unstable_declared", issue = "38412")]
70 #[unstable(feature = "unstable_undeclared", issue = "38412")]
78 #[stable(feature = "unit_test", since = "1.0.0")]
79 pub fn new() -> Self { Default::default() }
83 #[stable(feature = "unit_test", since = "1.0.0")]
84 pub fn new() -> Self { Default::default() }
88 #[stable(feature = "unit_test", since = "0.0.0")]
90 #[stable(feature = "unit_test", since = "0.0.0")]
92 #[stable(feature = "unit_test", since = "0.0.0")]
93 fn stable_trait_method(&self) -> Self::Type
;
94 #[unstable(feature = "unstable_undeclared", issue = "38412")]
95 fn unstable_undeclared_trait_method(&self) -> Self::Type
;
96 #[unstable(feature = "unstable_declared", issue = "38412")]
97 fn unstable_declared_trait_method(&self) -> Self::Type
;
100 #[stable(feature = "unit_test", since = "0.0.0")]
101 impl Trait
for Record
{
103 fn stable_trait_method(&self) -> i32 { self.d_priv }
104 fn unstable_undeclared_trait_method(&self) -> i32 { self.d_priv }
105 fn unstable_declared_trait_method(&self) -> i32 { self.d_priv }
108 #[stable(feature = "unit_test", since = "0.0.0")]
109 impl Trait
for Tuple
{
111 fn stable_trait_method(&self) -> i32 { self.3 }
112 fn unstable_undeclared_trait_method(&self) -> i32 { self.3 }
113 fn unstable_declared_trait_method(&self) -> i32 { self.3 }
117 #[unstable(feature = "unstable_undeclared", issue = "38412")]
118 pub fn unstable_undeclared(&self) -> i32 { self.d_priv }
119 #[unstable(feature = "unstable_declared", issue = "38412")]
120 pub fn unstable_declared(&self) -> i32 { self.d_priv }
121 #[stable(feature = "unit_test", since = "0.0.0")]
122 pub fn stable(&self) -> i32 { self.d_priv }
124 #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY
125 pub(crate) fn pub_crate(&self) -> i32 { self.d_priv }
126 #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY
127 pub(in m
) fn pub_mod(&self) -> i32 { self.d_priv }
128 #[stable(feature = "unit_test", since = "0.0.0")] // SILLY
129 fn private(&self) -> i32 { self.d_priv }
133 #[unstable(feature = "unstable_undeclared", issue = "38412")]
134 pub fn unstable_undeclared(&self) -> i32 { self.0 }
135 #[unstable(feature = "unstable_declared", issue = "38412")]
136 pub fn unstable_declared(&self) -> i32 { self.0 }
137 #[stable(feature = "unit_test", since = "0.0.0")]
138 pub fn stable(&self) -> i32 { self.0 }
140 pub(crate) fn pub_crate(&self) -> i32 { self.0 }
141 pub(in m
) fn pub_mod(&self) -> i32 { self.0 }
142 fn private(&self) -> i32 { self.0 }