Skip to content

Commit 1dce275

Browse files
committed
moved renamed docs stderr formatted auxiliary | explore-issue-38412.rs
1 parent 9b415a8 commit 1dce275

File tree

3 files changed

+178
-31
lines changed

3 files changed

+178
-31
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// This crate attempts to enumerate the various scenarios for how a
2+
// type can define fields and methods with various visibilities and
3+
// stabilities.
4+
//
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 enables (feature "unstable_declared")
9+
// 4. an unstable attribute that unit test fails to enable (feature "unstable_undeclared")
10+
//
11+
// This file also covers four kinds of visibility: private,
12+
// pub(module), pub(crate), and pub.
13+
//
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.
20+
//
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)
26+
27+
#![feature(staged_api)]
28+
29+
#![stable(feature = "unit_test", since = "1.0.0")]
30+
31+
#[stable(feature = "unit_test", since = "1.0.0")]
32+
pub use m::{Record, Trait, Tuple};
33+
34+
mod m {
35+
#[derive(Default)]
36+
#[stable(feature = "unit_test", since = "1.0.0")]
37+
pub struct Record {
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
47+
pub(in crate::m) c_mod: i32,
48+
#[stable(feature = "unit_test", since = "1.0.0")] // SILLY
49+
d_priv: i32
50+
}
51+
52+
#[derive(Default)]
53+
#[stable(feature = "unit_test", since = "1.0.0")]
54+
pub struct Tuple(
55+
#[stable(feature = "unit_test", since = "1.0.0")]
56+
pub i32,
57+
#[unstable(feature = "unstable_declared", issue = "38412")]
58+
pub i32,
59+
#[unstable(feature = "unstable_undeclared", issue = "38412")]
60+
pub i32,
61+
62+
pub(crate) i32,
63+
pub(in crate::m) i32,
64+
i32);
65+
66+
impl Record {
67+
#[stable(feature = "unit_test", since = "1.0.0")]
68+
pub fn new() -> Self { Default::default() }
69+
}
70+
71+
impl Tuple {
72+
#[stable(feature = "unit_test", since = "1.0.0")]
73+
pub fn new() -> Self { Default::default() }
74+
}
75+
76+
77+
#[stable(feature = "unit_test", since = "1.0.0")]
78+
pub trait Trait {
79+
#[stable(feature = "unit_test", since = "1.0.0")]
80+
type Type;
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;
87+
}
88+
89+
#[stable(feature = "unit_test", since = "1.0.0")]
90+
impl Trait for Record {
91+
type Type = i32;
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 }
95+
}
96+
97+
#[stable(feature = "unit_test", since = "1.0.0")]
98+
impl Trait for Tuple {
99+
type Type = i32;
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 }
103+
}
104+
105+
impl Record {
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 }
112+
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 crate::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 }
119+
}
120+
121+
impl Tuple {
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 }
128+
129+
pub(crate) fn pub_crate(&self) -> i32 { self.0 }
130+
pub(in crate::m) fn pub_mod(&self) -> i32 { self.0 }
131+
fn private(&self) -> i32 { self.0 }
132+
}
133+
}

tests/ui/explore-issue-38412.rs renamed to tests/ui/stability-attribute/stability-privacy-interaction.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1+
//! Regression test for issue #38412: interaction between stability attributes and privacy
2+
//!
3+
//! Tests that the compiler correctly handles the interaction between feature gates
4+
//! and privacy/visibility rules. Specifically verifies that enabled unstable features
5+
//! are accessible while disabled ones are properly rejected.
6+
17
//@ aux-build:pub-and-stability.rs
28

3-
// A big point of this test is that we *enable* `unstable_declared`,
4-
// but do *not* enable `unstable_undeclared`. This way we can check
5-
// that the compiler is letting in uses of enabled feature-gated
6-
// stuff but still rejecting uses of disabled feature-gated stuff.
9+
// Enable `unstable_declared` but not `unstable_undeclared` to test
10+
// that the compiler allows enabled features but rejects disabled ones
711
#![feature(unstable_declared)]
812

913
extern crate pub_and_stability;
1014
use pub_and_stability::{Record, Trait, Tuple};
1115

