Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b9865d9

Browse files
committedAug 9, 2019
Mention that tuple structs are private if their fields are
1 parent 813a3a5 commit b9865d9

File tree

5 files changed

+144
-3
lines changed

5 files changed

+144
-3
lines changed
 

‎src/librustc_resolve/lib.rs‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
5050
use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path};
5151
use syntax::ast::{QSelf, TraitItem, TraitItemKind, TraitRef, Ty, TyKind};
5252
use syntax::ptr::P;
53-
use syntax::{span_err, struct_span_err, unwrap_or, walk_list};
53+
use syntax::{struct_span_err, unwrap_or, walk_list};
5454

5555
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
5656
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
@@ -4789,8 +4789,33 @@ impl<'a> Resolver<'a> {
47894789
let mut reported_spans = FxHashSet::default();
47904790
for &PrivacyError(dedup_span, ident, binding) in &self.privacy_errors {
47914791
if reported_spans.insert(dedup_span) {
4792-
span_err!(self.session, ident.span, E0603, "{} `{}` is private",
4793-
binding.descr(), ident.name);
4792+
let mut err = struct_span_err!(
4793+
self.session,
4794+
ident.span,
4795+
E0603,
4796+
"{} `{}` is private",
4797+
binding.descr(),
4798+
ident.name,
4799+
);
4800+
// FIXME: use the ctor's `def_id` to check wether any of the fields is not visible
4801+
match binding.kind {
4802+
NameBindingKind::Res(Res::Def(DefKind::Ctor(
4803+
CtorOf::Struct,
4804+
CtorKind::Fn,
4805+
), _def_id), _) => {
4806+
err.note("a tuple struct constructor is private if any of its fields \
4807+
is private");
4808+
}
4809+
NameBindingKind::Res(Res::Def(DefKind::Ctor(
4810+
CtorOf::Variant,
4811+
CtorKind::Fn,
4812+
), _def_id), _) => {
4813+
err.note("a tuple variant constructor is private if any of its fields \
4814+
is private");
4815+
}
4816+
_ => {}
4817+
}
4818+
err.emit();
47944819
}
47954820
}
47964821
}

‎src/test/ui/privacy/privacy5.stderr‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,288 +3,384 @@ error[E0603]: tuple struct `A` is private
33
|
44
LL | let a = a::A(());
55
| ^
6+
|
7+
= note: a tuple struct constructor is private if any of its fields is private
68

79
error[E0603]: tuple struct `B` is private
810
--> $DIR/privacy5.rs:52:16
911
|
1012
LL | let b = a::B(2);
1113
| ^
14+
|
15+
= note: a tuple struct constructor is private if any of its fields is private
1216

1317
error[E0603]: tuple struct `C` is private
1418
--> $DIR/privacy5.rs:53:16
1519
|
1620
LL | let c = a::C(2, 3);
1721
| ^
22+
|
23+
= note: a tuple struct constructor is private if any of its fields is private
1824

1925
error[E0603]: tuple struct `A` is private
2026
--> $DIR/privacy5.rs:56:12
2127
|
2228
LL | let a::A(()) = a;
2329
| ^
30+
|
31+
= note: a tuple struct constructor is private if any of its fields is private
2432

2533
error[E0603]: tuple struct `A` is private
2634
--> $DIR/privacy5.rs:57:12
2735
|
2836
LL | let a::A(_) = a;
2937
| ^
38+
|
39+
= note: a tuple struct constructor is private if any of its fields is private
3040

3141
error[E0603]: tuple struct `A` is private
3242
--> $DIR/privacy5.rs:58:18
3343
|
3444
LL | match a { a::A(()) => {} }
3545
| ^
46+
|
47+
= note: a tuple struct constructor is private if any of its fields is private
3648

3749
error[E0603]: tuple struct `A` is private
3850
--> $DIR/privacy5.rs:59:18
3951
|
4052
LL | match a { a::A(_) => {} }
4153
| ^
54+
|
55+
= note: a tuple struct constructor is private if any of its fields is private
4256

4357
error[E0603]: tuple struct `B` is private
4458
--> $DIR/privacy5.rs:61:12
4559
|
4660
LL | let a::B(_) = b;
4761
| ^
62+
|
63+
= note: a tuple struct constructor is private if any of its fields is private
4864

4965
error[E0603]: tuple struct `B` is private
5066
--> $DIR/privacy5.rs:62:12
5167
|
5268
LL | let a::B(_b) = b;
5369
| ^
70+
|
71+
= note: a tuple struct constructor is private if any of its fields is private
5472

5573
error[E0603]: tuple struct `B` is private
5674
--> $DIR/privacy5.rs:63:18
5775
|
5876
LL | match b { a::B(_) => {} }
5977
| ^
78+
|
79+
= note: a tuple struct constructor is private if any of its fields is private
6080

6181
error[E0603]: tuple struct `B` is private
6282
--> $DIR/privacy5.rs:64:18
6383
|
6484
LL | match b { a::B(_b) => {} }
6585
| ^
86+
|
87+
= note: a tuple struct constructor is private if any of its fields is private
6688

6789
error[E0603]: tuple struct `B` is private
6890
--> $DIR/privacy5.rs:65:18
6991
|
7092
LL | match b { a::B(1) => {} a::B(_) => {} }
7193
| ^
94+
|
95+
= note: a tuple struct constructor is private if any of its fields is private
7296

7397
error[E0603]: tuple struct `B` is private
7498
--> $DIR/privacy5.rs:65:32
7599
|
76100
LL | match b { a::B(1) => {} a::B(_) => {} }
77101
| ^
102+
|
103+
= note: a tuple struct constructor is private if any of its fields is private
78104

79105
error[E0603]: tuple struct `C` is private
80106
--> $DIR/privacy5.rs:68:12
81107
|
82108
LL | let a::C(_, _) = c;
83109
| ^
110+
|
111+
= note: a tuple struct constructor is private if any of its fields is private
84112

85113
error[E0603]: tuple struct `C` is private
86114
--> $DIR/privacy5.rs:69:12
87115
|
88116
LL | let a::C(_a, _) = c;
89117
| ^
118+
|
119+
= note: a tuple struct constructor is private if any of its fields is private
90120

91121
error[E0603]: tuple struct `C` is private
92122
--> $DIR/privacy5.rs:70:12
93123
|
94124
LL | let a::C(_, _b) = c;
95125
| ^
126+
|
127+
= note: a tuple struct constructor is private if any of its fields is private
96128

97129
error[E0603]: tuple struct `C` is private
98130
--> $DIR/privacy5.rs:71:12
99131
|
100132
LL | let a::C(_a, _b) = c;
101133
| ^
134+
|
135+
= note: a tuple struct constructor is private if any of its fields is private
102136

103137
error[E0603]: tuple struct `C` is private
104138
--> $DIR/privacy5.rs:72:18
105139
|
106140
LL | match c { a::C(_, _) => {} }
107141
| ^
142+
|
143+
= note: a tuple struct constructor is private if any of its fields is private
108144

109145
error[E0603]: tuple struct `C` is private
110146
--> $DIR/privacy5.rs:73:18
111147
|
112148
LL | match c { a::C(_a, _) => {} }
113149
| ^
150+
|
151+
= note: a tuple struct constructor is private if any of its fields is private
114152

115153
error[E0603]: tuple struct `C` is private
116154
--> $DIR/privacy5.rs:74:18
117155
|
118156
LL | match c { a::C(_, _b) => {} }
119157
| ^
158+
|
159+
= note: a tuple struct constructor is private if any of its fields is private
120160

121161
error[E0603]: tuple struct `C` is private
122162
--> $DIR/privacy5.rs:75:18
123163
|
124164
LL | match c { a::C(_a, _b) => {} }
125165
| ^
166+
|
167+
= note: a tuple struct constructor is private if any of its fields is private
126168

127169
error[E0603]: tuple struct `A` is private
128170
--> $DIR/privacy5.rs:83:17
129171
|
130172
LL | let a2 = a::A;
131173
| ^
174+
|
175+
= note: a tuple struct constructor is private if any of its fields is private
132176

133177
error[E0603]: tuple struct `B` is private
134178
--> $DIR/privacy5.rs:84:17
135179
|
136180
LL | let b2 = a::B;
137181
| ^
182+
|
183+
= note: a tuple struct constructor is private if any of its fields is private
138184

139185
error[E0603]: tuple struct `C` is private
140186
--> $DIR/privacy5.rs:85:17
141187
|
142188
LL | let c2 = a::C;
143189
| ^
190+
|
191+
= note: a tuple struct constructor is private if any of its fields is private
144192

145193
error[E0603]: tuple struct `A` is private
146194
--> $DIR/privacy5.rs:90:20
147195
|
148196
LL | let a = other::A(());
149197
| ^
198+
|
199+
= note: a tuple struct constructor is private if any of its fields is private
150200

151201
error[E0603]: tuple struct `B` is private
152202
--> $DIR/privacy5.rs:91:20
153203
|
154204
LL | let b = other::B(2);
155205
| ^
206+
|
207+
= note: a tuple struct constructor is private if any of its fields is private
156208

157209
error[E0603]: tuple struct `C` is private
158210
--> $DIR/privacy5.rs:92:20
159211
|
160212
LL | let c = other::C(2, 3);
161213
| ^
214+
|
215+
= note: a tuple struct constructor is private if any of its fields is private
162216

163217
error[E0603]: tuple struct `A` is private
164218
--> $DIR/privacy5.rs:95:16
165219
|
166220
LL | let other::A(()) = a;
167221
| ^
222+
|
223+
= note: a tuple struct constructor is private if any of its fields is private
168224

169225
error[E0603]: tuple struct `A` is private
170226
--> $DIR/privacy5.rs:96:16
171227
|
172228
LL | let other::A(_) = a;
173229
| ^
230+
|
231+
= note: a tuple struct constructor is private if any of its fields is private
174232

175233
error[E0603]: tuple struct `A` is private
176234
--> $DIR/privacy5.rs:97:22
177235
|
178236
LL | match a { other::A(()) => {} }
179237
| ^
238+
|
239+
= note: a tuple struct constructor is private if any of its fields is private
180240

181241
error[E0603]: tuple struct `A` is private
182242
--> $DIR/privacy5.rs:98:22
183243
|
184244
LL | match a { other::A(_) => {} }
185245
| ^
246+
|
247+
= note: a tuple struct constructor is private if any of its fields is private
186248

187249
error[E0603]: tuple struct `B` is private
188250
--> $DIR/privacy5.rs:100:16
189251
|
190252
LL | let other::B(_) = b;
191253
| ^
254+
|
255+
= note: a tuple struct constructor is private if any of its fields is private
192256

193257
error[E0603]: tuple struct `B` is private
194258
--> $DIR/privacy5.rs:101:16
195259
|
196260
LL | let other::B(_b) = b;
197261
| ^
262+
|
263+
= note: a tuple struct constructor is private if any of its fields is private
198264

199265
error[E0603]: tuple struct `B` is private
200266
--> $DIR/privacy5.rs:102:22
201267
|
202268
LL | match b { other::B(_) => {} }
203269
| ^
270+
|
271+
= note: a tuple struct constructor is private if any of its fields is private
204272

205273
error[E0603]: tuple struct `B` is private
206274
--> $DIR/privacy5.rs:103:22
207275
|
208276
LL | match b { other::B(_b) => {} }
209277
| ^
278+
|
279+
= note: a tuple struct constructor is private if any of its fields is private
210280

211281
error[E0603]: tuple struct `B` is private
212282
--> $DIR/privacy5.rs:104:22
213283
|
214284
LL | match b { other::B(1) => {} other::B(_) => {} }
215285
| ^
286+
|
287+
= note: a tuple struct constructor is private if any of its fields is private
216288

217289
error[E0603]: tuple struct `B` is private
218290
--> $DIR/privacy5.rs:104:40
219291
|
220292
LL | match b { other::B(1) => {} other::B(_) => {} }
221293
| ^
294+
|
295+
= note: a tuple struct constructor is private if any of its fields is private
222296

223297
error[E0603]: tuple struct `C` is private
224298
--> $DIR/privacy5.rs:107:16
225299
|
226300
LL | let other::C(_, _) = c;
227301
| ^
302+
|
303+
= note: a tuple struct constructor is private if any of its fields is private
228304

229305
error[E0603]: tuple struct `C` is private
230306
--> $DIR/privacy5.rs:108:16
231307
|
232308
LL | let other::C(_a, _) = c;
233309
| ^
310+
|
311+
= note: a tuple struct constructor is private if any of its fields is private
234312

235313
error[E0603]: tuple struct `C` is private
236314
--> $DIR/privacy5.rs:109:16
237315
|
238316
LL | let other::C(_, _b) = c;
239317
| ^
318+
|
319+
= note: a tuple struct constructor is private if any of its fields is private
240320

241321
error[E0603]: tuple struct `C` is private
242322
--> $DIR/privacy5.rs:110:16
243323
|
244324
LL | let other::C(_a, _b) = c;
245325
| ^
326+
|
327+
= note: a tuple struct constructor is private if any of its fields is private
246328

247329
error[E0603]: tuple struct `C` is private
248330
--> $DIR/privacy5.rs:111:22
249331
|
250332
LL | match c { other::C(_, _) => {} }
251333
| ^
334+
|
335+
= note: a tuple struct constructor is private if any of its fields is private
252336

253337
error[E0603]: tuple struct `C` is private
254338
--> $DIR/privacy5.rs:112:22
255339
|
256340
LL | match c { other::C(_a, _) => {} }
257341
| ^
342+
|
343+
= note: a tuple struct constructor is private if any of its fields is private
258344

259345
error[E0603]: tuple struct `C` is private
260346
--> $DIR/privacy5.rs:113:22
261347
|
262348
LL | match c { other::C(_, _b) => {} }
263349
| ^
350+
|
351+
= note: a tuple struct constructor is private if any of its fields is private
264352

265353
error[E0603]: tuple struct `C` is private
266354
--> $DIR/privacy5.rs:114:22
267355
|
268356
LL | match c { other::C(_a, _b) => {} }
269357
| ^
358+
|
359+
= note: a tuple struct constructor is private if any of its fields is private
270360

271361
error[E0603]: tuple struct `A` is private
272362
--> $DIR/privacy5.rs:122:21
273363
|
274364
LL | let a2 = other::A;
275365
| ^
366+
|
367+
= note: a tuple struct constructor is private if any of its fields is private
276368

277369
error[E0603]: tuple struct `B` is private
278370
--> $DIR/privacy5.rs:123:21
279371
|
280372
LL | let b2 = other::B;
281373
| ^
374+
|
375+
= note: a tuple struct constructor is private if any of its fields is private
282376

283377
error[E0603]: tuple struct `C` is private
284378
--> $DIR/privacy5.rs:124:21
285379
|
286380
LL | let c2 = other::C;
287381
| ^
382+
|
383+
= note: a tuple struct constructor is private if any of its fields is private
288384

289385
error: aborting due to 48 previous errors
290386

‎src/test/ui/resolve/privacy-struct-ctor.stderr‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,48 @@ error[E0603]: tuple struct `Z` is private
3434
|
3535
LL | n::Z;
3636
| ^
37+
|
38+
= note: a tuple struct constructor is private if any of its fields is private
3739

3840
error[E0603]: tuple struct `S` is private
3941
--> $DIR/privacy-struct-ctor.rs:29:8
4042
|
4143
LL | m::S;
4244
| ^
45+
|
46+
= note: a tuple struct constructor is private if any of its fields is private
4347

4448
error[E0603]: tuple struct `S` is private
4549
--> $DIR/privacy-struct-ctor.rs:31:19
4650
|
4751
LL | let _: S = m::S(2);
4852
| ^
53+
|
54+
= note: a tuple struct constructor is private if any of its fields is private
4955

5056
error[E0603]: tuple struct `Z` is private
5157
--> $DIR/privacy-struct-ctor.rs:35:11
5258
|
5359
LL | m::n::Z;
5460
| ^
61+
|
62+
= note: a tuple struct constructor is private if any of its fields is private
5563

5664
error[E0603]: tuple struct `S` is private
5765
--> $DIR/privacy-struct-ctor.rs:41:16
5866
|
5967
LL | xcrate::m::S;
6068
| ^
69+
|
70+
= note: a tuple struct constructor is private if any of its fields is private
6171

6272
error[E0603]: tuple struct `Z` is private
6373
--> $DIR/privacy-struct-ctor.rs:45:19
6474
|
6575
LL | xcrate::m::n::Z;
6676
| ^
77+
|
78+
= note: a tuple struct constructor is private if any of its fields is private
6779

6880
error: aborting due to 10 previous errors
6981

‎src/test/ui/rfc-2008-non-exhaustive/struct.stderr‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ error[E0603]: tuple struct `TupleStruct` is private
1515
|
1616
LL | let ts_explicit = structs::TupleStruct(640, 480);
1717
| ^^^^^^^^^^^
18+
|
19+
= note: a tuple struct constructor is private if any of its fields is private
1820

1921
error[E0603]: unit struct `UnitStruct` is private
2022
--> $DIR/struct.rs:32:32

‎src/test/ui/rfc-2008-non-exhaustive/variant.stderr‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0603]: tuple variant `Tuple` is private
33
|
44
LL | let variant_tuple = NonExhaustiveVariants::Tuple(640);
55
| ^^^^^
6+
|
7+
= note: a tuple variant constructor is private if any of its fields is private
68

79
error[E0603]: unit variant `Unit` is private
810
--> $DIR/variant.rs:14:47
@@ -21,12 +23,16 @@ error[E0603]: tuple variant `Tuple` is private
2123
|
2224
LL | NonExhaustiveVariants::Tuple(fe_tpl) => "",
2325
| ^^^^^
26+
|
27+
= note: a tuple variant constructor is private if any of its fields is private
2428

2529
error[E0603]: tuple variant `Tuple` is private
2630
--> $DIR/variant.rs:26:35
2731
|
2832
LL | if let NonExhaustiveVariants::Tuple(fe_tpl) = variant_struct {
2933
| ^^^^^
34+
|
35+
= note: a tuple variant constructor is private if any of its fields is private
3036

3137
error[E0639]: cannot create non-exhaustive variant using struct expression
3238
--> $DIR/variant.rs:8:26

0 commit comments

Comments
 (0)
Please sign in to comment.