Skip to content

Commit 0d817ee

Browse files
committed
auto merge of #8423 : alexcrichton/rust/less-priv-again, r=bstrie
Closes #5495
2 parents f02cc6b + 930885d commit 0d817ee

36 files changed

+234
-121
lines changed

src/libextra/crypto/sha1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Sha1 {
159159
}
160160

161161
impl Digest for Sha1 {
162-
pub fn reset(&mut self) {
162+
fn reset(&mut self) {
163163
self.length_bits = 0;
164164
self.h[0] = 0x67452301u32;
165165
self.h[1] = 0xEFCDAB89u32;
@@ -169,9 +169,9 @@ impl Digest for Sha1 {
169169
self.buffer.reset();
170170
self.computed = false;
171171
}
172-
pub fn input(&mut self, msg: &[u8]) { add_input(self, msg); }
173-
pub fn result(&mut self, out: &mut [u8]) { return mk_result(self, out); }
174-
pub fn output_bits(&self) -> uint { 160 }
172+
fn input(&mut self, msg: &[u8]) { add_input(self, msg); }
173+
fn result(&mut self, out: &mut [u8]) { return mk_result(self, out); }
174+
fn output_bits(&self) -> uint { 160 }
175175
}
176176

177177
#[cfg(test)]

src/libextra/enum_set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub struct EnumSet<E> {
2121
/// An iterface for casting C-like enum to uint and back.
2222
pub trait CLike {
2323
/// Converts C-like enum to uint.
24-
pub fn to_uint(&self) -> uint;
24+
fn to_uint(&self) -> uint;
2525
/// Converts uint to C-like enum.
26-
pub fn from_uint(uint) -> Self;
26+
fn from_uint(uint) -> Self;
2727
}
2828

2929
fn bit<E:CLike>(e: E) -> uint {
@@ -142,11 +142,11 @@ mod test {
142142
}
143143

144144
impl CLike for Foo {
145-
pub fn to_uint(&self) -> uint {
145+
fn to_uint(&self) -> uint {
146146
*self as uint
147147
}
148148

149-
pub fn from_uint(v: uint) -> Foo {
149+
fn from_uint(v: uint) -> Foo {
150150
unsafe { cast::transmute(v) }
151151
}
152152
}

src/libextra/num/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl ToStrRadix for BigUint {
537537
impl FromStrRadix for BigUint {
538538
/// Creates and initializes an BigUint.
539539
540-
pub fn from_str_radix(s: &str, radix: uint)
540+
fn from_str_radix(s: &str, radix: uint)
541541
-> Option<BigUint> {
542542
BigUint::parse_bytes(s.as_bytes(), radix)
543543
}

src/libextra/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct Metric {
104104
pub struct MetricMap(TreeMap<~str,Metric>);
105105

106106
impl Clone for MetricMap {
107-
pub fn clone(&self) -> MetricMap {
107+
fn clone(&self) -> MetricMap {
108108
MetricMap((**self).clone())
109109
}
110110
}

src/libextra/treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ impl<K: TotalOrd, V, T: Iterator<(K, V)>> Extendable<(K, V), T> for TreeMap<K, V
853853
}
854854

855855
impl<T: TotalOrd, Iter: Iterator<T>> FromIterator<T, Iter> for TreeSet<T> {
856-
pub fn from_iterator(iter: &mut Iter) -> TreeSet<T> {
856+
fn from_iterator(iter: &mut Iter) -> TreeSet<T> {
857857
let mut set = TreeSet::new();
858858
set.extend(iter);
859859
set

src/libextra/url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ pub fn to_str(url: &Url) -> ~str {
701701
}
702702

703703
impl ToStr for Url {
704-
pub fn to_str(&self) -> ~str {
704+
fn to_str(&self) -> ~str {
705705
to_str(self)
706706
}
707707
}

src/librustc/middle/privacy.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
351351
// Do not check privacy inside items with the resolve_unexported
352352
// attribute. This is used for the test runner.
353353
if !attr::contains_name(item.attrs, "!resolve_unexported") {
354+
check_sane_privacy(tcx, item);
354355
oldvisit::visit_item(item, (method_map, visitor));
355356
}
356357
},
@@ -540,3 +541,81 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
540541
});
541542
oldvisit::visit_crate(crate, (method_map, visitor));
542543
}
544+
545+
/// Validates all of the visibility qualifers placed on the item given. This
546+
/// ensures that there are no extraneous qualifiers that don't actually do
547+
/// anything. In theory these qualifiers wouldn't parse, but that may happen
548+
/// later on down the road...
549+
fn check_sane_privacy(tcx: ty::ctxt, item: @ast::item) {
550+
match item.node {
551+
// implementations of traits don't need visibility qualifiers because
552+
// that's controlled by having the trait in scope.
553+
ast::item_impl(_, Some(*), _, ref methods) => {
554+
for m in methods.iter() {
555+
match m.vis {
556+
ast::private | ast::public => {
557+
tcx.sess.span_err(m.span, "unnecessary visibility")
558+
}
559+
ast::inherited => {}
560+
}
561+
}
562+
}
563+
564+
ast::item_enum(ref def, _) => {
565+
for v in def.variants.iter() {
566+
match v.node.vis {
567+
ast::public => {
568+
if item.vis == ast::public {
569+
tcx.sess.span_err(v.span, "unnecessary `pub` \
570+
visibility");
571+
}
572+
}
573+
ast::private => {
574+
if item.vis != ast::public {
575+
tcx.sess.span_err(v.span, "unnecessary `priv` \
576+
visibility");
577+
}
578+
}
579+
ast::inherited => {}
580+
}
581+
}
582+
}
583+
584+
ast::item_struct(ref def, _) => {
585+
for f in def.fields.iter() {
586+
match f.node.kind {
587+
ast::named_field(_, ast::public) => {
588+
tcx.sess.span_err(f.span, "unnecessary `pub` \
589+
visibility");
590+
}
591+
ast::named_field(_, ast::private) => {
592+
// Fields should really be private by default...
593+
}
594+
ast::named_field(*) | ast::unnamed_field => {}
595+
}
596+
}
597+
}
598+
599+
ast::item_trait(_, _, ref methods) => {
600+
for m in methods.iter() {
601+
match *m {
602+
ast::provided(ref m) => {
603+
match m.vis {
604+
ast::private | ast::public => {
605+
tcx.sess.span_err(m.span, "unnecessary \
606+
visibility");
607+
}
608+
ast::inherited => {}
609+
}
610+
}
611+
// this is warned about in the parser
612+
ast::required(*) => {}
613+
}
614+
}
615+
}
616+
617+
ast::item_impl(*) | ast::item_static(*) | ast::item_foreign_mod(*) |
618+
ast::item_fn(*) | ast::item_mod(*) | ast::item_ty(*) |
619+
ast::item_mac(*) => {}
620+
}
621+
}

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'self> StatRecorder<'self> {
165165

166166
#[unsafe_destructor]
167167
impl<'self> Drop for StatRecorder<'self> {
168-
pub fn drop(&self) {
168+
fn drop(&self) {
169169
if self.ccx.sess.trans_stats() {
170170
let end = time::precise_time_ns();
171171
let elapsed = ((end - self.start) / 1_000_000) as uint;

src/librustc/middle/ty.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ pub fn AllBuiltinBounds() -> BuiltinBounds {
709709
}
710710

711711
impl CLike for BuiltinBound {
712-
pub fn to_uint(&self) -> uint {
712+
fn to_uint(&self) -> uint {
713713
*self as uint
714714
}
715-
pub fn from_uint(v: uint) -> BuiltinBound {
715+
fn from_uint(v: uint) -> BuiltinBound {
716716
unsafe { cast::transmute(v) }
717717
}
718718
}
@@ -4345,16 +4345,16 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
43454345
}
43464346

43474347
pub trait ExprTyProvider {
4348-
pub fn expr_ty(&self, ex: &ast::expr) -> t;
4349-
pub fn ty_ctxt(&self) -> ctxt;
4348+
fn expr_ty(&self, ex: &ast::expr) -> t;
4349+
fn ty_ctxt(&self) -> ctxt;
43504350
}
43514351

43524352
impl ExprTyProvider for ctxt {
4353-
pub fn expr_ty(&self, ex: &ast::expr) -> t {
4353+
fn expr_ty(&self, ex: &ast::expr) -> t {
43544354
expr_ty(*self, ex)
43554355
}
43564356

4357-
pub fn ty_ctxt(&self) -> ctxt {
4357+
fn ty_ctxt(&self) -> ctxt {
43584358
*self
43594359
}
43604360
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ pub fn blank_fn_ctxt(ccx: @mut CrateCtxt,
287287
}
288288

289289
impl ExprTyProvider for FnCtxt {
290-
pub fn expr_ty(&self, ex: &ast::expr) -> ty::t {
290+
fn expr_ty(&self, ex: &ast::expr) -> ty::t {
291291
self.expr_ty(ex)
292292
}
293293

294-
pub fn ty_ctxt(&self) -> ty::ctxt {
294+
fn ty_ctxt(&self) -> ty::ctxt {
295295
self.ccx.tcx
296296
}
297297
}

0 commit comments

Comments
 (0)