1216
fn main() {
13-
// Okay
17+
// Test struct field access patterns
1418
let Record { .. } = Record::new();
1519

16-
// Okay
17-
let Record { a_stable_pub: _, a_unstable_declared_pub: _, .. } = Record::new();
20+
let Record {
21+
a_stable_pub: _,
22+
a_unstable_declared_pub: _,
23+
..
24+
} = Record::new();
1825

19-
let Record { a_stable_pub: _, a_unstable_declared_pub: _, a_unstable_undeclared_pub: _, .. } =
20-
Record::new();
21-
//~^^ ERROR use of unstable library feature `unstable_undeclared`
26+
let Record {
27+
a_stable_pub: _,
28+
a_unstable_declared_pub: _,
29+
a_unstable_undeclared_pub: _, //~ ERROR use of unstable library feature `unstable_undeclared`
30+
..
31+
} = Record::new();
2232

2333
let r = Record::new();
2434
let t = Tuple::new();
2535

36+
// Test field access with different stability/privacy combinations
2637
r.a_stable_pub;
2738
r.a_unstable_declared_pub;
2839
r.a_unstable_undeclared_pub; //~ ERROR use of unstable library feature
@@ -37,10 +48,12 @@ fn main() {
3748
t.4; //~ ERROR is private
3849
t.5; //~ ERROR is private
3950

51+
// Test trait method access
4052
r.stable_trait_method();
4153
r.unstable_declared_trait_method();
4254
r.unstable_undeclared_trait_method(); //~ ERROR use of unstable library feature
4355

56+
// Test inherent method access
4457
r.stable();
4558
r.unstable_declared();
4659
r.unstable_undeclared(); //~ ERROR use of unstable library feature
@@ -49,6 +62,7 @@ fn main() {
4962
r.pub_mod(); //~ ERROR `pub_mod` is private
5063
r.private(); //~ ERROR `private` is private
5164

65+
// Repeat tests for tuple struct
5266
let t = Tuple::new();
5367
t.stable_trait_method();
5468
t.unstable_declared_trait_method();

tests/ui/explore-issue-38412.stderr renamed to tests/ui/stability-attribute/stability-privacy-interaction.stderr

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
error[E0658]: use of unstable library feature `unstable_undeclared`
2-
--> $DIR/explore-issue-38412.rs:19:63
2+
--> $DIR/stability-privacy-interaction.rs:29:9
33
|
4-
LL | let Record { a_stable_pub: _, a_unstable_declared_pub: _, a_unstable_undeclared_pub: _, .. } =
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | a_unstable_undeclared_pub: _,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #38412 <https://github.com/rust-lang/rust/issues/38412> for more information
88
= help: add `#![feature(unstable_undeclared)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0658]: use of unstable library feature `unstable_undeclared`
12-
--> $DIR/explore-issue-38412.rs:28:5
12+
--> $DIR/stability-privacy-interaction.rs:39:5
1313
|
1414
LL | r.a_unstable_undeclared_pub;
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -19,25 +19,25 @@ LL | r.a_unstable_undeclared_pub;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0616]: field `b_crate` of struct `Record` is private
22-
--> $DIR/explore-issue-38412.rs:29:7
22+
--> $DIR/stability-privacy-interaction.rs:40:7
2323
|
2424
LL | r.b_crate;
2525
| ^^^^^^^ private field
2626

2727
error[E0616]: field `c_mod` of struct `Record` is private
28-
--> $DIR/explore-issue-38412.rs:30:7
28+
--> $DIR/stability-privacy-interaction.rs:41:7
2929
|
3030
LL | r.c_mod;
3131
| ^^^^^ private field
3232

3333
error[E0616]: field `d_priv` of struct `Record` is private
34-
--> $DIR/explore-issue-38412.rs:31:7
34+
--> $DIR/stability-privacy-interaction.rs:42:7
3535
|
3636
LL | r.d_priv;
3737
| ^^^^^^ private field
3838

3939
error[E0658]: use of unstable library feature `unstable_undeclared`
40-
--> $DIR/explore-issue-38412.rs:35:5
40+
--> $DIR/stability-privacy-interaction.rs:46:5
4141
|
4242
LL | t.2;
4343
| ^^^
@@ -47,25 +47,25 @@ LL | t.2;
4747
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4848

4949
error[E0616]: field `3` of struct `pub_and_stability::Tuple` is private
50-
--> $DIR/explore-issue-38412.rs:36:7
50+
--> $DIR/stability-privacy-interaction.rs:47:7
5151
|
5252
LL | t.3;
5353
| ^ private field
5454

5555
error[E0616]: field `4` of struct `pub_and_stability::Tuple` is private
56-
--> $DIR/explore-issue-38412.rs:37:7
56+
--> $DIR/stability-privacy-interaction.rs:48:7
5757
|
5858
LL | t.4;
5959
| ^ private field
6060

6161
error[E0616]: field `5` of struct `pub_and_stability::Tuple` is private
62-
--> $DIR/explore-issue-38412.rs:38:7
62+
--> $DIR/stability-privacy-interaction.rs:49:7
6363
|
6464
LL | t.5;
6565
| ^ private field
6666

6767
error[E0658]: use of unstable library feature `unstable_undeclared`
68-
--> $DIR/explore-issue-38412.rs:42:7
68+
--> $DIR/stability-privacy-interaction.rs:54:7
6969
|
7070
LL | r.unstable_undeclared_trait_method();
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -75,7 +75,7 @@ LL | r.unstable_undeclared_trait_method();
7575
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
7676

7777
error[E0658]: use of unstable library feature `unstable_undeclared`
78-
--> $DIR/explore-issue-38412.rs:46:7
78+
--> $DIR/stability-privacy-interaction.rs:59:7
7979
|
8080
LL | r.unstable_undeclared();
8181
| ^^^^^^^^^^^^^^^^^^^
@@ -85,7 +85,7 @@ LL | r.unstable_undeclared();
8585
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
8686

8787
error[E0624]: method `pub_crate` is private
88-
--> $DIR/explore-issue-38412.rs:48:7
88+
--> $DIR/stability-privacy-interaction.rs:61:7
8989
|
9090
LL | r.pub_crate();
9191
| ^^^^^^^^^ private method
@@ -96,7 +96,7 @@ LL | pub(crate) fn pub_crate(&self) -> i32 { self.d_priv }
9696
| ------------------------------------- private method defined here
9797

9898
error[E0624]: method `pub_mod` is private
99-
--> $DIR/explore-issue-38412.rs:49:7
99+
--> $DIR/stability-privacy-interaction.rs:62:7
100100
|
101101
LL | r.pub_mod();
102102
| ^^^^^^^ private method
@@ -107,7 +107,7 @@ LL | pub(in crate::m) fn pub_mod(&self) -> i32 { self.d_priv }
107107
| ----------------------------------------- private method defined here
108108

109109
error[E0624]: method `private` is private
110-
--> $DIR/explore-issue-38412.rs:50:7
110+
--> $DIR/stability-privacy-interaction.rs:63:7
111111
|
112112
LL | r.private();
113113
| ^^^^^^^ private method
@@ -118,7 +118,7 @@ LL | fn private(&self) -> i32 { self.d_priv }
118118
| ------------------------ private method defined here
119119

120120
error[E0658]: use of unstable library feature `unstable_undeclared`
121-
--> $DIR/explore-issue-38412.rs:55:7
121+
--> $DIR/stability-privacy-interaction.rs:69:7
122122
|
123123
LL | t.unstable_undeclared_trait_method();
124124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -128,7 +128,7 @@ LL | t.unstable_undeclared_trait_method();
128128
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
129129

130130
error[E0658]: use of unstable library feature `unstable_undeclared`
131-
--> $DIR/explore-issue-38412.rs:59:7
131+
--> $DIR/stability-privacy-interaction.rs:73:7
132132
|
133133
LL | t.unstable_undeclared();
134134
| ^^^^^^^^^^^^^^^^^^^
@@ -138,7 +138,7 @@ LL | t.unstable_undeclared();
138138
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
139139

140140
error[E0624]: method `pub_crate` is private
141-
--> $DIR/explore-issue-38412.rs:61:7
141+
--> $DIR/stability-privacy-interaction.rs:75:7
142142
|
143143
LL | t.pub_crate();
144144
| ^^^^^^^^^ private method
@@ -149,7 +149,7 @@ LL | pub(crate) fn pub_crate(&self) -> i32 { self.0 }
149149
| ------------------------------------- private method defined here
150150

151151
error[E0624]: method `pub_mod` is private
152-
--> $DIR/explore-issue-38412.rs:62:7
152+
--> $DIR/stability-privacy-interaction.rs:76:7
153153
|
154154
LL | t.pub_mod();
155155
| ^^^^^^^ private method
@@ -160,7 +160,7 @@ LL | pub(in crate::m) fn pub_mod(&self) -> i32 { self.0 }
160160
| ----------------------------------------- private method defined here
161161

162162
error[E0624]: method `private` is private
163-
--> $DIR/explore-issue-38412.rs:63:7
163+
--> $DIR/stability-privacy-interaction.rs:77:7
164164
|
165165
LL | t.private();
166166
| ^^^^^^^ private method

0 commit comments

Comments
 (0)