1 // This crate attempts to enumerate the various scenarios for how a
2 // type can define fields and methods with various visibilities and
5 // The basic stability pattern in this file has four cases:
6 // 1. no stability attribute at all
7 // 2. a stable attribute (feature "unit_test")
8 // 3. an unstable attribute that unit test declares (feature "unstable_declared")
9 // 4. an unstable attribute that unit test fails to declare (feature "unstable_undeclared")
11 // This file also covers four kinds of visibility: private,
12 // pub(module), pub(crate), and pub.
14 // However, since stability attributes can only be observed in
15 // cross-crate linkage scenarios, there is little reason to take the
16 // cross-product (4 stability cases * 4 visibility cases), because the
17 // first three visibility cases cannot be accessed outside this crate,
18 // and therefore stability is only relevant when the visibility is pub
19 // to the whole universe.
21 // (The only reason to do so would be if one were worried about the
22 // compiler having some subtle bug where adding a stability attribute
23 // introduces a privacy violation. As a way to provide evidence that
24 // this is not occurring, I have put stability attributes on some
25 // non-pub fields, marked with SILLY below)
27 #![feature(staged_api)]
29 #![stable(feature = "unit_test", since = "1.0.0")]
31 #[stable(feature = "unit_test", since = "1.0.0")]
32 pub use m
::{Record, Trait, Tuple}
;
36 #[stable(feature = "unit_test", since = "1.0.0")]
38 #[stable(feature = "unit_test", since = "1.0.0")]
39 pub a_stable_pub
: i32,
40 #[unstable(feature = "unstable_declared", issue = "38412")]
41 pub a_unstable_declared_pub
: i32,
42 #[unstable(feature = "unstable_undeclared", issue = "38412")]
43 pub a_unstable_undeclared_pub
: i32,
44 #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY
45 pub(crate) b_crate
: i32,
46 #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY
48 #[stable(feature = "unit_test", since = "1.0.0")] // SILLY
53 #[stable(feature = "unit_test", since = "1.0.0")]
55 #[stable(feature = "unit_test", since = "1.0.0")]
57 #[unstable(feature = "unstable_declared", issue = "38412")]
59 #[unstable(feature = "unstable_undeclared", issue = "38412")]
67 #[stable(feature = "unit_test", since = "1.0.0")]
68 pub fn new() -> Self { Default::default() }
72 #[stable(feature = "unit_test", since = "1.0.0")]
73 pub fn new() -> Self { Default::default() }
77 #[stable(feature = "unit_test", since = "1.0.0")]
79 #[stable(feature = "unit_test", since = "1.0.0")]
81 #[stable(feature = "unit_test", since = "1.0.0")]
82 fn stable_trait_method(&self) -> Self::Type
;
83 #[unstable(feature = "unstable_undeclared", issue = "38412")]
84 fn unstable_undeclared_trait_method(&self) -> Self::Type
;
85 #[unstable(feature = "unstable_declared", issue = "38412")]
86 fn unstable_declared_trait_method(&self) -> Self::Type
;
89 #[stable(feature = "unit_test", since = "1.0.0")]
90 impl Trait
for Record
{
92 fn stable_trait_method(&self) -> i32 { self.d_priv }
93 fn unstable_undeclared_trait_method(&self) -> i32 { self.d_priv }
94 fn unstable_declared_trait_method(&self) -> i32 { self.d_priv }
97 #[stable(feature = "unit_test", since = "1.0.0")]
98 impl Trait
for Tuple
{
100 fn stable_trait_method(&self) -> i32 { self.3 }
101 fn unstable_undeclared_trait_method(&self) -> i32 { self.3 }
102 fn unstable_declared_trait_method(&self) -> i32 { self.3 }
106 #[unstable(feature = "unstable_undeclared", issue = "38412")]
107 pub fn unstable_undeclared(&self) -> i32 { self.d_priv }
108 #[unstable(feature = "unstable_declared", issue = "38412")]
109 pub fn unstable_declared(&self) -> i32 { self.d_priv }
110 #[stable(feature = "unit_test", since = "1.0.0")]
111 pub fn stable(&self) -> i32 { self.d_priv }
113 #[unstable(feature = "unstable_undeclared", issue = "38412")] // SILLY
114 pub(crate) fn pub_crate(&self) -> i32 { self.d_priv }
115 #[unstable(feature = "unstable_declared", issue = "38412")] // SILLY
116 pub(in m
) fn pub_mod(&self) -> i32 { self.d_priv }
117 #[stable(feature = "unit_test", since = "1.0.0")] // SILLY
118 fn private(&self) -> i32 { self.d_priv }
122 #[unstable(feature = "unstable_undeclared", issue = "38412")]
123 pub fn unstable_undeclared(&self) -> i32 { self.0 }
124 #[unstable(feature = "unstable_declared", issue = "38412")]
125 pub fn unstable_declared(&self) -> i32 { self.0 }
126 #[stable(feature = "unit_test", since = "1.0.0")]
127 pub fn stable(&self) -> i32 { self.0 }
129 pub(crate) fn pub_crate(&self) -> i32 { self.0 }
130 pub(in m
) fn pub_mod(&self) -> i32 { self.0 }
131 fn private(&self) -> i32 { self.0 }