Skip to content

Commit 72869b6

Browse files
committed
2 parents 12391df + a0347d5 commit 72869b6

32 files changed

+125
-269
lines changed

src/doc/rust.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1586,10 +1586,10 @@ pub struct Bar {
15861586
field: int
15871587
}
15881588
1589-
// Declare a public enum with public and private variants
1589+
// Declare a public enum with two public variants
15901590
pub enum State {
15911591
PubliclyAccessibleState,
1592-
priv PrivatelyAccessibleState
1592+
PubliclyAccessibleState2,
15931593
}
15941594
~~~~
15951595

src/liblibc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ pub mod types {
229229
*/
230230
#[repr(u8)]
231231
pub enum c_void {
232-
priv variant1,
233-
priv variant2
232+
__variant1,
233+
__variant2,
234234
}
235235
pub enum FILE {}
236236
pub enum fpos_t {}

src/librand/distributions/gamma.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ use super::{IndependentSample, Sample, Exp};
4545
/// for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
4646
/// (September 2000),
4747
/// 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414)
48-
pub enum Gamma {
49-
priv Large(GammaLargeShape),
50-
priv One(Exp),
51-
priv Small(GammaSmallShape)
48+
pub struct Gamma {
49+
repr: GammaRepr,
50+
}
51+
52+
enum GammaRepr {
53+
Large(GammaLargeShape),
54+
One(Exp),
55+
Small(GammaSmallShape)
5256
}
5357

5458
// These two helpers could be made public, but saving the
@@ -90,11 +94,12 @@ impl Gamma {
9094
assert!(shape > 0.0, "Gamma::new called with shape <= 0");
9195
assert!(scale > 0.0, "Gamma::new called with scale <= 0");
9296

93-
match shape {
97+
let repr = match shape {
9498
1.0 => One(Exp::new(1.0 / scale)),
9599
0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
96100
_ => Large(GammaLargeShape::new_raw(shape, scale))
97-
}
101+
};
102+
Gamma { repr: repr }
98103
}
99104
}
100105

@@ -131,7 +136,7 @@ impl Sample<f64> for GammaLargeShape {
131136

132137
impl IndependentSample<f64> for Gamma {
133138
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
134-
match *self {
139+
match self.repr {
135140
Small(ref g) => g.ind_sample(rng),
136141
One(ref g) => g.ind_sample(rng),
137142
Large(ref g) => g.ind_sample(rng),
@@ -183,32 +188,37 @@ impl IndependentSample<f64> for GammaLargeShape {
183188
/// let v = chi.ind_sample(&mut rand::task_rng());
184189
/// println!("{} is from a χ²(11) distribution", v)
185190
/// ```
186-
pub enum ChiSquared {
191+
pub struct ChiSquared {
192+
repr: ChiSquaredRepr,
193+
}
194+
195+
enum ChiSquaredRepr {
187196
// k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1,
188197
// e.g. when alpha = 1/2 as it would be for this case, so special-
189198
// casing and using the definition of N(0,1)^2 is faster.
190-
priv DoFExactlyOne,
191-
priv DoFAnythingElse(Gamma)
199+
DoFExactlyOne,
200+
DoFAnythingElse(Gamma),
192201
}
193202

194203
impl ChiSquared {
195204
/// Create a new chi-squared distribution with degrees-of-freedom
196205
/// `k`. Fails if `k < 0`.
197206
pub fn new(k: f64) -> ChiSquared {
198-
if k == 1.0 {
207+
let repr = if k == 1.0 {
199208
DoFExactlyOne
200209
} else {
201210
assert!(k > 0.0, "ChiSquared::new called with `k` < 0");
202211
DoFAnythingElse(Gamma::new(0.5 * k, 2.0))
203-
}
212+
};
213+
ChiSquared { repr: repr }
204214
}
205215
}
206216
impl Sample<f64> for ChiSquared {
207217
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) }
208218
}
209219
impl IndependentSample<f64> for ChiSquared {
210220
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
211-
match *self {
221+
match self.repr {
212222
DoFExactlyOne => {
213223
// k == 1 => N(0,1)^2
214224
let StandardNormal(norm) = rng.gen::<StandardNormal>();

src/librustc/metadata/decoder.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ enum Family {
124124
Trait, // I
125125
Struct, // S
126126
PublicField, // g
127-
PrivateField, // j
128127
InheritedField // N
129128
}
130129

@@ -149,7 +148,6 @@ fn item_family(item: ebml::Doc) -> Family {
149148
'I' => Trait,
150149
'S' => Struct,
151150
'g' => PublicField,
152-
'j' => PrivateField,
153151
'N' => InheritedField,
154152
c => fail!("unexpected family char: {}", c)
155153
}
@@ -161,7 +159,6 @@ fn item_visibility(item: ebml::Doc) -> ast::Visibility {
161159
Some(visibility_doc) => {
162160
match reader::doc_as_u8(visibility_doc) as char {
163161
'y' => ast::Public,
164-
'n' => ast::Private,
165162
'i' => ast::Inherited,
166163
_ => fail!("unknown visibility character")
167164
}
@@ -364,7 +361,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
364361
Trait => DlDef(ast::DefTrait(did)),
365362
Enum => DlDef(ast::DefTy(did)),
366363
Impl => DlImpl(did),
367-
PublicField | PrivateField | InheritedField => DlField,
364+
PublicField | InheritedField => DlField,
368365
}
369366
}
370367

@@ -962,7 +959,6 @@ pub fn get_item_attrs(cdata: Cmd,
962959
fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
963960
match family {
964961
PublicField => ast::Public,
965-
PrivateField => ast::Private,
966962
InheritedField => ast::Inherited,
967963
_ => fail!()
968964
}
@@ -975,7 +971,7 @@ pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
975971
let mut result = Vec::new();
976972
reader::tagged_docs(item, tag_item_field, |an_item| {
977973
let f = item_family(an_item);
978-
if f == PublicField || f == PrivateField || f == InheritedField {
974+
if f == PublicField || f == InheritedField {
979975
// FIXME #6993: name should be of type Name, not Ident
980976
let name = item_name(&*intr, an_item);
981977
let did = item_def_id(an_item, cdata);

src/librustc/metadata/encoder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ fn encode_struct_field_family(ebml_w: &mut Encoder,
607607
visibility: Visibility) {
608608
encode_family(ebml_w, match visibility {
609609
Public => 'g',
610-
Private => 'j',
611610
Inherited => 'N'
612611
});
613612
}
@@ -616,7 +615,6 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
616615
ebml_w.start_tag(tag_items_data_item_visibility);
617616
let ch = match visibility {
618617
Public => 'y',
619-
Private => 'n',
620618
Inherited => 'i',
621619
};
622620
ebml_w.wr_str(str::from_char(ch));

src/librustc/middle/privacy.rs

+10-70
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,10 @@ impl Visitor<()> for ParentVisitor {
6767
// they inherit privacy
6868
ast::ItemEnum(ref def, _) => {
6969
for variant in def.variants.iter() {
70-
// If variants are private, then their logical "parent" is
71-
// the enclosing module because everyone in the enclosing
72-
// module can still use the private variant
73-
if variant.node.vis == ast::Private {
74-
self.parents.insert(variant.node.id, self.curparent);
75-
76-
// Otherwise, if the variant is public, then the parent is
77-
// considered the enclosing enum because the enum will
78-
// dictate the privacy visibility of this variant instead.
79-
} else {
80-
self.parents.insert(variant.node.id, item.id);
81-
}
70+
// The parent is considered the enclosing enum because the
71+
// enum will dictate the privacy visibility of this variant
72+
// instead.
73+
self.parents.insert(variant.node.id, item.id);
8274
}
8375
}
8476

@@ -224,9 +216,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
224216
// public all variants are public unless they're explicitly priv
225217
ast::ItemEnum(ref def, _) if public_first => {
226218
for variant in def.variants.iter() {
227-
if variant.node.vis != ast::Private {
228-
self.exported_items.insert(variant.node.id);
229-
}
219+
self.exported_items.insert(variant.node.id);
230220
}
231221
}
232222

@@ -462,10 +452,7 @@ impl<'a> PrivacyVisitor<'a> {
462452
Some(ast_map::NodeForeignItem(_)) => {
463453
self.tcx.map.get_foreign_vis(closest_private_id)
464454
}
465-
Some(ast_map::NodeVariant(ref v)) => {
466-
// sadly enum variants still inherit visibility, so only
467-
// break out of this is explicitly private
468-
if v.node.vis == ast::Private { break }
455+
Some(ast_map::NodeVariant(..)) => {
469456
ast::Public // need to move up a level (to the enum)
470457
}
471458
_ => ast::Public,
@@ -997,10 +984,6 @@ impl<'a> Visitor<()> for SanePrivacyVisitor<'a> {
997984
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
998985
match i.vis {
999986
ast::Inherited => {}
1000-
ast::Private => {
1001-
self.tcx.sess.span_err(i.span, "unnecessary visibility \
1002-
qualifier");
1003-
}
1004987
ast::Public => {
1005988
if self.in_fn {
1006989
self.tcx.sess.span_err(i.span, "unnecessary `pub`, imports \
@@ -1036,25 +1019,6 @@ impl<'a> SanePrivacyVisitor<'a> {
10361019
}
10371020
}
10381021
};
1039-
let check_not_priv = |sp: Span, vis: ast::Visibility, note: &str| {
1040-
if vis == ast::Private {
1041-
tcx.sess.span_err(sp, "unnecessary `priv` qualifier");
1042-
if note.len() > 0 {
1043-
tcx.sess.span_note(sp, note);
1044-
}
1045-
}
1046-
};
1047-
let check_struct = |def: &@ast::StructDef| {
1048-
for f in def.fields.iter() {
1049-
match f.node.kind {
1050-
ast::NamedField(_, ast::Private) => {
1051-
tcx.sess.span_err(f.span, "unnecessary `priv` \
1052-
visibility");
1053-
}
1054-
ast::NamedField(..) | ast::UnnamedField(..) => {}
1055-
}
1056-
}
1057-
};
10581022
match item.node {
10591023
// implementations of traits don't need visibility qualifiers because
10601024
// that's controlled by having the trait in scope.
@@ -1067,22 +1031,14 @@ impl<'a> SanePrivacyVisitor<'a> {
10671031
}
10681032
}
10691033

1070-
ast::ItemImpl(_, _, _, ref methods) => {
1034+
ast::ItemImpl(..) => {
10711035
check_inherited(item.span, item.vis,
10721036
"place qualifiers on individual methods instead");
1073-
for i in methods.iter() {
1074-
check_not_priv(i.span, i.vis, "functions are private by \
1075-
default");
1076-
}
10771037
}
1078-
ast::ItemForeignMod(ref fm) => {
1038+
ast::ItemForeignMod(..) => {
10791039
check_inherited(item.span, item.vis,
10801040
"place qualifiers on individual functions \
10811041
instead");
1082-
for i in fm.items.iter() {
1083-
check_not_priv(i.span, i.vis, "functions are private by \
1084-
default");
1085-
}
10861042
}
10871043

10881044
ast::ItemEnum(ref def, _) => {
@@ -1094,24 +1050,11 @@ impl<'a> SanePrivacyVisitor<'a> {
10941050
visibility");
10951051
}
10961052
}
1097-
ast::Private => {
1098-
if item.vis != ast::Public {
1099-
tcx.sess.span_err(v.span, "unnecessary `priv` \
1100-
visibility");
1101-
}
1102-
}
11031053
ast::Inherited => {}
11041054
}
1105-
1106-
match v.node.kind {
1107-
ast::StructVariantKind(ref s) => check_struct(s),
1108-
ast::TupleVariantKind(..) => {}
1109-
}
11101055
}
11111056
}
11121057

1113-
ast::ItemStruct(ref def, _) => check_struct(def),
1114-
11151058
ast::ItemTrait(_, _, ref methods) => {
11161059
for m in methods.iter() {
11171060
match *m {
@@ -1124,12 +1067,9 @@ impl<'a> SanePrivacyVisitor<'a> {
11241067
}
11251068
}
11261069

1127-
ast::ItemStatic(..) |
1070+
ast::ItemStatic(..) | ast::ItemStruct(..) |
11281071
ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
1129-
ast::ItemMac(..) => {
1130-
check_not_priv(item.span, item.vis, "items are private by \
1131-
default");
1132-
}
1072+
ast::ItemMac(..) => {}
11331073
}
11341074
}
11351075

src/librustc/middle/resolve.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1421,12 +1421,8 @@ impl<'a> Resolver<'a> {
14211421
variant: &Variant,
14221422
item_id: DefId,
14231423
parent: ReducedGraphParent,
1424-
parent_public: bool) {
1424+
is_public: bool) {
14251425
let ident = variant.node.name;
1426-
// FIXME: this is unfortunate to have to do this privacy calculation
1427-
// here. This should be living in middle::privacy, but it's
1428-
// necessary to keep around in some form becaues of glob imports...
1429-
let is_public = parent_public && variant.node.vis != ast::Private;
14301426

14311427
match variant.node.kind {
14321428
TupleVariantKind(_) => {
@@ -1668,12 +1664,11 @@ impl<'a> Resolver<'a> {
16681664
// We assume the parent is visible, or else we wouldn't have seen
16691665
// it. Also variants are public-by-default if the parent was also
16701666
// public.
1671-
let is_public = vis != ast::Private;
16721667
if is_struct {
1673-
child_name_bindings.define_type(def, DUMMY_SP, is_public);
1668+
child_name_bindings.define_type(def, DUMMY_SP, true);
16741669
self.structs.insert(variant_id);
16751670
} else {
1676-
child_name_bindings.define_value(def, DUMMY_SP, is_public);
1671+
child_name_bindings.define_value(def, DUMMY_SP, true);
16771672
}
16781673
}
16791674
DefFn(..) | DefStaticMethod(..) | DefStatic(..) => {

0 commit comments

Comments
 (0)