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

+4-4
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

+4-4
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+79
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

+1-1
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

+6-6
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

+2-2
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
}

src/librustc/middle/typeck/infer/error_reporting.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ use util::ppaux::UserString;
7676
use util::ppaux::note_and_explain_region;
7777

7878
pub trait ErrorReporting {
79-
pub fn report_region_errors(@mut self,
80-
errors: &OptVec<RegionResolutionError>);
79+
fn report_region_errors(@mut self,
80+
errors: &OptVec<RegionResolutionError>);
8181

82-
pub fn report_and_explain_type_error(@mut self,
83-
trace: TypeTrace,
84-
terr: &ty::type_err);
82+
fn report_and_explain_type_error(@mut self,
83+
trace: TypeTrace,
84+
terr: &ty::type_err);
8585

8686
fn values_str(@mut self, values: &ValuePairs) -> Option<~str>;
8787

@@ -112,8 +112,8 @@ pub trait ErrorReporting {
112112

113113

114114
impl ErrorReporting for InferCtxt {
115-
pub fn report_region_errors(@mut self,
116-
errors: &OptVec<RegionResolutionError>) {
115+
fn report_region_errors(@mut self,
116+
errors: &OptVec<RegionResolutionError>) {
117117
for error in errors.iter() {
118118
match *error {
119119
ConcreteFailure(origin, sub, sup) => {
@@ -139,7 +139,7 @@ impl ErrorReporting for InferCtxt {
139139
}
140140
}
141141

142-
pub fn report_and_explain_type_error(@mut self,
142+
fn report_and_explain_type_error(@mut self,
143143
trace: TypeTrace,
144144
terr: &ty::type_err) {
145145
let tcx = self.tcx;

src/librustc/middle/typeck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ trait get_and_find_region {
294294
}
295295

296296
impl get_and_find_region for isr_alist {
297-
pub fn get(&self, br: ty::bound_region) -> ty::Region {
297+
fn get(&self, br: ty::bound_region) -> ty::Region {
298298
self.find(br).unwrap()
299299
}
300300

301-
pub fn find(&self, br: ty::bound_region) -> Option<ty::Region> {
301+
fn find(&self, br: ty::bound_region) -> Option<ty::Region> {
302302
let mut ret = None;
303303
do list::each(*self) |isr| {
304304
let (isr_br, isr_r) = *isr;

src/librustdoc/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ use extra::getopts;
2222
#[deriving(Clone, Eq)]
2323
pub enum OutputFormat {
2424
/// Markdown
25-
pub Markdown,
25+
Markdown,
2626
/// HTML, via markdown and pandoc
27-
pub PandocHtml
27+
PandocHtml
2828
}
2929

3030
/// How to organize the output
3131
#[deriving(Clone, Eq)]
3232
pub enum OutputStyle {
3333
/// All in a single document
34-
pub DocPerCrate,
34+
DocPerCrate,
3535
/// Each module in its own document
36-
pub DocPerMod
36+
DocPerMod
3737
}
3838

3939
/// The configuration for a rustdoc session

src/libstd/num/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ impl_num_cast!(f64, to_f64)
414414
impl_num_cast!(float, to_float)
415415

416416
pub trait ToStrRadix {
417-
pub fn to_str_radix(&self, radix: uint) -> ~str;
417+
fn to_str_radix(&self, radix: uint) -> ~str;
418418
}
419419

420420
pub trait FromStrRadix {
421-
pub fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
421+
fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
422422
}
423423

424424
/// Calculates a power to a given radix, optimized for uint `pow` and `radix`.

src/libstd/ptr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<T, I: Int> Add<I, *T> for *T {
394394
/// Add an integer value to a pointer to get an offset pointer.
395395
/// Is calculated according to the size of the type pointed to.
396396
#[inline]
397-
pub fn add(&self, rhs: &I) -> *T {
397+
fn add(&self, rhs: &I) -> *T {
398398
self.offset(rhs.to_int() as int)
399399
}
400400
}
@@ -404,7 +404,7 @@ impl<T, I: Int> Sub<I, *T> for *T {
404404
/// Subtract an integer value from a pointer to get an offset pointer.
405405
/// Is calculated according to the size of the type pointed to.
406406
#[inline]
407-
pub fn sub(&self, rhs: &I) -> *T {
407+
fn sub(&self, rhs: &I) -> *T {
408408
self.offset(-rhs.to_int() as int)
409409
}
410410
}
@@ -414,7 +414,7 @@ impl<T, I: Int> Add<I, *mut T> for *mut T {
414414
/// Add an integer value to a pointer to get an offset pointer.
415415
/// Is calculated according to the size of the type pointed to.
416416
#[inline]
417-
pub fn add(&self, rhs: &I) -> *mut T {
417+
fn add(&self, rhs: &I) -> *mut T {
418418
self.offset(rhs.to_int() as int)
419419
}
420420
}
@@ -424,7 +424,7 @@ impl<T, I: Int> Sub<I, *mut T> for *mut T {
424424
/// Subtract an integer value from a pointer to get an offset pointer.
425425
/// Is calculated according to the size of the type pointed to.
426426
#[inline]
427-
pub fn sub(&self, rhs: &I) -> *mut T {
427+
fn sub(&self, rhs: &I) -> *mut T {
428428
self.offset(-rhs.to_int() as int)
429429
}
430430
}

src/libstd/rand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub mod rustrt {
260260
/// A random number generator
261261
pub trait Rng {
262262
/// Return the next random integer
263-
pub fn next(&mut self) -> u32;
263+
fn next(&mut self) -> u32;
264264
}
265265

266266
/// A value with a particular weight compared to other values
@@ -825,7 +825,7 @@ pub struct XorShiftRng {
825825

826826
impl Rng for XorShiftRng {
827827
#[inline]
828-
pub fn next(&mut self) -> u32 {
828+
fn next(&mut self) -> u32 {
829829
let x = self.x;
830830
let t = x ^ (x << 11);
831831
self.x = self.y;

src/libstd/rt/io/comm_adapters.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ impl<C: GenericChan<~[u8]>> ChanWriter<C> {
3131
}
3232

3333
impl<C: GenericChan<~[u8]>> Writer for ChanWriter<C> {
34-
pub fn write(&mut self, _buf: &[u8]) { fail!() }
34+
fn write(&mut self, _buf: &[u8]) { fail!() }
3535

36-
pub fn flush(&mut self) { fail!() }
36+
fn flush(&mut self) { fail!() }
3737
}
3838

3939
struct ReaderPort<R>;

0 commit comments

Comments
 (0)