diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-02-26 17:12:00 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-02-27 09:40:16 -0800 |
| commit | 07c3f5c0de752166ae34f0fe50e50e65a2403b66 (patch) | |
| tree | 2c40b3bb0659ac6ea6dabed650d8e01de199e3f5 /src/libsyntax | |
| parent | 573a31dfa769887f4be77a621ef4cab2d92a74e5 (diff) | |
| download | rust-07c3f5c0de752166ae34f0fe50e50e65a2403b66.tar.gz rust-07c3f5c0de752166ae34f0fe50e50e65a2403b66.zip | |
librustc: Forbid `pub` or `priv` before trait implementations
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 48 | ||||
| -rw-r--r-- | src/libsyntax/ast_map.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/codemap.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/check.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/parse_proto.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/pipec.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
14 files changed, 73 insertions, 59 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 5af67aa0e3b..744cb92fb1c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -61,7 +61,7 @@ type Name = uint; // with a macro expansion type Mrk = uint; -pub impl<S:Encoder> Encodable<S> for ident { +impl<S:Encoder> Encodable<S> for ident { fn encode(&self, s: &S) { let intr = match unsafe { task::local_data::local_data_get(interner_key!()) @@ -74,7 +74,7 @@ pub impl<S:Encoder> Encodable<S> for ident { } } -pub impl<D:Decoder> Decodable<D> for ident { +impl<D:Decoder> Decodable<D> for ident { static fn decode(d: &D) -> ident { let intr = match unsafe { task::local_data::local_data_get(interner_key!()) @@ -87,7 +87,7 @@ pub impl<D:Decoder> Decodable<D> for ident { } } -pub impl to_bytes::IterBytes for ident { +impl to_bytes::IterBytes for ident { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { self.repr.iter_bytes(lsb0, f) } @@ -246,7 +246,7 @@ pub enum binding_mode { bind_infer } -pub impl to_bytes::IterBytes for binding_mode { +impl to_bytes::IterBytes for binding_mode { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { match *self { bind_by_copy => 0u8.iter_bytes(lsb0, f), @@ -291,7 +291,7 @@ pub enum pat_ { #[deriving_eq] pub enum mutability { m_mutbl, m_imm, m_const, } -pub impl to_bytes::IterBytes for mutability { +impl to_bytes::IterBytes for mutability { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -304,13 +304,13 @@ pub enum Abi { RustAbi } -pub impl to_bytes::IterBytes for Abi { +impl to_bytes::IterBytes for Abi { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f) } } -pub impl ToStr for Abi { +impl ToStr for Abi { pure fn to_str(&self) -> ~str { match *self { RustAbi => ~"\"rust\"" @@ -327,13 +327,13 @@ pub enum Sigil { ManagedSigil } -pub impl to_bytes::IterBytes for Sigil { +impl to_bytes::IterBytes for Sigil { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f) } } -pub impl ToStr for Sigil { +impl ToStr for Sigil { pure fn to_str(&self) -> ~str { match *self { BorrowedSigil => ~"&", @@ -412,7 +412,7 @@ pub enum inferable<T> { infer(node_id) } -pub impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> { +impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { match *self { expl(ref t) => @@ -430,7 +430,7 @@ pub impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> { #[deriving_eq] pub enum rmode { by_ref, by_val, by_copy } -pub impl to_bytes::IterBytes for rmode { +impl to_bytes::IterBytes for rmode { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -771,13 +771,13 @@ pub enum trait_method { #[deriving_eq] pub enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, } -pub impl ToStr for int_ty { +impl ToStr for int_ty { pure fn to_str(&self) -> ~str { ::ast_util::int_ty_to_str(*self) } } -pub impl to_bytes::IterBytes for int_ty { +impl to_bytes::IterBytes for int_ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -788,13 +788,13 @@ pub impl to_bytes::IterBytes for int_ty { #[deriving_eq] pub enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, } -pub impl ToStr for uint_ty { +impl ToStr for uint_ty { pure fn to_str(&self) -> ~str { ::ast_util::uint_ty_to_str(*self) } } -pub impl to_bytes::IterBytes for uint_ty { +impl to_bytes::IterBytes for uint_ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -805,13 +805,13 @@ pub impl to_bytes::IterBytes for uint_ty { #[deriving_eq] pub enum float_ty { ty_f, ty_f32, ty_f64, } -pub impl ToStr for float_ty { +impl ToStr for float_ty { pure fn to_str(&self) -> ~str { ::ast_util::float_ty_to_str(*self) } } -pub impl to_bytes::IterBytes for float_ty { +impl to_bytes::IterBytes for float_ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -865,7 +865,7 @@ pub enum Onceness { Many } -pub impl ToStr for Onceness { +impl ToStr for Onceness { pure fn to_str(&self) -> ~str { match *self { Once => ~"once", @@ -874,7 +874,7 @@ pub impl ToStr for Onceness { } } -pub impl to_bytes::IterBytes for Onceness { +impl to_bytes::IterBytes for Onceness { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f); } @@ -924,7 +924,7 @@ pub enum ty_ { ty_infer, } -pub impl to_bytes::IterBytes for Ty { +impl to_bytes::IterBytes for Ty { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f); } @@ -960,7 +960,7 @@ pub enum purity { extern_fn, // declared with "extern fn" } -pub impl ToStr for purity { +impl ToStr for purity { pure fn to_str(&self) -> ~str { match *self { impure_fn => ~"impure", @@ -971,7 +971,7 @@ pub impl ToStr for purity { } } -pub impl to_bytes::IterBytes for purity { +impl to_bytes::IterBytes for purity { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -986,7 +986,7 @@ pub enum ret_style { return_val, // everything else } -pub impl to_bytes::IterBytes for ret_style { +impl to_bytes::IterBytes for ret_style { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } @@ -1268,7 +1268,7 @@ pub enum item_ { #[deriving_eq] pub enum struct_mutability { struct_mutable, struct_immutable } -pub impl to_bytes::IterBytes for struct_mutability { +impl to_bytes::IterBytes for struct_mutability { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as u8).iter_bytes(lsb0, f) } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 74f67808a5e..959454841a2 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -34,7 +34,7 @@ pub enum path_elt { path_name(ident) } -pub impl cmp::Eq for path_elt { +impl cmp::Eq for path_elt { pure fn eq(&self, other: &path_elt) -> bool { match (*self) { path_mod(e0a) => { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index fec3a961a52..4c5c4da5142 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -198,7 +198,7 @@ pub pure fn is_call_expr(e: @expr) -> bool { } // This makes def_id hashable -pub impl to_bytes::IterBytes for def_id { +impl to_bytes::IterBytes for def_id { #[inline(always)] pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f); @@ -303,7 +303,7 @@ pub trait inlined_item_utils { fn accept<E>(&self, e: E, v: visit::vt<E>); } -pub impl inlined_item_utils for inlined_item { +impl inlined_item_utils for inlined_item { fn ident(&self) -> ident { match *self { ii_item(i) => /* FIXME (#2543) */ copy i.ident, diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 1ab55fe9035..65711d9894a 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -46,71 +46,71 @@ pub enum CharPos = uint; // XXX: Lots of boilerplate in these impls, but so far my attempts to fix // have been unsuccessful -pub impl Pos for BytePos { +impl Pos for BytePos { static pure fn from_uint(n: uint) -> BytePos { BytePos(n) } pure fn to_uint(&self) -> uint { **self } } -pub impl cmp::Eq for BytePos { +impl cmp::Eq for BytePos { pure fn eq(&self, other: &BytePos) -> bool { **self == **other } pure fn ne(&self, other: &BytePos) -> bool { !(*self).eq(other) } } -pub impl cmp::Ord for BytePos { +impl cmp::Ord for BytePos { pure fn lt(&self, other: &BytePos) -> bool { **self < **other } pure fn le(&self, other: &BytePos) -> bool { **self <= **other } pure fn ge(&self, other: &BytePos) -> bool { **self >= **other } pure fn gt(&self, other: &BytePos) -> bool { **self > **other } } -pub impl Add<BytePos, BytePos> for BytePos { +impl Add<BytePos, BytePos> for BytePos { pure fn add(&self, rhs: &BytePos) -> BytePos { BytePos(**self + **rhs) } } -pub impl Sub<BytePos, BytePos> for BytePos { +impl Sub<BytePos, BytePos> for BytePos { pure fn sub(&self, rhs: &BytePos) -> BytePos { BytePos(**self - **rhs) } } -pub impl to_bytes::IterBytes for BytePos { +impl to_bytes::IterBytes for BytePos { pure fn iter_bytes(&self, +lsb0: bool, &&f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } -pub impl Pos for CharPos { +impl Pos for CharPos { static pure fn from_uint(n: uint) -> CharPos { CharPos(n) } pure fn to_uint(&self) -> uint { **self } } -pub impl cmp::Eq for CharPos { +impl cmp::Eq for CharPos { pure fn eq(&self, other: &CharPos) -> bool { **self == **other } pure fn ne(&self, other: &CharPos) -> bool { !(*self).eq(other) } } -pub impl cmp::Ord for CharPos { +impl cmp::Ord for CharPos { pure fn lt(&self, other: &CharPos) -> bool { **self < **other } pure fn le(&self, other: &CharPos) -> bool { **self <= **other } pure fn ge(&self, other: &CharPos) -> bool { **self >= **other } pure fn gt(&self, other: &CharPos) -> bool { **self > **other } } -pub impl to_bytes::IterBytes for CharPos { +impl to_bytes::IterBytes for CharPos { pure fn iter_bytes(&self, +lsb0: bool, &&f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } -pub impl Add<CharPos,CharPos> for CharPos { +impl Add<CharPos,CharPos> for CharPos { pure fn add(&self, rhs: &CharPos) -> CharPos { CharPos(**self + **rhs) } } -pub impl Sub<CharPos,CharPos> for CharPos { +impl Sub<CharPos,CharPos> for CharPos { pure fn sub(&self, rhs: &CharPos) -> CharPos { CharPos(**self - **rhs) } @@ -133,19 +133,19 @@ pub struct span { #[deriving_eq] pub struct spanned<T> { node: T, span: span } -pub impl cmp::Eq for span { +impl cmp::Eq for span { pure fn eq(&self, other: &span) -> bool { return (*self).lo == (*other).lo && (*self).hi == (*other).hi; } pure fn ne(&self, other: &span) -> bool { !(*self).eq(other) } } -pub impl<S:Encoder> Encodable<S> for span { +impl<S:Encoder> Encodable<S> for span { /* Note #1972 -- spans are encoded but not decoded */ fn encode(&self, _s: &S) { } } -pub impl<D:Decoder> Decodable<D> for span { +impl<D:Decoder> Decodable<D> for span { static fn decode(_d: &D) -> span { dummy_sp() } diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 0019acc1291..9e60e215174 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -1192,7 +1192,7 @@ mod test { } } - pub impl Encoder for TestEncoder { + impl Encoder for TestEncoder { fn emit_nil(&self) { self.add_to_log(CallToEmitNil) } fn emit_uint(&self, +v: uint) {self.add_to_log(CallToEmitUint(v)); } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 49f7fe5853e..6adea6395a3 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -54,7 +54,7 @@ pub trait append_types { fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path; } -pub impl append_types for @ast::path { +impl append_types for @ast::path { fn add_ty(ty: @ast::Ty) -> @ast::path { @ast::path { types: vec::append_one(self.types, ty), .. *self} @@ -119,7 +119,7 @@ pub trait ext_ctxt_ast_builder { fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param]; } -pub impl ext_ctxt_ast_builder for ext_ctxt { +impl ext_ctxt_ast_builder for ext_ctxt { fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty { self.ty_path_ast_builder(path_global(~[ self.ident_of(~"core"), diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index cc42a0992cb..f456f7b81ae 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -37,7 +37,7 @@ use ext::base::ext_ctxt; use ext::pipes::proto::{state, protocol, next_state}; use ext::pipes::proto; -pub impl proto::visitor<(), (), ()> for ext_ctxt { +impl proto::visitor<(), (), ()> for ext_ctxt { fn visit_proto(&self, _proto: protocol, _states: &[()]) { } diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index 66feb7cc753..9a330db9f18 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -23,7 +23,7 @@ pub trait proto_parser { fn parse_message(&self, state: state); } -pub impl proto_parser for parser::Parser { +impl proto_parser for parser::Parser { fn parse_proto(&self, id: ~str) -> protocol { let proto = protocol(id, *self.span); diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 444b09d9ae4..84d46e318b1 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -46,7 +46,7 @@ pub trait gen_init { fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr; } -pub impl gen_send for message { +impl gen_send for message { fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item { debug!("pipec: gen_send"); let name = self.name(); @@ -196,7 +196,7 @@ pub impl gen_send for message { } } -pub impl to_type_decls for state { +impl to_type_decls for state { fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item] { debug!("pipec: to_type_decls"); // This compiles into two different type declarations. Say the @@ -307,7 +307,7 @@ pub impl to_type_decls for state { } } -pub impl gen_init for protocol { +impl gen_init for protocol { fn gen_init(&self, cx: ext_ctxt) -> @ast::item { let ext_cx = cx; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 7c6dc1f937d..d22feff9470 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -21,7 +21,7 @@ use core::to_str::ToStr; #[deriving_eq] pub enum direction { send, recv } -pub impl ToStr for direction { +impl ToStr for direction { pure fn to_str(&self) -> ~str { match *self { send => ~"Send", diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index dacb6f60e37..2d8b62629ee 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -694,7 +694,7 @@ pub fn default_ast_fold() -> ast_fold_fns { new_span: noop_span}; } -pub impl ast_fold for ast_fold_fns { +impl ast_fold for ast_fold_fns { /* naturally, a macro to write these would be nice */ fn fold_crate(c: crate) -> crate { let (n, s) = (self.fold_crate)(c.node, c.span, self as ast_fold); diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 51cc25e84a3..dc5bdeba92a 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -127,7 +127,7 @@ impl reader for StringReader { fn dup(@mut self) -> reader { dup_string_reader(self) as reader } } -pub impl reader for TtReader { +impl reader for TtReader { fn is_eof(@mut self) -> bool { self.cur_tok == token::EOF } fn next_token(@mut self) -> TokenAndSpan { tt_next_token(self) } fn fatal(@mut self, m: ~str) -> ! { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 33d959a7753..b384e7ebdd0 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -50,9 +50,10 @@ pub enum ObsoleteSyntax { ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer, ObsoleteMutVector, + ObsoleteTraitImplVisibility, } -pub impl to_bytes::IterBytes for ObsoleteSyntax { +impl to_bytes::IterBytes for ObsoleteSyntax { #[inline(always)] pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (*self as uint).iter_bytes(lsb0, f); @@ -140,6 +141,12 @@ pub impl Parser { in a mutable location, like a mutable local variable or an \ `@mut` box" ), + ObsoleteTraitImplVisibility => ( + "visibility-qualified trait implementation", + "`pub` or `priv` is meaningless for trait implementations, \ + because the `impl...for...` form defines overloads for \ + methods that already exist; remove the `pub` or `priv`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b4bd28cbfe2..59ad35b38e4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -76,7 +76,7 @@ use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith}; use parse::obsolete::{ObsoleteSyntax, ObsoleteLowerCaseKindBounds}; use parse::obsolete::{ObsoleteUnsafeBlock, ObsoleteImplSyntax}; use parse::obsolete::{ObsoleteTraitBoundSeparator, ObsoleteMutOwnedPointer}; -use parse::obsolete::{ObsoleteMutVector}; +use parse::obsolete::{ObsoleteMutVector, ObsoleteTraitImplVisibility}; use parse::prec::{as_prec, token_to_binop}; use parse::token::{can_begin_expr, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, special_idents}; @@ -2942,9 +2942,9 @@ pub impl Parser { } // Parses two variants (with the region/type params always optional): - // impl<T> ~[T] : to_str { ... } - // impl<T> to_str for ~[T] { ... } - fn parse_item_impl() -> item_info { + // impl<T> Foo { ... } + // impl<T> ToStr for ~[T] { ... } + fn parse_item_impl(visibility: ast::visibility) -> item_info { fn wrap_path(p: Parser, pt: @path) -> @Ty { @Ty { id: p.get_id(), @@ -2993,6 +2993,12 @@ pub impl Parser { None }; + // Do not allow visibility to be specified in `impl...for...`. It is + // meaningless. + if opt_trait.is_some() && visibility != ast::inherited { + self.obsolete(*self.span, ObsoleteTraitImplVisibility); + } + let mut meths = ~[]; if !self.eat(token::SEMI) { self.expect(token::LBRACE); @@ -3860,7 +3866,8 @@ pub impl Parser { maybe_append(attrs, extra_attrs))); } else if items_allowed && self.eat_keyword(~"impl") { // IMPL ITEM - let (ident, item_, extra_attrs) = self.parse_item_impl(); + let (ident, item_, extra_attrs) = + self.parse_item_impl(visibility); return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_, visibility, maybe_append(attrs, extra_attrs))); |
