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 visibilities 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 visibility 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)]
39 #![stable(feature = "unit_test", since = "1.0.0")]
41 #[stable(feature = "unit_test", since = "1.0.0")]
42 pub use m::{Record, Trait, Tuple};
46 #[stable(feature = "unit_test", since = "1.0.0")]
48 #[stable(feature = "unit_test", since = "1.0.0")]
49 pub a_stable_pub: i32,
50 #[unstable(feature = "unstable_declared", issue = "38412")]
51 pub a_unstable_declared_pub: i32,
52 #[unstable(feature = "unstable_undeclared", issue = "38412")]
53 pub a_unstable_undeclared_pub: i32,
54 #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY
55 pub(crate) b_crate: i32,
56 #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY
58 #[stable(feature = "unit_test", since = "1.0.0")] // SILLY
63 #[stable(feature = "unit_test", since = "1.0.0")]
65 #[stable(feature = "unit_test", since = "1.0.0")]
67 #[unstable(feature = "unstable_declared", issue = "38412")]
69 #[unstable(feature = "unstable_undeclared", issue = "38412")]
77 #[stable(feature = "unit_test", since = "1.0.0")]
78 pub fn new() -> Self { Default::default() }
82 #[stable(feature = "unit_test", since = "1.0.0")]
83 pub fn new() -> Self { Default::default() }
87 #[stable(feature = "unit_test", since = "1.0.0")]
89 #[stable(feature = "unit_test", since = "1.0.0")]
91 #[stable(feature = "unit_test", since = "1.0.0")]
92 fn stable_trait_method(&self) -> Self::Type;
93 #[unstable(feature = "unstable_undeclared", issue = "38412")]
94 fn unstable_undeclared_trait_method(&self) -> Self::Type;
95 #[unstable(feature = "unstable_declared", issue = "38412")]
96 fn unstable_declared_trait_method(&self) -> Self::Type;
99 #[stable(feature = "unit_test", since = "1.0.0")]
100 impl Trait for Record {
102 fn stable_trait_method(&self) -> i32 { self.d_priv }
103 fn unstable_undeclared_trait_method(&self) -> i32 { self.d_priv }
104 fn unstable_declared_trait_method(&self) -> i32 { self.d_priv }
107 #[stable(feature = "unit_test", since = "1.0.0")]
108 impl Trait for Tuple {
110 fn stable_trait_method(&self) -> i32 { self.3 }
111 fn unstable_undeclared_trait_method(&self) -> i32 { self.3 }
112 fn unstable_declared_trait_method(&self) -> i32 { self.3 }
116 #[unstable(feature = "unstable_undeclared", issue = "38412")]
117 pub fn unstable_undeclared(&self) -> i32 { self.d_priv }
118 #[unstable(feature = "unstable_declared", issue = "38412")]
119 pub fn unstable_declared(&self) -> i32 { self.d_priv }
120 #[stable(feature = "unit_test", since = "1.0.0")]
121 pub fn stable(&self) -> i32 { self.d_priv }
123 #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY
124 pub(crate) fn pub_crate(&self) -> i32 { self.d_priv }
125 #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY
126 pub(in m) fn pub_mod(&self) -> i32 { self.d_priv }
127 #[stable(feature = "unit_test", since = "1.0.0")] // SILLY
128 fn private(&self) -> i32 { self.d_priv }
132 #[unstable(feature = "unstable_undeclared", issue = "38412")]
133 pub fn unstable_undeclared(&self) -> i32 { self.0 }
134 #[unstable(feature = "unstable_declared", issue = "38412")]
135 pub fn unstable_declared(&self) -> i32 { self.0 }
136 #[stable(feature = "unit_test", since = "1.0.0")]
137 pub fn stable(&self) -> i32 { self.0 }
139 pub(crate) fn pub_crate(&self) -> i32 { self.0 }
140 pub(in m) fn pub_mod(&self) -> i32 { self.0 }
141 fn private(&self) -> i32 { self.0 }