auto merge of #8423 : alexcrichton/rust/less-priv-again, r=bstrie

Closes #5495
This commit is contained in:
bors 2013-08-13 07:26:23 -07:00
commit 0d817ee869
36 changed files with 234 additions and 121 deletions

View File

@ -159,7 +159,7 @@ impl 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 @@ impl Digest for Sha1 {
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)]

View 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 @@ mod test {
}
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) }
}
}

View File

@ -537,7 +537,7 @@ impl ToStrRadix for BigUint {
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)
}

View 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())
}
}

View File

@ -853,7 +853,7 @@ impl<K: TotalOrd, V, T: Iterator<(K, V)>> Extendable<(K, V), T> for TreeMap<K, V
}
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

View 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)
}
}

View 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 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
});
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(*) => {}
}
}

View File

@ -165,7 +165,7 @@ impl<'self> StatRecorder<'self> {
#[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;

View 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 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
}
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
}
}

View 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
}
}

View File

@ -76,10 +76,10 @@ use util::ppaux::UserString;
use util::ppaux::note_and_explain_region;
pub trait ErrorReporting {
pub fn report_region_errors(@mut self,
fn report_region_errors(@mut self,
errors: &OptVec<RegionResolutionError>);
pub fn report_and_explain_type_error(@mut self,
fn report_and_explain_type_error(@mut self,
trace: TypeTrace,
terr: &ty::type_err);
@ -112,7 +112,7 @@ pub trait ErrorReporting {
impl ErrorReporting for InferCtxt {
pub fn report_region_errors(@mut self,
fn report_region_errors(@mut self,
errors: &OptVec<RegionResolutionError>) {
for error in errors.iter() {
match *error {
@ -139,7 +139,7 @@ impl ErrorReporting for InferCtxt {
}
}
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;

View 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;

View File

@ -22,18 +22,18 @@ use extra::getopts;
#[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

View File

@ -414,11 +414,11 @@ impl_num_cast!(f64, to_f64)
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`.

View 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)
}
}

View 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;

View File

@ -31,9 +31,9 @@ impl<C: GenericChan<~[u8]>> ChanWriter<C> {
}
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>;

View 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 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
}
}
pub fn install_watcher_data(&mut self) {
fn install_watcher_data(&mut self) {
unsafe {
let data = ~WatcherData {
read_cb: None,
@ -182,7 +182,7 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
}
}
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 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
}
}
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);

View 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 @@ impl<'self, S: Str> StrVector for &'self [S] {
}
/// 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 @@ impl<'self> StrSlice<'self> for &'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 @@ impl OwnedStr for ~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);

View 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 @@ impl<'self, T:Clone> VectorVector<T> for &'self [~[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] {

View 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 {

View File

@ -82,7 +82,7 @@ impl AttrMetaMethods for 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",

View 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

View File

@ -542,7 +542,7 @@ impl<'self> MethodDef<'self> {
id: cx.next_id(),
span: span,
self_id: cx.next_id(),
vis: ast::public
vis: ast::inherited,
}
}

View 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 mod rt {
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 {

View File

@ -124,7 +124,7 @@ impl<T:Clone> 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 @@ impl<A:Eq> Eq for OptVec<A> {
}
}
pub fn ne(&self, other: &OptVec<A>) -> bool {
fn ne(&self, other: &OptVec<A>) -> bool {
!self.eq(other)
}
}

View File

@ -65,6 +65,7 @@ pub enum ObsoleteSyntax {
ObsoleteExternVisibility,
ObsoleteUnsafeExternFn,
ObsoletePrivVisibility,
ObsoleteTraitFuncVisibility,
}
impl to_bytes::IterBytes for ObsoleteSyntax {
@ -95,7 +96,7 @@ pub trait ParserObsoleteMethods {
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 @@ impl ParserObsoleteMethods for Parser {
"`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 @@ impl ParserObsoleteMethods for Parser {
// 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 @@ impl ParserObsoleteMethods for Parser {
}
}
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 @@ impl ParserObsoleteMethods for Parser {
}
}
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 @@ impl ParserObsoleteMethods for Parser {
}
}
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 @@ impl ParserObsoleteMethods for Parser {
}
}
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 @@ impl ParserObsoleteMethods for Parser {
}
}
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) {

View File

@ -70,24 +70,7 @@ use parse::common::{SeqSep, seq_sep_none};
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 @@ impl Parser {
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,

View File

@ -1,4 +1,4 @@
pub enum Foo {
pub Bar,
Bar,
priv Baz,
}

View File

@ -14,20 +14,20 @@ pub use sub_foo::Boz;
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 {

View File

@ -15,19 +15,17 @@
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 @@ impl Foo {
#[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) {}
}

View File

@ -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() {}

View File

@ -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
}

View 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);
}
}

View File

@ -11,7 +11,7 @@
// compile-flags:-Z debug-info
pub trait TraitWithDefaultMethod {
pub fn method(self) {
fn method(self) {
()
}
}

View File

@ -10,17 +10,17 @@
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
}
}