mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
impls of traits cannot define methods on the anonymous trait
This commit is contained in:
parent
78ee821154
commit
3ed9fbd63c
@ -37,6 +37,7 @@ pub trait Times {
|
||||
pub trait CopyableIter<A:Copy> {
|
||||
pure fn filter_to_vec(pred: fn(a: A) -> bool) -> ~[A];
|
||||
pure fn map_to_vec<B>(op: fn(v: A) -> B) -> ~[B];
|
||||
pure fn flat_map_to_vec<B:Copy,IB: BaseIter<B>>(op: fn(A) -> IB) -> ~[B];
|
||||
pure fn to_vec() -> ~[A];
|
||||
pure fn find(p: fn(a: A) -> bool) -> Option<A>;
|
||||
}
|
||||
|
@ -44,6 +44,9 @@ pub trait GenericPath {
|
||||
pure fn with_filestem((&str)) -> self;
|
||||
pure fn with_filetype((&str)) -> self;
|
||||
|
||||
pure fn dir_path() -> self;
|
||||
pure fn file_path() -> self;
|
||||
|
||||
pure fn push((&str)) -> self;
|
||||
pure fn push_rel((&self)) -> self;
|
||||
pure fn push_many((&[~str])) -> self;
|
||||
|
@ -811,13 +811,22 @@ pub struct RecvPacketBuffered<T: Send, Tbuffer: Send> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
|
||||
impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> {
|
||||
fn unwrap() -> *Packet<T> {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
option::unwrap(move p)
|
||||
}
|
||||
|
||||
fn reuse_buffer() -> BufferResource<Tbuffer> {
|
||||
//error!("recv reuse_buffer");
|
||||
let mut tmp = None;
|
||||
tmp <-> self.buffer;
|
||||
option::unwrap(move tmp)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
|
||||
pure fn header() -> *PacketHeader {
|
||||
match self.p {
|
||||
Some(packet) => unsafe {
|
||||
@ -829,13 +838,6 @@ impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
|
||||
None => fail ~"packet already consumed"
|
||||
}
|
||||
}
|
||||
|
||||
fn reuse_buffer() -> BufferResource<Tbuffer> {
|
||||
//error!("recv reuse_buffer");
|
||||
let mut tmp = None;
|
||||
tmp <-> self.buffer;
|
||||
option::unwrap(move tmp)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
||||
@ -1046,7 +1048,7 @@ pub fn PortSet<T: Send>() -> PortSet<T>{
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Send> PortSet<T> : Recv<T> {
|
||||
impl<T: Send> PortSet<T> {
|
||||
|
||||
fn add(port: pipes::Port<T>) {
|
||||
self.ports.push(move port)
|
||||
@ -1057,6 +1059,9 @@ impl<T: Send> PortSet<T> : Recv<T> {
|
||||
self.add(move po);
|
||||
move ch
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Send> PortSet<T> : Recv<T> {
|
||||
|
||||
fn try_recv() -> Option<T> {
|
||||
let mut result = None;
|
||||
|
@ -34,9 +34,7 @@ pub fn MovePtrAdaptor<V: TyVisitor MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
||||
MovePtrAdaptor { inner: move v }
|
||||
}
|
||||
|
||||
/// Abstract type-directed pointer-movement using the MovePtr trait
|
||||
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V>: TyVisitor {
|
||||
|
||||
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V> {
|
||||
#[inline(always)]
|
||||
fn bump(sz: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
@ -60,7 +58,10 @@ impl<V: TyVisitor MovePtr> MovePtrAdaptor<V>: TyVisitor {
|
||||
fn bump_past<T>() {
|
||||
self.bump(sys::size_of::<T>());
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstract type-directed pointer-movement using the MovePtr trait
|
||||
impl<V: TyVisitor MovePtr> MovePtrAdaptor<V>: TyVisitor {
|
||||
fn visit_bot() -> bool {
|
||||
self.align_to::<()>();
|
||||
if ! self.inner.visit_bot() { return false; }
|
||||
|
@ -72,6 +72,10 @@ trait tr {
|
||||
fn tr(xcx: extended_decode_ctxt) -> self;
|
||||
}
|
||||
|
||||
trait tr_intern {
|
||||
fn tr_intern(xcx: extended_decode_ctxt) -> ast::def_id;
|
||||
}
|
||||
|
||||
// ______________________________________________________________________
|
||||
// Top-level methods.
|
||||
|
||||
@ -168,13 +172,16 @@ impl extended_decode_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::def_id: tr_intern {
|
||||
fn tr_intern(xcx: extended_decode_ctxt) -> ast::def_id {
|
||||
xcx.tr_intern_def_id(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::def_id: tr {
|
||||
fn tr(xcx: extended_decode_ctxt) -> ast::def_id {
|
||||
xcx.tr_def_id(self)
|
||||
}
|
||||
fn tr_intern(xcx: extended_decode_ctxt) -> ast::def_id {
|
||||
xcx.tr_intern_def_id(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl span: tr {
|
||||
|
@ -549,7 +549,6 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
||||
}
|
||||
|
||||
impl @fn_ctxt: ast_conv {
|
||||
fn infcx() -> infer::infer_ctxt { self.inh.infcx }
|
||||
fn tcx() -> ty::ctxt { self.ccx.tcx }
|
||||
fn ccx() -> @crate_ctxt { self.ccx }
|
||||
|
||||
@ -563,6 +562,7 @@ impl @fn_ctxt: ast_conv {
|
||||
}
|
||||
|
||||
impl @fn_ctxt {
|
||||
fn infcx() -> infer::infer_ctxt { self.inh.infcx }
|
||||
fn search_in_scope_regions(br: ty::bound_region)
|
||||
-> Result<ty::Region, ~str>
|
||||
{
|
||||
|
@ -465,22 +465,27 @@ fn check_methods_against_trait(ccx: @crate_ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
for vec::each(*ty::trait_methods(tcx, did)) |trait_m| {
|
||||
match vec::find(impl_ms, |impl_m| trait_m.ident == impl_m.mty.ident) {
|
||||
Some(ref cm) => {
|
||||
// Check that each method we impl is a method on the trait
|
||||
// Trait methods we don't implement must be default methods, but if not
|
||||
// we'll catch it in coherence
|
||||
let trait_ms = ty::trait_methods(tcx, did);
|
||||
for impl_ms.each |impl_m| {
|
||||
match trait_ms.find(|trait_m| trait_m.ident == impl_m.mty.ident) {
|
||||
Some(ref trait_m) => {
|
||||
compare_impl_method(
|
||||
ccx.tcx, vec::len(tps), cm, trait_m,
|
||||
ccx.tcx, tps.len(), impl_m, trait_m,
|
||||
&tpt.substs, selfty);
|
||||
}
|
||||
None => {
|
||||
// If we couldn't find an implementation for trait_m in
|
||||
// the impl, then either this method has a default
|
||||
// implementation or we're using the trait-provided
|
||||
// version. Either way, we handle this later, during the
|
||||
// coherence phase.
|
||||
// This method is not part of the trait
|
||||
tcx.sess.span_err(
|
||||
impl_m.span,
|
||||
fmt!("method `%s` is not a member of trait `%s`",
|
||||
tcx.sess.str_of(impl_m.mty.ident),
|
||||
path_to_str(a_trait_ty.path, tcx.sess.intr())));
|
||||
}
|
||||
} // match
|
||||
} // |trait_m|
|
||||
}
|
||||
}
|
||||
} // fn
|
||||
|
||||
fn convert_field(ccx: @crate_ctxt,
|
||||
|
@ -7,6 +7,11 @@ fn macros() { include!("macros.rs"); } // FIXME(#3114): Macro import/export.
|
||||
|
||||
enum Lub = combine_fields; // "subtype", "subregion" etc
|
||||
|
||||
impl Lub {
|
||||
fn bot_ty(b: ty::t) -> cres<ty::t> { Ok(b) }
|
||||
fn ty_bot(b: ty::t) -> cres<ty::t> { self.bot_ty(b) } // commutative
|
||||
}
|
||||
|
||||
impl Lub: combine {
|
||||
fn infcx() -> infer_ctxt { self.infcx }
|
||||
fn tag() -> ~str { ~"lub" }
|
||||
@ -16,9 +21,6 @@ impl Lub: combine {
|
||||
fn lub() -> Lub { Lub(*self) }
|
||||
fn glb() -> Glb { Glb(*self) }
|
||||
|
||||
fn bot_ty(b: ty::t) -> cres<ty::t> { Ok(b) }
|
||||
fn ty_bot(b: ty::t) -> cres<ty::t> { self.bot_ty(b) } // commutative
|
||||
|
||||
fn mts(a: ty::mt, b: ty::mt) -> cres<ty::mt> {
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
|
@ -390,7 +390,7 @@ pub mod chained {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> T<K, V>: ToStr {
|
||||
impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> T<K, V> {
|
||||
fn to_writer(wr: io::Writer) {
|
||||
if self.count == 0u {
|
||||
wr.write_str(~"{}");
|
||||
@ -410,7 +410,9 @@ pub mod chained {
|
||||
};
|
||||
wr.write_str(~" }");
|
||||
}
|
||||
}
|
||||
|
||||
impl<K:Eq IterBytes Hash Copy ToStr, V: ToStr Copy> T<K, V>: ToStr {
|
||||
pure fn to_str() -> ~str unsafe {
|
||||
// Meh -- this should be safe
|
||||
do io::with_str_writer |wr| { self.to_writer(wr) }
|
||||
|
@ -824,9 +824,6 @@ impl TcpSocketBuf: io::Reader {
|
||||
bytes[0] as int
|
||||
}
|
||||
}
|
||||
fn unread_byte(amt: int) {
|
||||
self.data.buf.unshift(amt as u8);
|
||||
}
|
||||
fn eof() -> bool {
|
||||
self.end_of_stream
|
||||
}
|
||||
|
@ -101,7 +101,6 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> {
|
||||
}
|
||||
pure fn get(key: uint) -> V { get(self, key) }
|
||||
pure fn find(key: uint) -> Option<V> { find(self, key) }
|
||||
fn rehash() { fail }
|
||||
|
||||
fn update_with_key(key: uint, val: V, ff: fn(uint, V, V) -> V) -> bool {
|
||||
match self.find(key) {
|
||||
|
@ -79,7 +79,10 @@ trait ext_ctxt_ast_builder {
|
||||
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
|
||||
fn stmt_expr(e: @ast::expr) -> @ast::stmt;
|
||||
fn block_expr(b: ast::blk) -> @ast::expr;
|
||||
fn move_expr(e: @ast::expr) -> @ast::expr;
|
||||
fn ty_option(ty: @ast::Ty) -> @ast::Ty;
|
||||
fn ty_infer() -> @ast::Ty;
|
||||
fn ty_nil_ast_builder() -> @ast::Ty;
|
||||
}
|
||||
|
||||
impl ext_ctxt: ext_ctxt_ast_builder {
|
||||
|
@ -38,7 +38,6 @@ use ext::base::ext_ctxt;
|
||||
use ast::tt_delim;
|
||||
use parse::lexer::{new_tt_reader, reader};
|
||||
use parse::parser::Parser;
|
||||
use parse::common::parser_common;
|
||||
|
||||
use pipes::parse_proto::proto_parser;
|
||||
|
||||
|
@ -8,6 +8,7 @@ use pipec::*;
|
||||
trait proto_parser {
|
||||
fn parse_proto(id: ~str) -> protocol;
|
||||
fn parse_state(proto: protocol);
|
||||
fn parse_message(state: state);
|
||||
}
|
||||
|
||||
impl parser::Parser: proto_parser {
|
||||
|
@ -24,6 +24,7 @@ mod syntax {
|
||||
|
||||
trait gen_send {
|
||||
fn gen_send(cx: ext_ctxt, try: bool) -> @ast::item;
|
||||
fn to_ty(cx: ext_ctxt) -> @ast::Ty;
|
||||
}
|
||||
|
||||
trait to_type_decls {
|
||||
@ -34,6 +35,10 @@ trait to_type_decls {
|
||||
trait gen_init {
|
||||
fn gen_init(cx: ext_ctxt) -> @ast::item;
|
||||
fn compile(cx: ext_ctxt) -> @ast::item;
|
||||
fn buffer_ty_path(cx: ext_ctxt) -> @ast::Ty;
|
||||
fn gen_buffer_type(cx: ext_ctxt) -> @ast::item;
|
||||
fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr;
|
||||
fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr;
|
||||
}
|
||||
|
||||
impl message: gen_send {
|
||||
|
@ -3,7 +3,6 @@ use ext::base::ext_ctxt;
|
||||
use ast::tt_delim;
|
||||
use parse::lexer::{new_tt_reader, reader};
|
||||
use parse::parser::Parser;
|
||||
use parse::common::parser_common;
|
||||
|
||||
fn expand_trace_macros(cx: ext_ctxt, sp: span,
|
||||
tt: ~[ast::token_tree]) -> base::mac_result
|
||||
|
@ -22,41 +22,7 @@ fn token_to_str(reader: reader, ++token: token::Token) -> ~str {
|
||||
token::to_str(reader.interner(), token)
|
||||
}
|
||||
|
||||
trait parser_common {
|
||||
fn unexpected_last(t: token::Token) -> !;
|
||||
fn unexpected() -> !;
|
||||
fn expect(t: token::Token);
|
||||
fn parse_ident() -> ast::ident;
|
||||
fn parse_path_list_ident() -> ast::path_list_ident;
|
||||
fn parse_value_ident() -> ast::ident;
|
||||
fn eat(tok: token::Token) -> bool;
|
||||
// A sanity check that the word we are asking for is a known keyword
|
||||
fn require_keyword(word: ~str);
|
||||
fn token_is_keyword(word: ~str, ++tok: token::Token) -> bool;
|
||||
fn is_keyword(word: ~str) -> bool;
|
||||
fn is_any_keyword(tok: token::Token) -> bool;
|
||||
fn eat_keyword(word: ~str) -> bool;
|
||||
fn expect_keyword(word: ~str);
|
||||
fn expect_gt();
|
||||
fn parse_seq_to_before_gt<T: Copy>(sep: Option<token::Token>,
|
||||
f: fn(Parser) -> T) -> ~[T];
|
||||
fn parse_seq_to_gt<T: Copy>(sep: Option<token::Token>,
|
||||
f: fn(Parser) -> T) -> ~[T];
|
||||
fn parse_seq_lt_gt<T: Copy>(sep: Option<token::Token>,
|
||||
f: fn(Parser) -> T) -> spanned<~[T]>;
|
||||
fn parse_seq_to_end<T: Copy>(ket: token::Token, sep: seq_sep,
|
||||
f: fn(Parser) -> T) -> ~[T];
|
||||
fn parse_seq_to_before_end<T: Copy>(ket: token::Token, sep: seq_sep,
|
||||
f: fn(Parser) -> T) -> ~[T];
|
||||
fn parse_unspanned_seq<T: Copy>(bra: token::Token,
|
||||
ket: token::Token,
|
||||
sep: seq_sep,
|
||||
f: fn(Parser) -> T) -> ~[T];
|
||||
fn parse_seq<T: Copy>(bra: token::Token, ket: token::Token, sep: seq_sep,
|
||||
f: fn(Parser) -> T) -> spanned<~[T]>;
|
||||
}
|
||||
|
||||
impl Parser: parser_common {
|
||||
impl Parser {
|
||||
fn unexpected_last(t: token::Token) -> ! {
|
||||
self.span_fatal(
|
||||
copy self.last_span,
|
||||
|
@ -27,7 +27,6 @@ export parse_from_source_str;
|
||||
|
||||
use parser::Parser;
|
||||
use attr::parser_attr;
|
||||
use common::parser_common;
|
||||
use ast::node_id;
|
||||
use util::interner;
|
||||
use diagnostic::{span_handler, mk_span_handler, mk_handler, emitter};
|
||||
|
@ -52,12 +52,7 @@ impl ObsoleteSyntax: to_bytes::IterBytes {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ObsoleteReporter {
|
||||
fn obsolete(sp: span, kind: ObsoleteSyntax);
|
||||
fn obsolete_expr(sp: span, kind: ObsoleteSyntax) -> @expr;
|
||||
}
|
||||
|
||||
impl Parser : ObsoleteReporter {
|
||||
impl Parser {
|
||||
/// Reports an obsolete syntax non-fatal error.
|
||||
fn obsolete(sp: span, kind: ObsoleteSyntax) {
|
||||
let (kind_str, desc) = match kind {
|
||||
|
@ -16,7 +16,7 @@ use common::{seq_sep_trailing_disallowed, seq_sep_trailing_allowed,
|
||||
use dvec::DVec;
|
||||
use vec::{push};
|
||||
use obsolete::{
|
||||
ObsoleteReporter, ObsoleteSyntax,
|
||||
ObsoleteSyntax,
|
||||
ObsoleteLowerCaseKindBounds, ObsoleteLet,
|
||||
ObsoleteFieldTerminator, ObsoleteStructCtor,
|
||||
ObsoleteWith, ObsoleteClassMethod, ObsoleteClassTraits,
|
||||
|
@ -9,9 +9,11 @@ trait Hahaha: Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, Eq, //
|
||||
|
||||
enum Lol = int;
|
||||
|
||||
pub impl Lol: Hahaha {
|
||||
pure fn eq(other: &Lol) -> bool { *self != **other }
|
||||
pure fn ne(other: &Lol) -> bool { *self == **other }
|
||||
pub impl Lol: Hahaha { }
|
||||
|
||||
impl Lol: Eq {
|
||||
pure fn eq(&self, other: &Lol) -> bool { **self != **other }
|
||||
pure fn ne(&self, other: &Lol) -> bool { **self == **other }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -0,0 +1,7 @@
|
||||
trait A { }
|
||||
|
||||
impl int: A {
|
||||
fn foo() { } //~ ERROR method `foo` is not a member of trait `A`
|
||||
}
|
||||
|
||||
fn main() { }
|
@ -21,7 +21,8 @@ fn align(size: uint, align: uint) -> uint {
|
||||
enum ptr_visit_adaptor<V: TyVisitor movable_ptr> = {
|
||||
inner: V
|
||||
};
|
||||
impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V>: TyVisitor {
|
||||
|
||||
impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V> {
|
||||
|
||||
#[inline(always)]
|
||||
fn bump(sz: uint) {
|
||||
@ -47,6 +48,10 @@ impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V>: TyVisitor {
|
||||
self.bump(sys::size_of::<T>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<V: TyVisitor movable_ptr> ptr_visit_adaptor<V>: TyVisitor {
|
||||
|
||||
fn visit_bot() -> bool {
|
||||
self.align_to::<()>();
|
||||
if ! self.inner.visit_bot() { return false; }
|
||||
|
Loading…
Reference in New Issue
Block a user