]> git.lizzy.rs Git - rust.git/commitdiff
Forbid pub/priv where it has no effect
authorAlex Crichton <alex@alexcrichton.com>
Fri, 9 Aug 2013 08:25:24 +0000 (01:25 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 13 Aug 2013 06:20:46 +0000 (23:20 -0700)
Closes #5495

36 files changed:
src/libextra/crypto/sha1.rs
src/libextra/enum_set.rs
src/libextra/num/bigint.rs
src/libextra/test.rs
src/libextra/treemap.rs
src/libextra/url.rs
src/librustc/middle/privacy.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/infer/error_reporting.rs
src/librustc/middle/typeck/mod.rs
src/librustdoc/config.rs
src/libstd/num/num.rs
src/libstd/ptr.rs
src/libstd/rand.rs
src/libstd/rt/io/comm_adapters.rs
src/libstd/rt/uv/mod.rs
src/libstd/str.rs
src/libstd/vec.rs
src/libsyntax/ast_util.rs
src/libsyntax/attr.rs
src/libsyntax/codemap.rs
src/libsyntax/ext/deriving/generic.rs
src/libsyntax/ext/quote.rs
src/libsyntax/opt_vec.rs
src/libsyntax/parse/obsolete.rs
src/libsyntax/parse/parser.rs
src/test/auxiliary/private_variant_xc.rs
src/test/auxiliary/reexported_static_methods.rs
src/test/compile-fail/lint-missing-doc.rs
src/test/compile-fail/useless-priv.rs [new file with mode: 0644]
src/test/compile-fail/useless-priv2.rs [new file with mode: 0644]
src/test/run-pass/bug-7295.rs
src/test/run-pass/issue-7712.rs
src/test/run-pass/static-methods-in-traits.rs

index aa52902c27d11ea28dc4ab2a8ed63f2fbca32b19..8ee9006f6136c0f33984a8ce5aa7f43a0dee8c28 100644 (file)
@@ -159,7 +159,7 @@ pub fn new() -> Sha1 {
 }
 
 impl Digest for Sha1 {
-    pub fn reset(&mut self) {
+    fn reset(&mut self) {
         self.length_bits = 0;
         self.h[0] = 0x67452301u32;
         self.h[1] = 0xEFCDAB89u32;
@@ -169,9 +169,9 @@ pub fn reset(&mut self) {
         self.buffer.reset();
         self.computed = false;
     }
-    pub fn input(&mut self, msg: &[u8]) { add_input(self, msg); }
-    pub fn result(&mut self, out: &mut [u8]) { return mk_result(self, out); }
-    pub fn output_bits(&self) -> uint { 160 }
+    fn input(&mut self, msg: &[u8]) { add_input(self, msg); }
+    fn result(&mut self, out: &mut [u8]) { return mk_result(self, out); }
+    fn output_bits(&self) -> uint { 160 }
 }
 
 #[cfg(test)]
index 25501faa02e12dd000cc8f1a5201251c1a5d939b..28ff16c43e8afbc79d9ad5efe665d35507a6b86d 100644 (file)
@@ -21,9 +21,9 @@ pub struct EnumSet<E> {
 /// An iterface for casting C-like enum to uint and back.
 pub trait CLike {
     /// Converts C-like enum to uint.
-    pub fn to_uint(&self) -> uint;
+    fn to_uint(&self) -> uint;
     /// Converts uint to C-like enum.
-    pub fn from_uint(uint) -> Self;
+    fn from_uint(uint) -> Self;
 }
 
 fn bit<E:CLike>(e: E) -> uint {
@@ -142,11 +142,11 @@ enum Foo {
     }
 
     impl CLike for Foo {
-        pub fn to_uint(&self) -> uint {
+        fn to_uint(&self) -> uint {
             *self as uint
         }
 
-        pub fn from_uint(v: uint) -> Foo {
+        fn from_uint(v: uint) -> Foo {
             unsafe { cast::transmute(v) }
         }
     }
index 27dfc090f8888a093fd01a766e46b7ca0bf5f8f5..354696ef42060642e23ee3fa6b7e58a756cd57b4 100644 (file)
@@ -537,7 +537,7 @@ fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
 impl FromStrRadix for BigUint {
     /// Creates and initializes an BigUint.
 
-    pub fn from_str_radix(s: &str, radix: uint)
+    fn from_str_radix(s: &str, radix: uint)
         -> Option<BigUint> {
         BigUint::parse_bytes(s.as_bytes(), radix)
     }
index 8b7332ff545a4868c9f62a1942dffe0cb4fc3c7e..a9c3bf98cb6599684c13cfc5bb99bba9abe56e78 100644 (file)
@@ -104,7 +104,7 @@ pub struct Metric {
 pub struct MetricMap(TreeMap<~str,Metric>);
 
 impl Clone for MetricMap {
-    pub fn clone(&self) -> MetricMap {
+    fn clone(&self) -> MetricMap {
         MetricMap((**self).clone())
     }
 }
index f5a61692509ad2a322907d867eca00c2b59ec7f1..486a7dab5c1bb105a58c797152254ef2be690c06 100644 (file)
@@ -853,7 +853,7 @@ fn extend(&mut self, iter: &mut T) {
 }
 
 impl<T: TotalOrd, Iter: Iterator<T>> FromIterator<T, Iter> for TreeSet<T> {
-    pub fn from_iterator(iter: &mut Iter) -> TreeSet<T> {
+    fn from_iterator(iter: &mut Iter) -> TreeSet<T> {
         let mut set = TreeSet::new();
         set.extend(iter);
         set
index 581bdf2a294dbd6e1f1562b7492a5ba362e60f06..3f23cbd02abab64abcea103b919f4d56fcf1b9b2 100644 (file)
@@ -701,7 +701,7 @@ pub fn to_str(url: &Url) -> ~str {
 }
 
 impl ToStr for Url {
-    pub fn to_str(&self) -> ~str {
+    fn to_str(&self) -> ~str {
         to_str(self)
     }
 }
index aa7b2e55cdc63b423f0b3a06d4b20ba6ace48ece..54e7c79e97cc2c96c8cce196a23603dadfff44cb 100644 (file)
@@ -351,6 +351,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
             // Do not check privacy inside items with the resolve_unexported
             // attribute. This is used for the test runner.
             if !attr::contains_name(item.attrs, "!resolve_unexported") {
+                check_sane_privacy(tcx, item);
                 oldvisit::visit_item(item, (method_map, visitor));
             }
         },
@@ -540,3 +541,81 @@ struct variant \
     });
     oldvisit::visit_crate(crate, (method_map, visitor));
 }
+
+/// Validates all of the visibility qualifers placed on the item given. This
+/// ensures that there are no extraneous qualifiers that don't actually do
+/// anything. In theory these qualifiers wouldn't parse, but that may happen
+/// later on down the road...
+fn check_sane_privacy(tcx: ty::ctxt, item: @ast::item) {
+    match item.node {
+        // implementations of traits don't need visibility qualifiers because
+        // that's controlled by having the trait in scope.
+        ast::item_impl(_, Some(*), _, ref methods) => {
+            for m in methods.iter() {
+                match m.vis {
+                    ast::private | ast::public => {
+                        tcx.sess.span_err(m.span, "unnecessary visibility")
+                    }
+                    ast::inherited => {}
+                }
+            }
+        }
+
+        ast::item_enum(ref def, _) => {
+            for v in def.variants.iter() {
+                match v.node.vis {
+                    ast::public => {
+                        if item.vis == ast::public {
+                            tcx.sess.span_err(v.span, "unnecessary `pub` \
+                                                       visibility");
+                        }
+                    }
+                    ast::private => {
+                        if item.vis != ast::public {
+                            tcx.sess.span_err(v.span, "unnecessary `priv` \
+                                                       visibility");
+                        }
+                    }
+                    ast::inherited => {}
+                }
+            }
+        }
+
+        ast::item_struct(ref def, _) => {
+            for f in def.fields.iter() {
+                match f.node.kind {
+                    ast::named_field(_, ast::public) => {
+                        tcx.sess.span_err(f.span, "unnecessary `pub` \
+                                                   visibility");
+                    }
+                    ast::named_field(_, ast::private) => {
+                        // Fields should really be private by default...
+                    }
+                    ast::named_field(*) | ast::unnamed_field => {}
+                }
+            }
+        }
+
+        ast::item_trait(_, _, ref methods) => {
+            for m in methods.iter() {
+                match *m {
+                    ast::provided(ref m) => {
+                        match m.vis {
+                            ast::private | ast::public => {
+                                tcx.sess.span_err(m.span, "unnecessary \
+                                                           visibility");
+                            }
+                            ast::inherited => {}
+                        }
+                    }
+                    // this is warned about in the parser
+                    ast::required(*) => {}
+                }
+            }
+        }
+
+        ast::item_impl(*) | ast::item_static(*) | ast::item_foreign_mod(*) |
+        ast::item_fn(*) | ast::item_mod(*) | ast::item_ty(*) |
+        ast::item_mac(*) => {}
+    }
+}
index 1291a586682abc7438d35cc48b0223fb7b6041f7..7331b50dd107c95a5743829aa46fce6167cfdf7d 100644 (file)
@@ -165,7 +165,7 @@ pub fn new(ccx: @mut CrateContext,
 
 #[unsafe_destructor]
 impl<'self> Drop for StatRecorder<'self> {
-    pub fn drop(&self) {
+    fn drop(&self) {
         if self.ccx.sess.trans_stats() {
             let end = time::precise_time_ns();
             let elapsed = ((end - self.start) / 1_000_000) as uint;
index 2ba6930d9c5ea5193cd41e6071703708fc47984c..80d6ce6ab080971f36967675ba5f299d92c1d671 100644 (file)
@@ -709,10 +709,10 @@ pub fn AllBuiltinBounds() -> BuiltinBounds {
 }
 
 impl CLike for BuiltinBound {
-    pub fn to_uint(&self) -> uint {
+    fn to_uint(&self) -> uint {
         *self as uint
     }
-    pub fn from_uint(v: uint) -> BuiltinBound {
+    fn from_uint(v: uint) -> BuiltinBound {
         unsafe { cast::transmute(v) }
     }
 }
@@ -4345,16 +4345,16 @@ fn normalize_vstore(vstore: vstore) -> vstore {
 }
 
 pub trait ExprTyProvider {
-    pub fn expr_ty(&self, ex: &ast::expr) -> t;
-    pub fn ty_ctxt(&self) -> ctxt;
+    fn expr_ty(&self, ex: &ast::expr) -> t;
+    fn ty_ctxt(&self) -> ctxt;
 }
 
 impl ExprTyProvider for ctxt {
-    pub fn expr_ty(&self, ex: &ast::expr) -> t {
+    fn expr_ty(&self, ex: &ast::expr) -> t {
         expr_ty(*self, ex)
     }
 
-    pub fn ty_ctxt(&self) -> ctxt {
+    fn ty_ctxt(&self) -> ctxt {
         *self
     }
 }
index e7ef30c4576c4868803cd7bfbcbf7ed2ce37de70..d27b7f07a12271253b699360a0a430357ede7a2d 100644 (file)
@@ -287,11 +287,11 @@ pub fn blank_fn_ctxt(ccx: @mut CrateCtxt,
 }
 
 impl ExprTyProvider for FnCtxt {
-    pub fn expr_ty(&self, ex: &ast::expr) -> ty::t {
+    fn expr_ty(&self, ex: &ast::expr) -> ty::t {
         self.expr_ty(ex)
     }
 
-    pub fn ty_ctxt(&self) -> ty::ctxt {
+    fn ty_ctxt(&self) -> ty::ctxt {
         self.ccx.tcx
     }
 }
index 1b325dd8a4b99fec36cab5e3bfd65cd0a2aaac72..2c8e7b280598ef81603df489b980fdca27750ef4 100644 (file)
 use util::ppaux::note_and_explain_region;
 
 pub trait ErrorReporting {
-    pub fn report_region_errors(@mut self,
-                                errors: &OptVec<RegionResolutionError>);
+    fn report_region_errors(@mut self,
+                            errors: &OptVec<RegionResolutionError>);
 
-    pub fn report_and_explain_type_error(@mut self,
-                                         trace: TypeTrace,
-                                         terr: &ty::type_err);
+    fn report_and_explain_type_error(@mut self,
+                                     trace: TypeTrace,
+                                     terr: &ty::type_err);
 
     fn values_str(@mut self, values: &ValuePairs) -> Option<~str>;
 
@@ -112,8 +112,8 @@ fn report_sup_sup_conflict(@mut self,
 
 
 impl ErrorReporting for InferCtxt {
-    pub fn report_region_errors(@mut self,
-                                errors: &OptVec<RegionResolutionError>) {
+    fn report_region_errors(@mut self,
+                            errors: &OptVec<RegionResolutionError>) {
         for error in errors.iter() {
             match *error {
                 ConcreteFailure(origin, sub, sup) => {
@@ -139,7 +139,7 @@ pub fn report_region_errors(@mut self,
         }
     }
 
-    pub fn report_and_explain_type_error(@mut self,
+    fn report_and_explain_type_error(@mut self,
                                      trace: TypeTrace,
                                      terr: &ty::type_err) {
         let tcx = self.tcx;
index 53ae80f19facc3354325fcdd3c873c24724162bd..61027519b5b9dddbced8cca323b8f2a686eaf478 100644 (file)
@@ -294,11 +294,11 @@ trait get_and_find_region {
 }
 
 impl get_and_find_region for isr_alist {
-    pub fn get(&self, br: ty::bound_region) -> ty::Region {
+    fn get(&self, br: ty::bound_region) -> ty::Region {
         self.find(br).unwrap()
     }
 
-    pub fn find(&self, br: ty::bound_region) -> Option<ty::Region> {
+    fn find(&self, br: ty::bound_region) -> Option<ty::Region> {
         let mut ret = None;
         do list::each(*self) |isr| {
             let (isr_br, isr_r) = *isr;
index 877338902cc07ebf4e6b596c7d0fbcf3315708b8..dd43e22fc0c57b051239e4d09b68652c27cef71e 100644 (file)
 #[deriving(Clone, Eq)]
 pub enum OutputFormat {
     /// Markdown
-    pub Markdown,
+    Markdown,
     /// HTML, via markdown and pandoc
-    pub PandocHtml
+    PandocHtml
 }
 
 /// How to organize the output
 #[deriving(Clone, Eq)]
 pub enum OutputStyle {
     /// All in a single document
-    pub DocPerCrate,
+    DocPerCrate,
     /// Each module in its own document
-    pub DocPerMod
+    DocPerMod
 }
 
 /// The configuration for a rustdoc session
index 3af1666b4dad3b4fbdaf13f5fd5741f600168a66..9e72b355bf9f96ae2d10f4a4c1b36893f0c96319 100644 (file)
@@ -414,11 +414,11 @@ fn from<N:NumCast>(n: N) -> $T {
 impl_num_cast!(float, to_float)
 
 pub trait ToStrRadix {
-    pub fn to_str_radix(&self, radix: uint) -> ~str;
+    fn to_str_radix(&self, radix: uint) -> ~str;
 }
 
 pub trait FromStrRadix {
-    pub fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
+    fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
 }
 
 /// Calculates a power to a given radix, optimized for uint `pow` and `radix`.
index 96f3e480617ad8f0f56b8da4e8f5e9dfb6b8d19c..b13d46d540d4adae771882066939ec0011ffe512 100644 (file)
@@ -394,7 +394,7 @@ impl<T, I: Int> Add<I, *T> for *T {
     /// Add an integer value to a pointer to get an offset pointer.
     /// Is calculated according to the size of the type pointed to.
     #[inline]
-    pub fn add(&self, rhs: &I) -> *T {
+    fn add(&self, rhs: &I) -> *T {
         self.offset(rhs.to_int() as int)
     }
 }
@@ -404,7 +404,7 @@ impl<T, I: Int> Sub<I, *T> for *T {
     /// Subtract an integer value from a pointer to get an offset pointer.
     /// Is calculated according to the size of the type pointed to.
     #[inline]
-    pub fn sub(&self, rhs: &I) -> *T {
+    fn sub(&self, rhs: &I) -> *T {
         self.offset(-rhs.to_int() as int)
     }
 }
@@ -414,7 +414,7 @@ impl<T, I: Int> Add<I, *mut T> for *mut T {
     /// Add an integer value to a pointer to get an offset pointer.
     /// Is calculated according to the size of the type pointed to.
     #[inline]
-    pub fn add(&self, rhs: &I) -> *mut T {
+    fn add(&self, rhs: &I) -> *mut T {
         self.offset(rhs.to_int() as int)
     }
 }
@@ -424,7 +424,7 @@ impl<T, I: Int> Sub<I, *mut T> for *mut T {
     /// Subtract an integer value from a pointer to get an offset pointer.
     /// Is calculated according to the size of the type pointed to.
     #[inline]
-    pub fn sub(&self, rhs: &I) -> *mut T {
+    fn sub(&self, rhs: &I) -> *mut T {
         self.offset(-rhs.to_int() as int)
     }
 }
index 5f8fa9fddbcf7c2808f06ea9247590d49d4fa297..500278fddb0b16110bd329e42ebc62b7566b560c 100644 (file)
@@ -260,7 +260,7 @@ pub mod rustrt {
 /// A random number generator
 pub trait Rng {
     /// Return the next random integer
-    pub fn next(&mut self) -> u32;
+    fn next(&mut self) -> u32;
 }
 
 /// A value with a particular weight compared to other values
@@ -825,7 +825,7 @@ pub struct XorShiftRng {
 
 impl Rng for XorShiftRng {
     #[inline]
-    pub fn next(&mut self) -> u32 {
+    fn next(&mut self) -> u32 {
         let x = self.x;
         let t = x ^ (x << 11);
         self.x = self.y;
index 6a3e44b2a4d7009a3c914c08a4de7530501c3cae..06424fee8bc121831a71eb2aeb5afd69a8240f75 100644 (file)
@@ -31,9 +31,9 @@ pub fn new(_chan: C) -> ChanWriter<C> { fail!() }
 }
 
 impl<C: GenericChan<~[u8]>> Writer for ChanWriter<C> {
-    pub fn write(&mut self, _buf: &[u8]) { fail!() }
+    fn write(&mut self, _buf: &[u8]) { fail!() }
 
-    pub fn flush(&mut self) { fail!() }
+    fn flush(&mut self) { fail!() }
 }
 
 struct ReaderPort<R>;
index ae5e7dd27b5f3188760e3ddd0ba1cfc5e1132591..6c5a28b31b1e4e43568cb442ed5d06c35dc13900 100644 (file)
@@ -90,8 +90,8 @@ pub trait Request { }
 
 /// A type that wraps a native handle
 pub trait NativeHandle<T> {
-    pub fn from_native_handle(T) -> Self;
-    pub fn native_handle(&self) -> T;
+    fn from_native_handle(T) -> Self;
+    fn native_handle(&self) -> T;
 }
 
 impl Loop {
@@ -155,7 +155,7 @@ pub trait WatcherInterop {
 
 impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
     /// Get the uv event loop from a Watcher
-    pub fn event_loop(&self) -> Loop {
+    fn event_loop(&self) -> Loop {
         unsafe {
             let handle = self.native_handle();
             let loop_ = uvll::get_loop_for_uv_handle(handle);
@@ -163,7 +163,7 @@ pub fn event_loop(&self) -> Loop {
         }
     }
 
-    pub fn install_watcher_data(&mut self) {
+    fn install_watcher_data(&mut self) {
         unsafe {
             let data = ~WatcherData {
                 read_cb: None,
@@ -182,7 +182,7 @@ pub fn install_watcher_data(&mut self) {
         }
     }
 
-    pub fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData {
+    fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData {
         unsafe {
             let data = uvll::get_data_for_uv_handle(self.native_handle());
             let data = transmute::<&*c_void, &mut ~WatcherData>(&data);
@@ -190,7 +190,7 @@ pub fn get_watcher_data<'r>(&'r mut self) -> &'r mut WatcherData {
         }
     }
 
-    pub fn drop_watcher_data(&mut self) {
+    fn drop_watcher_data(&mut self) {
         unsafe {
             let data = uvll::get_data_for_uv_handle(self.native_handle());
             let _data = transmute::<*c_void, ~WatcherData>(data);
index 9e5f2db4092e8eea935bf43985358692730ccc7f..886e4d86ab643f23d3ed3003489ad154dae749e2 100644 (file)
@@ -142,13 +142,13 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
 
 #[allow(missing_doc)]
 pub trait StrVector {
-    pub fn concat(&self) -> ~str;
-    pub fn connect(&self, sep: &str) -> ~str;
+    fn concat(&self) -> ~str;
+    fn connect(&self, sep: &str) -> ~str;
 }
 
 impl<'self, S: Str> StrVector for &'self [S] {
     /// Concatenate a vector of strings.
-    pub fn concat(&self) -> ~str {
+    fn concat(&self) -> ~str {
         if self.is_empty() { return ~""; }
 
         let len = self.iter().map(|s| s.as_slice().len()).sum();
@@ -171,7 +171,7 @@ pub fn concat(&self) -> ~str {
     }
 
     /// Concatenate a vector of strings, placing a given separator between each.
-    pub fn connect(&self, sep: &str) -> ~str {
+    fn connect(&self, sep: &str) -> ~str {
         if self.is_empty() { return ~""; }
 
         // concat is faster
@@ -1554,7 +1554,7 @@ fn trim_right_chars<C: CharEq>(&self, to_trim: &C) -> &'self str {
     /// # Return value
     ///
     /// The original string with all occurances of `from` replaced with `to`
-    pub fn replace(&self, from: &str, to: &str) -> ~str {
+    fn replace(&self, from: &str, to: &str) -> ~str {
         let mut result = ~"";
         let mut last_end = 0;
         for (start, end) in self.matches_index_iter(from) {
@@ -2081,7 +2081,7 @@ fn append(self, rhs: &str) -> ~str {
     /// * s - A string
     /// * n - The number of bytes to reserve space for
     #[inline]
-    pub fn reserve(&mut self, n: uint) {
+    fn reserve(&mut self, n: uint) {
         unsafe {
             let v: &mut ~[u8] = cast::transmute(self);
             (*v).reserve(n);
index 2228922d9e4d951b9dcec6660649183eb711b3f8..27e09d8547989f1bbe2214f9adaceb97805fb08d 100644 (file)
@@ -313,18 +313,18 @@ pub fn connect_slices<T:Clone>(v: &[&[T]], sep: &T) -> ~[T] { v.connect_vec(sep)
 pub trait VectorVector<T> {
     // FIXME #5898: calling these .concat and .connect conflicts with
     // StrVector::con{cat,nect}, since they have generic contents.
-    pub fn concat_vec(&self) -> ~[T];
-    pub fn connect_vec(&self, sep: &T) -> ~[T];
+    fn concat_vec(&self) -> ~[T];
+    fn connect_vec(&self, sep: &T) -> ~[T];
 }
 
 impl<'self, T:Clone> VectorVector<T> for &'self [~[T]] {
     /// Flattens a vector of slices of T into a single vector of T.
-    pub fn concat_vec(&self) -> ~[T] {
+    fn concat_vec(&self) -> ~[T] {
         self.flat_map(|inner| (*inner).clone())
     }
 
     /// Concatenate a vector of vectors, placing a given separator between each.
-    pub fn connect_vec(&self, sep: &T) -> ~[T] {
+    fn connect_vec(&self, sep: &T) -> ~[T] {
         let mut r = ~[];
         let mut first = true;
         for inner in self.iter() {
@@ -337,12 +337,12 @@ pub fn connect_vec(&self, sep: &T) -> ~[T] {
 
 impl<'self,T:Clone> VectorVector<T> for &'self [&'self [T]] {
     /// Flattens a vector of slices of T into a single vector of T.
-    pub fn concat_vec(&self) -> ~[T] {
+    fn concat_vec(&self) -> ~[T] {
         self.flat_map(|&inner| inner.to_owned())
     }
 
     /// Concatenate a vector of slices, placing a given separator between each.
-    pub fn connect_vec(&self, sep: &T) -> ~[T] {
+    fn connect_vec(&self, sep: &T) -> ~[T] {
         let mut r = ~[];
         let mut first = true;
         for &inner in self.iter() {
@@ -1649,7 +1649,7 @@ impl<T:Eq> OwnedEqVector<T> for ~[T] {
     * Remove consecutive repeated elements from a vector; if the vector is
     * sorted, this removes all duplicates.
     */
-    pub fn dedup(&mut self) {
+    fn dedup(&mut self) {
         unsafe {
             // Although we have a mutable reference to `self`, we cannot make
             // *arbitrary* changes. There exists the possibility that this
@@ -2079,7 +2079,7 @@ pub mod bytes {
     /// A trait for operations on mutable operations on `[u8]`
     pub trait MutableByteVector {
         /// Sets all bytes of the receiver to the given value.
-        pub fn set_memory(self, value: u8);
+        fn set_memory(self, value: u8);
     }
 
     impl<'self> MutableByteVector for &'self mut [u8] {
index d99f8cab4937fad51167888fa80d1660e84e4bc8..02eaf432b5402ba91b62217807ecd2a922cda2ee 100644 (file)
@@ -672,7 +672,7 @@ pub fn walk_pat(pat: @pat, it: &fn(@pat) -> bool) -> bool {
 }
 
 pub trait EachViewItem {
-    pub fn each_view_item(&self, f: @fn(&ast::view_item) -> bool) -> bool;
+    fn each_view_item(&self, f: @fn(&ast::view_item) -> bool) -> bool;
 }
 
 struct EachViewItemData {
index 47d8ebecca06a313fb68f3c49b07d6c7c116bbc6..51df08f52283f9c5509cc852a9d22a2d5d90ea72 100644 (file)
@@ -82,7 +82,7 @@ fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
         }
     }
 
-    pub fn name_str_pair(&self) -> Option<(@str, @str)> {
+    fn name_str_pair(&self) -> Option<(@str, @str)> {
         self.value_str().map_move(|s| (self.name(), s))
     }
 }
@@ -105,14 +105,14 @@ pub trait AttributeMethods {
 
 impl AttributeMethods for Attribute {
     /// Extract the MetaItem from inside this Attribute.
-    pub fn meta(&self) -> @MetaItem {
+    fn meta(&self) -> @MetaItem {
         self.node.value
     }
 
     /// Convert self to a normal #[doc="foo"] comment, if it is a
     /// comment like `///` or `/** */`. (Returns self unchanged for
     /// non-sugared doc attributes.)
-    pub fn desugar_doc(&self) -> Attribute {
+    fn desugar_doc(&self) -> Attribute {
         if self.node.is_sugared_doc {
             let comment = self.value_str().unwrap();
             let meta = mk_name_value_item_str(@"doc",
index 8c70f128d9a09b82408950f3bba087b3189b7d5c..d4337523cfb25826f9850ec945e7ecfad45aba3b 100644 (file)
@@ -194,10 +194,10 @@ pub struct FileLines
 // represents the origin of a file:
 pub enum FileSubstr {
     // indicates that this is a normal standalone file:
-    pub FssNone,
+    FssNone,
     // indicates that this "file" is actually a substring
     // of another file that appears earlier in the codemap
-    pub FssInternal(span),
+    FssInternal(span),
 }
 
 /// Identifies an offset of a multi-byte character in a FileMap
index a1abe47e0909d39b98d2786e4932daa0d1fdfdee..6b028e25c0fff73ef3b8833ed27329167dcc6df3 100644 (file)
@@ -542,7 +542,7 @@ fn create_method(&self, cx: @ExtCtxt, span: span,
             id: cx.next_id(),
             span: span,
             self_id: cx.next_id(),
-            vis: ast::public
+            vis: ast::inherited,
         }
     }
 
index d218be5e47637467013de96f0e260e4dbbb68aa5..9d82bb9c4f8abf07357e0987ca06e6a7394a227b 100644 (file)
@@ -40,11 +40,11 @@ pub mod rt {
     pub use codemap::{BytePos, span, dummy_spanned};
 
     pub trait ToTokens {
-        pub fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree];
+        fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree];
     }
 
     impl ToTokens for ~[token_tree] {
-        pub fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree] {
+        fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree] {
             (*self).clone()
         }
     }
@@ -65,7 +65,7 @@ pub fn to_tokens(cx: @ExtCtxt) -> ~[token_tree] {
 
     pub trait ToSource {
         // Takes a thing and generates a string containing rust code for it.
-        pub fn to_source(&self) -> @str;
+        fn to_source(&self) -> @str;
     }
 
     impl ToSource for ast::ident {
index 3a10206b513f8920d7adbc84a2310cb9f91b423c..2d7801a22dedab7c4a2c02af0a99e13bdd42f408 100644 (file)
@@ -124,7 +124,7 @@ pub fn prepend(&self, t: T) -> OptVec<T> {
 }
 
 impl<A:Eq> Eq for OptVec<A> {
-    pub fn eq(&self, other: &OptVec<A>) -> bool {
+    fn eq(&self, other: &OptVec<A>) -> bool {
         // Note: cannot use #[deriving(Eq)] here because
         // (Empty, Vec(~[])) ought to be equal.
         match (self, other) {
@@ -135,7 +135,7 @@ pub fn eq(&self, other: &OptVec<A>) -> bool {
         }
     }
 
-    pub fn ne(&self, other: &OptVec<A>) -> bool {
+    fn ne(&self, other: &OptVec<A>) -> bool {
         !self.eq(other)
     }
 }
index dda5e990221eccf066d42a502637108f17bad179..01c1af7464db618537f4a311c80fa04fa3c2538c 100644 (file)
@@ -65,6 +65,7 @@ pub enum ObsoleteSyntax {
     ObsoleteExternVisibility,
     ObsoleteUnsafeExternFn,
     ObsoletePrivVisibility,
+    ObsoleteTraitFuncVisibility,
 }
 
 impl to_bytes::IterBytes for ObsoleteSyntax {
@@ -95,7 +96,7 @@ fn report(&self,
 
 impl ParserObsoleteMethods for Parser {
     /// Reports an obsolete syntax non-fatal error.
-    pub fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
+    fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
         let (kind_str, desc) = match kind {
             ObsoleteLet => (
                 "`let` in field declaration",
@@ -258,6 +259,10 @@ pub fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
                 "`priv` not necessary",
                 "an item without a visibility qualifier is private by default"
             ),
+            ObsoleteTraitFuncVisibility => (
+                "visibility not necessary",
+                "trait functions inherit the visibility of the trait itself"
+            ),
         };
 
         self.report(sp, kind, kind_str, desc);
@@ -265,7 +270,7 @@ pub fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
 
     // Reports an obsolete syntax non-fatal error, and returns
     // a placeholder expression
-    pub fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr {
+    fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr {
         self.obsolete(sp, kind);
         self.mk_expr(sp.lo, sp.hi, expr_lit(@respan(sp, lit_nil)))
     }
@@ -283,7 +288,7 @@ fn report(&self,
         }
     }
 
-    pub fn token_is_obsolete_ident(&self, ident: &str, token: &Token)
+    fn token_is_obsolete_ident(&self, ident: &str, token: &Token)
                                    -> bool {
         match *token {
             token::IDENT(sid, _) => {
@@ -293,11 +298,11 @@ pub fn token_is_obsolete_ident(&self, ident: &str, token: &Token)
         }
     }
 
-    pub fn is_obsolete_ident(&self, ident: &str) -> bool {
+    fn is_obsolete_ident(&self, ident: &str) -> bool {
         self.token_is_obsolete_ident(ident, self.token)
     }
 
-    pub fn eat_obsolete_ident(&self, ident: &str) -> bool {
+    fn eat_obsolete_ident(&self, ident: &str) -> bool {
         if self.is_obsolete_ident(ident) {
             self.bump();
             true
@@ -306,7 +311,7 @@ pub fn eat_obsolete_ident(&self, ident: &str) -> bool {
         }
     }
 
-    pub fn try_parse_obsolete_struct_ctor(&self) -> bool {
+    fn try_parse_obsolete_struct_ctor(&self) -> bool {
         if self.eat_obsolete_ident("new") {
             self.obsolete(*self.last_span, ObsoleteStructCtor);
             self.parse_fn_decl();
@@ -317,7 +322,7 @@ pub fn try_parse_obsolete_struct_ctor(&self) -> bool {
         }
     }
 
-    pub fn try_parse_obsolete_with(&self) -> bool {
+    fn try_parse_obsolete_with(&self) -> bool {
         if *self.token == token::COMMA
             && self.look_ahead(1,
                                |t| self.token_is_obsolete_ident("with", t)) {
@@ -332,7 +337,7 @@ pub fn try_parse_obsolete_with(&self) -> bool {
         }
     }
 
-    pub fn try_parse_obsolete_priv_section(&self, attrs: &[Attribute])
+    fn try_parse_obsolete_priv_section(&self, attrs: &[Attribute])
                                            -> bool {
         if self.is_keyword(keywords::Priv) &&
                 self.look_ahead(1, |t| *t == token::LBRACE) {
index 7e18c440d816c49105122a777968a105f2f6833d..b38de31c56a7ff8117836a1bf5ea5f6a9001021e 100644 (file)
 use parse::common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed};
 use parse::lexer::reader;
 use parse::lexer::TokenAndSpan;
-use parse::obsolete::{ObsoleteClassTraits};
-use parse::obsolete::{ObsoleteLet, ObsoleteFieldTerminator};
-use parse::obsolete::{ObsoleteMoveInit, ObsoleteBinaryMove, ObsoleteSwap};
-use parse::obsolete::ObsoleteSyntax;
-use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax};
-use parse::obsolete::{ObsoleteMutOwnedPointer};
-use parse::obsolete::{ObsoleteMutVector, ObsoleteImplVisibility};
-use parse::obsolete::{ObsoleteRecordType, ObsoleteRecordPattern};
-use parse::obsolete::{ObsoletePostFnTySigil};
-use parse::obsolete::{ObsoleteBareFnType, ObsoleteNewtypeEnum};
-use parse::obsolete::ObsoleteMode;
-use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
-use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
-use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
-use parse::obsolete::{ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl};
-use parse::obsolete::{ObsoleteMutWithMultipleBindings};
-use parse::obsolete::{ObsoleteExternVisibility, ObsoleteUnsafeExternFn};
-use parse::obsolete::{ParserObsoleteMethods, ObsoletePrivVisibility};
+use parse::obsolete::*;
 use parse::token::{can_begin_expr, get_ident_interner, ident_to_str, is_ident};
 use parse::token::{is_ident_or_path};
 use parse::token::{is_plain_ident, INTERPOLATED, keywords, special_idents};
@@ -932,6 +915,10 @@ pub fn parse_trait_methods(&self) -> ~[trait_method] {
                 debug!("parse_trait_methods(): parsing required method");
                 // NB: at the moment, visibility annotations on required
                 // methods are ignored; this could change.
+                if vis != ast::inherited {
+                    self.obsolete(*self.last_span,
+                                  ObsoleteTraitFuncVisibility);
+                }
                 required(TypeMethod {
                     ident: ident,
                     attrs: attrs,
index a3a604d9e784c1b83acf8fd2ec64d0525b30d842..e1ecbf8c5432e65de64ba295bcd5befec6d9eeca 100644 (file)
@@ -1,4 +1,4 @@
 pub enum Foo {
-    pub Bar,
+    Bar,
     priv Baz,
 }
index 811bf082ae8915ce3e5883770709c59f51e9ee17..bb20b04762d5af873b51c18c710e3983ccd20900 100644 (file)
 pub use sub_foo::Bort;
 
 pub trait Bar {
-    pub fn bar() -> Self;
+    fn bar() -> Self;
 }
 
 impl Bar for int {
-    pub fn bar() -> int { 84 }
+    fn bar() -> int { 84 }
 }
 
 pub mod sub_foo {
     pub trait Foo {
-        pub fn foo() -> Self;
+        fn foo() -> Self;
     }
 
     impl Foo for int {
-        pub fn foo() -> int { 42 }
+        fn foo() -> int { 42 }
     }
 
     pub struct Boz {
index 2350ca68b9747045693072c6605c2137b91a0b47..75bc93c6d0b30725f3d188f18e7ebd00f5093284 100644 (file)
 struct Foo {
     a: int,
     priv b: int,
-    pub c: int, // doesn't matter, Foo is private
 }
 
 pub struct PubFoo { //~ ERROR: missing documentation
     a: int,      //~ ERROR: missing documentation
     priv b: int,
-    pub c: int,  //~ ERROR: missing documentation
 }
 
 #[allow(missing_doc)]
 pub struct PubFoo2 {
     a: int,
-    pub c: int,
+    c: int,
 }
 
 /// dox
@@ -44,9 +42,9 @@ pub trait C {} //~ ERROR: missing documentation
 
 trait Bar {
     /// dox
-    pub fn foo();
+    fn foo();
     fn foo2(); //~ ERROR: missing documentation
-    pub fn foo3(); //~ ERROR: missing documentation
+    fn foo3(); //~ ERROR: missing documentation
 }
 
 impl Foo {
@@ -59,13 +57,13 @@ fn foo2() {}
 
 #[allow(missing_doc)]
 trait F {
-    pub fn a();
+    fn a();
     fn b(&self);
 }
 
 // should need to redefine documentation for implementations of traits
 impl F for Foo {
-    pub fn a() {}
+    fn a() {}
     fn b(&self) {}
 }
 
diff --git a/src/test/compile-fail/useless-priv.rs b/src/test/compile-fail/useless-priv.rs
new file mode 100644 (file)
index 0000000..3d6841c
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct A { pub i: int }         //~ ERROR: unnecessary `pub`
+struct B { priv i: int }        // don't warn b/c B can still be returned
+pub enum C { pub Variant }      //~ ERROR: unnecessary `pub`
+enum D { priv Variant2 }        //~ ERROR: unnecessary `priv`
+
+pub trait E {
+    pub fn foo() {}             //~ ERROR: unnecessary visibility
+}
+trait F { pub fn foo() {} }     //~ ERROR: unnecessary visibility
+
+impl E for A {
+    pub fn foo() {}             //~ ERROR: unnecessary visibility
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/useless-priv2.rs b/src/test/compile-fail/useless-priv2.rs
new file mode 100644 (file)
index 0000000..0d94300
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait E {
+    pub fn foo();               //~ ERROR: obsolete syntax
+}
+trait F { pub fn foo(); }       //~ ERROR: obsolete syntax
+
+struct B;
+impl E for B {
+    priv fn foo() {}             //~ ERROR: obsolete syntax
+}
index 2a1a0e35c56ed8f8457d01cffd8d5400cddc1871..ea711d78dd28e0bb890693b42e0b3d696739924a 100644 (file)
@@ -9,9 +9,9 @@
 // except according to those terms.
 
 pub trait Foo<T> {
-    pub fn func1<U>(&self, t: U);
+    fn func1<U>(&self, t: U);
 
-    pub fn func2<U>(&self, t: U) {
+    fn func2<U>(&self, t: U) {
         self.func1(t);
     }
 }
index 41c4af86bac95bdc8234a53f74b0ea2eeae74d35..1ea8312ddd927b2bdc2f94b2c51229dec85745e4 100644 (file)
@@ -11,7 +11,7 @@
 // compile-flags:-Z debug-info
 
 pub trait TraitWithDefaultMethod {
-    pub fn method(self) {
+    fn method(self) {
         ()
     }
 }
index 8cd7b78312bf289305eb183c2d810bee38a9900f..180cd115c96e8503002aae46475672494d1d94f5 100644 (file)
 
 mod a {
     pub trait Foo {
-        pub fn foo() -> Self;
+        fn foo() -> Self;
     }
 
     impl Foo for int {
-        pub fn foo() -> int {
+        fn foo() -> int {
             3
         }
     }
 
     impl Foo for uint {
-        pub fn foo() -> uint {
+        fn foo() -> uint {
             5u
         }
     }