]> git.lizzy.rs Git - rust.git/commitdiff
Convert class methods to impl methods. Stop parsing class methods
authorBrian Anderson <banderson@mozilla.com>
Sat, 8 Sep 2012 02:04:40 +0000 (19:04 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 10 Sep 2012 23:13:08 +0000 (16:13 -0700)
52 files changed:
src/compiletest/procsrv.rs
src/libcore/pipes.rs
src/libstd/comm.rs
src/libsyntax/ext/pipes/proto.rs
src/libsyntax/parse/parser.rs
src/rustc/middle/lang_items.rs
src/rustc/middle/resolve.rs
src/rustc/middle/typeck/check/method.rs
src/rustc/middle/typeck/coherence.rs
src/test/auxiliary/cci_class_2.rs
src/test/auxiliary/cci_class_3.rs
src/test/auxiliary/cci_class_4.rs
src/test/auxiliary/cci_class_5.rs
src/test/auxiliary/cci_class_6.rs
src/test/auxiliary/cci_class_cast.rs
src/test/bench/task-perf-word-count-generic.rs
src/test/compile-fail/assign-to-method.rs
src/test/compile-fail/class-cast-to-trait.rs
src/test/compile-fail/class-missing-self.rs
src/test/compile-fail/issue-2356.rs
src/test/compile-fail/issue-2487-b.rs
src/test/compile-fail/issue-3021-b.rs
src/test/compile-fail/mutable-class-fields-2.rs
src/test/compile-fail/private-method-cross-crate.rs
src/test/compile-fail/private-method.rs
src/test/compile-fail/regions-addr-of-self.rs
src/test/compile-fail/regions-addr-of-upvar-self.rs
src/test/run-pass/class-cast-to-trait-multiple-types.rs
src/test/run-pass/class-cast-to-trait.rs
src/test/run-pass/class-exports.rs
src/test/run-pass/class-impl-very-parameterized-trait.rs
src/test/run-pass/class-implement-trait-cross-crate.rs
src/test/run-pass/class-implement-traits.rs
src/test/run-pass/class-methods.rs
src/test/run-pass/class-poly-methods.rs
src/test/run-pass/class-separate-impl.rs
src/test/run-pass/class-typarams.rs
src/test/run-pass/classes-simple-method.rs
src/test/run-pass/classes.rs
src/test/run-pass/issue-2288.rs
src/test/run-pass/issue-2311-2.rs
src/test/run-pass/issue-2445-b.rs
src/test/run-pass/issue-2445.rs
src/test/run-pass/issue-2487-a.rs
src/test/run-pass/issue-2502.rs
src/test/run-pass/issue-2718.rs
src/test/run-pass/issue-2936.rs
src/test/run-pass/nested-class.rs
src/test/run-pass/private-class-field.rs
src/test/run-pass/private-method.rs
src/test/run-pass/resource-destruct.rs
src/test/run-pass/task-comm-6.rs

index f2e9e03d7dbae546174ceb6acfa9ce37e3a97bf3..1ab3bc55d9f048363fcc6efac5b62d367ccc5502 100644 (file)
@@ -1,7 +1,6 @@
 import run::spawn_process;
 import io::{ReaderUtil, WriterUtil};
 import libc::{c_int, pid_t};
-import pipes::chan;
 
 export run;
 
index 75716e642df4b779bc4177ecbd761141b53e682f..0ed0904b1b92511d7d2ce8f06c068da33e181709 100644 (file)
@@ -164,7 +164,17 @@ struct PacketHeader {
     // This is a reinterpret_cast of a ~buffer, that can also be cast
     // to a buffer_header if need be.
     mut buffer: *libc::c_void,
+}
+
+fn PacketHeader() -> PacketHeader {
+    PacketHeader {
+        state: Empty,
+        blocked_task: ptr::null(),
+        buffer: ptr::null()
+    }
+}
 
+impl PacketHeader {
     // Returns the old state.
     unsafe fn mark_blocked(this: *rust_task) -> State {
         rustrt::rust_task_ref(this);
@@ -196,14 +206,6 @@ fn set_buffer<T: Send>(b: ~Buffer<T>) unsafe {
     }
 }
 
-fn PacketHeader() -> PacketHeader {
-    PacketHeader {
-        state: Empty,
-        blocked_task: ptr::null(),
-        buffer: ptr::null()
-    }
-}
-
 #[doc(hidden)]
 type Packet<T: Send> = {
     header: PacketHeader,
@@ -794,6 +796,21 @@ struct SendPacketBuffered<T: Send, Tbuffer: Send> {
         //                    "none"
         //                } else { "some" }); }
     }
+}
+
+fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
+    -> SendPacketBuffered<T, Tbuffer> {
+        //debug!("take send %?", p);
+    SendPacketBuffered {
+        p: Some(p),
+        buffer: unsafe {
+            Some(BufferResource(
+                get_buffer(ptr::addr_of((*p).header))))
+        }
+    }
+}
+
+impl<T: Send, Tbuffer: Send> SendPacketBuffered<T, Tbuffer> {
     fn unwrap() -> *Packet<T> {
         let mut p = None;
         p <-> self.p;
@@ -820,18 +837,6 @@ fn reuse_buffer() -> BufferResource<Tbuffer> {
     }
 }
 
-fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
-    -> SendPacketBuffered<T, Tbuffer> {
-        //debug!("take send %?", p);
-    SendPacketBuffered {
-        p: Some(p),
-        buffer: unsafe {
-            Some(BufferResource(
-                get_buffer(ptr::addr_of((*p).header))))
-        }
-    }
-}
-
 // XXX remove me
 #[cfg(stage0)]
 #[allow(non_camel_case_types)]
@@ -858,7 +863,7 @@ fn recv_packet<T: Send>(p: *packet<T>) -> RecvPacket<T> {
     RecvPacket(p)
 }
 
-struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
+struct RecvPacketBuffered<T: Send, Tbuffer: Send> {
     mut p: Option<*Packet<T>>,
     mut buffer: Option<BufferResource<Tbuffer>>,
     drop {
@@ -875,6 +880,9 @@ struct RecvPacketBuffered<T: Send, Tbuffer: Send> : Selectable {
         //                    "none"
         //                } else { "some" }); }
     }
+}
+
+impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
     fn unwrap() -> *Packet<T> {
         let mut p = None;
         p <-> self.p;
@@ -1095,9 +1103,27 @@ fn try_recv() -> Option<T> {
     }
 }
 
+impl<T: Send> Port<T>: Selectable {
+    pure fn header() -> *PacketHeader unchecked {
+        match self.endp {
+          Some(endp) => endp.header(),
+          None => fail ~"peeking empty stream"
+        }
+    }
+}
+
 /// Treat many ports as one.
-struct PortSet<T: Send> : Recv<T> {
+struct PortSet<T: Send> {
     mut ports: ~[pipes::Port<T>],
+}
+
+fn PortSet<T: Send>() -> PortSet<T>{
+    PortSet {
+        ports: ~[]
+    }
+}
+
+impl<T: Send> PortSet<T> : Recv<T> {
 
     fn add(+port: pipes::Port<T>) {
         vec::push(self.ports, move port)
@@ -1145,21 +1171,6 @@ fn recv() -> T {
     }
 }
 
-fn PortSet<T: Send>() -> PortSet<T>{
-    PortSet {
-        ports: ~[]
-    }
-}
-
-impl<T: Send> Port<T>: Selectable {
-    pure fn header() -> *PacketHeader unchecked {
-        match self.endp {
-          Some(endp) => endp.header(),
-          None => fail ~"peeking empty stream"
-        }
-    }
-}
-
 /// A channel that can be shared between many senders.
 type SharedChan<T: Send> = unsafe::Exclusive<Chan<T>>;
 
index d78e11452bcb861559fae3327a84d35051226554..3302b4955bbd230cc0faa8d3e0185d2aa5ca3cb4 100644 (file)
 export DuplexStream;
 
 /// An extension of `pipes::stream` that allows both sending and receiving.
-struct DuplexStream<T: Send, U: Send> : Channel<T>, Recv<U>, Selectable {
+struct DuplexStream<T: Send, U: Send> {
     priv chan: Chan<T>,
     priv port: Port <U>,
+}
 
+impl<T: Send, U: Send> DuplexStream<T, U> : Channel<T> {
     fn send(+x: T) {
         self.chan.send(x)
     }
@@ -24,7 +26,9 @@ fn send(+x: T) {
     fn try_send(+x: T) -> bool {
         self.chan.try_send(x)
     }
+}
 
+impl<T: Send, U: Send> DuplexStream<T, U> : Recv<U> {
     fn recv() -> U {
         self.port.recv()
     }
@@ -36,7 +40,9 @@ fn try_recv() -> Option<U> {
     pure fn peek() -> bool {
         self.port.peek()
     }
+}
 
+impl<T: Send, U: Send> DuplexStream<T, U> : Selectable {
     pure fn header() -> *pipes::PacketHeader {
         self.port.header()
     }
index cb470aee7f36ec914fd4e45789283bbb4051402a..1f674bb5395305e2c19e811773921a188aa97912 100644 (file)
@@ -134,6 +134,9 @@ struct protocol_ {
     states: DVec<state>,
 
     mut bounded: Option<bool>,
+}
+
+impl protocol_ {
 
     /// Get a state.
     fn get_state(name: ~str) -> state {
index 138b83f69f07b7778ea410a4ba9da49854e7fc62..512a5e6459e0962016e8a62272ae44d3d4e27421 100644 (file)
@@ -242,7 +242,9 @@ struct parser {
     obsolete_set: hashmap<ObsoleteSyntax, ()>,
 
     drop {} /* do not copy the parser; its state is tied to outside state */
+}
 
+impl parser {
     fn bump() {
         self.last_span = self.span;
         let next = if self.buffer_start == self.buffer_end {
@@ -2776,32 +2778,25 @@ fn parse_single_class_item(vis: visibility) -> @class_member {
         let obsolete_let = self.eat_obsolete_ident("let");
         if obsolete_let { self.obsolete(copy self.last_span, ObsoleteLet) }
 
-        if (obsolete_let || self.token_is_keyword(~"mut", copy self.token) ||
-            !self.is_any_keyword(copy self.token)) &&
-            !self.token_is_pound_or_doc_comment(self.token) {
-            let a_var = self.parse_instance_var(vis);
-            match self.token {
-                token::SEMI => {
-                    self.obsolete(copy self.span, ObsoleteFieldTerminator);
-                    self.bump();
-                }
-                token::COMMA => {
-                    self.bump();
-                }
-                token::RBRACE => {}
-                _ => {
-                    self.span_fatal(copy self.span,
-                                    fmt!("expected `;`, `,`, or '}' but \
-                                          found `%s`",
-                                         token_to_str(self.reader,
-                                                      self.token)));
-                }
-            }
-            return a_var;
-        } else {
-            let m = self.parse_method(vis);
-            return @method_member(m);
+        let a_var = self.parse_instance_var(vis);
+        match self.token {
+          token::SEMI => {
+            self.obsolete(copy self.span, ObsoleteFieldTerminator);
+            self.bump();
+          }
+          token::COMMA => {
+            self.bump();
+          }
+          token::RBRACE => {}
+          _ => {
+            self.span_fatal(copy self.span,
+                            fmt!("expected `;`, `,`, or '}' but \
+                                  found `%s`",
+                                 token_to_str(self.reader,
+                                              self.token)));
+          }
         }
+        return a_var;
     }
 
     fn parse_dtor(attrs: ~[attribute]) -> class_contents {
index 084c2e82b3df5dc2c92d9932d74fea554a6576d3..fa47f7a21690d33c95dc5f10f62860b0d9561f79 100644 (file)
@@ -120,6 +120,9 @@ struct LanguageItemCollector {
     session: session,
 
     item_refs: hashmap<~str,&mut Option<def_id>>,
+}
+
+impl LanguageItemCollector {
 
     fn match_and_collect_meta_item(item_def_id: def_id,
                                    meta_item: meta_item) {
index b85b10e50e81bf8c5fe84a64b2f7fa0838be3a0e..c99afbd69921eb31a3d2e2dda6829a07c970f8ae 100644 (file)
@@ -379,14 +379,6 @@ struct ImportResolution {
     mut type_target: Option<Target>,
 
     mut used: bool,
-
-    fn target_for_namespace(namespace: Namespace) -> Option<Target> {
-        match namespace {
-            ModuleNS    => return copy self.module_target,
-            TypeNS      => return copy self.type_target,
-            ValueNS     => return copy self.value_target
-        }
-    }
 }
 
 fn ImportResolution(span: span) -> ImportResolution {
@@ -400,6 +392,16 @@ fn ImportResolution(span: span) -> ImportResolution {
     }
 }
 
+impl ImportResolution {
+    fn target_for_namespace(namespace: Namespace) -> Option<Target> {
+        match namespace {
+            ModuleNS    => return copy self.module_target,
+            TypeNS      => return copy self.type_target,
+            ValueNS     => return copy self.value_target
+        }
+    }
+}
+
 /// The link from a module up to its nearest parent node.
 enum ParentLink {
     NoParentLink,
@@ -448,10 +450,6 @@ struct Module {
 
     // The index of the import we're resolving.
     mut resolved_import_count: uint,
-
-    fn all_imports_resolved() -> bool {
-        return self.imports.len() == self.resolved_import_count;
-    }
 }
 
 fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
@@ -468,6 +466,12 @@ fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
     }
 }
 
+impl Module {
+    fn all_imports_resolved() -> bool {
+        return self.imports.len() == self.resolved_import_count;
+    }
+}
+
 // XXX: This is a workaround due to is_none in the standard library mistakenly
 // requiring a T:copy.
 
@@ -518,6 +522,9 @@ struct NameBindings {
     mut module_span: Option<span>,
     mut type_span: Option<span>,
     mut value_span: Option<span>,
+}
+
+impl NameBindings {
 
     /// Creates a new module in this set of name bindings.
     fn define_module(parent_link: ParentLink, def_id: Option<def_id>,
@@ -627,7 +634,9 @@ fn NameBindings() -> NameBindings {
 /// Interns the names of the primitive types.
 struct PrimitiveTypeTable {
     primitive_types: hashmap<Atom,prim_ty>,
+}
 
+impl PrimitiveTypeTable {
     fn intern(intr: ident_interner, string: @~str,
               primitive_type: prim_ty) {
         let atom = intr.intern(string);
@@ -773,6 +782,9 @@ struct Resolver {
     export_map: ExportMap,
     export_map2: ExportMap2,
     trait_map: TraitMap,
+}
+
+impl Resolver {
 
     /// The main name resolution procedure.
     fn resolve(@self, this: @Resolver) {
index a1c5af226bf11c7e05c45a9e8cb4f1b9ca434d5c..6694160e98e02f416dfb0d7e5642bc97f2bf8291 100644 (file)
@@ -105,6 +105,9 @@ struct lookup {
     candidate_impls: hashmap<def_id, ()>,
     supplied_tps: ~[ty::t],
     include_private: bool,
+}
+
+impl lookup {
 
     // Entrypoint:
     fn method() -> Option<method_map_entry> {
index b6fcb0c385fc4a243250e85646d8b036faec3293..a75ec2c83dc0fc0be904be969360f624fcfd8baa 100644 (file)
@@ -158,6 +158,9 @@ struct CoherenceChecker {
     // implementations that are defined in the same scope as their base types.
 
     privileged_implementations: hashmap<node_id,()>,
+}
+
+impl CoherenceChecker {
 
     // Create a mapping containing a MethodInfo for every provided
     // method in every trait.
index b0fffc06cb5443dfdcfacd2cae07d09f96f426e2..30b57e5fbff4bdf3400922c8b96b2a54b0955a5e 100644 (file)
@@ -7,9 +7,11 @@ struct cat {
 
   how_hungry : int,
 
-  fn speak() {}
 }
 
+    impl cat {
+        fn speak() {}
+    }
     fn cat(in_x : uint, in_y : int) -> cat {
         cat {
             meows: in_x,
index 3395de71e8a909281b0e6cfb2fd5392771b81d63..53f1a3568947aa9005961d19bfc234c6cfc73654 100644 (file)
@@ -6,12 +6,13 @@ struct cat {
   }
 
   how_hungry : int,
-
-  fn speak() { self.meows += 1u; }
-  fn meow_count() -> uint { self.meows }
-
 }
 
+    impl cat {
+        fn speak() { self.meows += 1u; }
+        fn meow_count() -> uint { self.meows }
+    }
+
     fn cat(in_x : uint, in_y : int) -> cat {
         cat {
             meows: in_x,
index 3fab6722da4a28899d388022baf8c570e4bcba5b..585fc09e3202e807e2cd86a13f253df6c37e043d 100644 (file)
@@ -3,17 +3,13 @@ mod kitties {
 struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : ~str,
+}
+
+impl cat {
 
   fn speak() { self.meow(); }
 
@@ -30,6 +26,16 @@ fn eat() -> bool {
   }
 }
 
+    priv impl cat {
+        fn meow() {
+            error!("Meow");
+            self.meows += 1u;
+            if self.meows % 5u == 0u {
+                self.how_hungry += 1;
+            }
+        }
+    }
+
     fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
         cat {
             meows: in_x,
index 4f758e74ed8e13101403ccd9054296b7ed698d20..f2c34722bd2eb377213b4374247ccbb37b365da2 100644 (file)
@@ -3,13 +3,16 @@ mod kitties {
 struct cat {
   priv {
     mut meows : uint,
-      fn nap() { for uint::range(1u, 10000u) |_i|{}}
   }
 
   how_hungry : int,
 
 }
 
+    impl cat {
+      priv fn nap() { for uint::range(1u, 10000u) |_i|{}}
+    }
+
     fn cat(in_x : uint, in_y : int) -> cat {
         cat {
             meows: in_x,
index 31506550099e48bcfb7eab1b45bd1f526c90fd46..272c381c73d2e950cf3d82ad19ed873fc79b6e5f 100644 (file)
@@ -7,13 +7,14 @@ struct cat<U> {
   }
 
   how_hungry : int,
-
-  fn speak<T>(stuff: ~[T]) {
-    self.meows += stuff.len();
-  }
-  fn meow_count() -> uint { self.meows }
 }
 
+    impl<U> cat<U> {
+        fn speak<T>(stuff: ~[T]) {
+            self.meows += stuff.len();
+        }
+        fn meow_count() -> uint { self.meows }
+    }
 
 fn cat<U>(in_x : uint, in_y : int, -in_info: ~[U]) -> cat<U> {
     cat {
index 0385ea991a230ac5aa141f1b964568071d8fe995..56cf40fd968b203533f76eba3e7ec2557f56e9c9 100644 (file)
@@ -3,38 +3,45 @@
 
 mod kitty {
 
-struct cat : ToStr {
+struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : ~str,
+}
 
-  fn speak() { self.meow(); }
-
-  fn eat() -> bool {
-    if self.how_hungry > 0 {
-        error!("OM NOM NOM");
-        self.how_hungry -= 2;
-        return true;
+    impl cat : ToStr {
+        fn to_str() -> ~str { self.name }
     }
-    else {
-        error!("Not hungry!");
-        return false;
-    }
-  }
 
-  fn to_str() -> ~str { self.name }
-}
+    priv impl cat {
+        fn meow() {
+            error!("Meow");
+            self.meows += 1u;
+            if self.meows % 5u == 0u {
+                self.how_hungry += 1;
+            }
+        }
+
+    }
 
+    impl cat {
+        fn speak() { self.meow(); }
+
+        fn eat() -> bool {
+            if self.how_hungry > 0 {
+                error!("OM NOM NOM");
+                self.how_hungry -= 2;
+                return true;
+            }
+            else {
+                error!("Not hungry!");
+                return false;
+            }
+        }
+    }
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
     cat {
         meows: in_x,
index a4dc2539eb3fc465485e690d78a8c99d651ca7d9..a2d816ec369e3f594c0780c410056f46944e9f49 100644 (file)
@@ -94,7 +94,9 @@ fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
 
 struct box<T> {
     mut contents: Option<T>,
+}
 
+impl<T> box<T> {
     fn swap(f: fn(+T) -> T) {
         let mut tmp = None;
         self.contents <-> tmp;
@@ -344,10 +346,12 @@ fn is_word_char(c: char) -> bool {
     char::is_alphabetic(c) || char::is_digit(c) || c == '_'
 }
 
-struct random_word_reader: word_reader {
+struct random_word_reader {
     mut remaining: uint,
     rng: rand::Rng,
+}
 
+impl random_word_reader: word_reader {
     fn read_word() -> Option<~str> {
         if self.remaining > 0 {
             self.remaining -= 1;
index d59a1c8448e79af713b0a3839d17e7b11605422b..4d63180a8438f007705d6f9e418df192de63f5ac 100644 (file)
@@ -4,6 +4,9 @@ struct cat {
   }
 
   how_hungry : int,
+}
+
+impl cat {
 
   fn speak() { self.meows += 1u; }
 }
index fa81909198553a560cf3b88a2aadfa9938808e55..58c0bfab79999c3a8aa02c9194ffc75bfd011412 100644 (file)
@@ -3,22 +3,16 @@ trait noisy {
   fn speak();
 }
 
-struct cat : noisy {
+struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : str,
+}
 
-  fn speak() { self.meow(); }
+impl cat {
 
   fn eat() -> bool {
     if self.how_hungry > 0 {
@@ -33,6 +27,21 @@ fn eat() -> bool {
   }
 }
 
+impl cat : noisy {
+  fn speak() { self.meow(); }
+
+}
+
+priv impl cat {
+    fn meow() {
+      error!("Meow");
+      self.meows += 1u;
+      if self.meows % 5u == 0u {
+          self.how_hungry += 1;
+      }
+    }
+}
+
 fn cat(in_x : uint, in_y : int, in_name: str) -> cat {
     cat {
         meows: in_x,
index 440152a92885b9758b0c7ab37042978a1bd588be..48a8c7a56b9cbced69262b6206a5086cfd2b00eb 100644 (file)
@@ -1,13 +1,16 @@
 struct cat {
   priv {
     mut meows : uint,
+  }
+}
+
+priv impl cat {
     fn sleep() { loop{} }
     fn meow() {
       error!("Meow");
       meows += 1u; //~ ERROR unresolved name
       sleep();     //~ ERROR unresolved name
     }
-  }
 
 }
 
index d0c265eb4ee3b8b7e88ccd02532cdc9b80cd8ad6..0335f6698953104ca839646ca4b22acf72414d53 100644 (file)
@@ -1,4 +1,9 @@
+// xfail-test Resolve code for classes knew how to do this, impls don't
+
 struct cat {
   tail: int,
+}
+
+impl cat {
   fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail`
 }
index 011c573b9b000a0e39044e20afa42a4aa0522f23..acf85de8bd7072fd38ca8056c25e958dedfa7421 100644 (file)
@@ -2,6 +2,9 @@ struct socket {
     sock: int,
 
     drop { }
+}
+
+impl socket {
 
     fn set_identity()  {
         do closure {
index 32b50b4385e138c8a8ecb9301762d50a185b5fa8..2dacbe314e26c6b6ab5cac3c84ea822cf1baab42 100644 (file)
@@ -4,6 +4,9 @@ fn siphash(k0 : u64) {
 
     struct siphash {
         mut v0: u64,
+    }
+
+    impl siphash {
         fn reset() {
            self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
            //~^ ERROR unresolved name: k0
index f2917044e708f1f765282e80b9a5c198e2ec3264..68eaffc7f703c39e61ca014411cc9dbfd8eba2a8 100644 (file)
@@ -5,7 +5,9 @@ struct cat {
   }
 
   how_hungry : int,
+}
 
+impl cat {
   fn eat() {
     self.how_hungry -= 5;
   }
index 3cf5e5da75af231a13dc23a289efa4533f320756..2d258e58b8472f353901c19392bde48be75ea9c3 100644 (file)
@@ -1,5 +1,6 @@
 // error-pattern:attempted access of field `nap` on type
 // xfail-fast
+// xfail-test
 // aux-build:cci_class_5.rs
 use cci_class_5;
 use cci_class_5::kitties::*;
index 545843762be1ce317799b3f4f58695516ba27a63..d9f070fb5bd8097907457a727f3efde5cd07a778 100644 (file)
@@ -1,22 +1,28 @@
-// error-pattern:call to private method not allowed
+// error-pattern:method `nap` is private
+
+mod kitties {
 struct cat {
   priv {
     mut meows : uint,
-      fn nap() { uint::range(1u, 10000u, |_i|{})}
   }
 
   how_hungry : int,
 
 }
 
+impl cat {
+    priv fn nap() { uint::range(1u, 10000u, |_i| false)}
+}
+
 fn cat(in_x : uint, in_y : int) -> cat {
     cat {
         meows: in_x,
         how_hungry: in_y
     }
 }
+}
 
 fn main() {
-  let nyan : cat = cat(52u, 99);
+  let nyan : kitties::cat = kitties::cat(52u, 99);
   nyan.nap();
 }
index 54fad53190eeedd90838a660b1380028318d1241..67e828762f11a38d17069a8ebd672dad8c38b5ab 100644 (file)
@@ -1,6 +1,8 @@
 struct dog {
     mut cats_chased: uint,
+}
 
+impl dog {
     fn chase_cat() {
         let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow
         *p += 1u;
index 4e51301827d8eaee2cabd8603d6fa9eef6b38fc4..a641d929f771b740fd13bc20fd024c173b9d6959 100644 (file)
@@ -1,6 +1,8 @@
 struct dog {
     mut food: uint,
+}
 
+impl dog {
     fn chase_cat() {
         for uint::range(0u, 10u) |_i| {
             let p: &static/mut uint = &mut self.food; //~ ERROR illegal borrow
index aa0268afbedc52d06af45f5f3ab22edb8a070330..f2e35c4cd557dbce084c5ede639b232596734a40 100644 (file)
@@ -2,10 +2,16 @@ trait noisy {
   fn speak() -> int;
 }
 
-struct dog : noisy {
+struct dog {
   priv {
     barks : @mut uint,
-    fn bark() -> int {
+  }
+
+  volume : @mut int,
+}
+
+impl dog {
+    priv fn bark() -> int {
       debug!("Woof %u %d", *self.barks, *self.volume);
       *self.barks += 1u;
       if *self.barks % 3u == 0u {
@@ -17,10 +23,9 @@ fn bark() -> int {
       debug!("Grrr %u %d", *self.barks, *self.volume);
       *self.volume
     }
-  }
-
-  volume : @mut int,
+}
 
+impl dog : noisy {
   fn speak() -> int { self.bark() }
 }
 
@@ -31,9 +36,24 @@ fn dog() -> dog {
     }
 }
 
-struct cat : noisy {
+struct cat {
   priv {
     meows : @mut uint,
+  }
+
+  how_hungry : @mut int,
+  name : ~str,
+}
+
+impl cat : noisy {
+  fn speak() -> int { self.meow() as int }
+}
+
+impl cat {
+  fn meow_count() -> uint { *self.meows }
+}
+
+priv impl cat {
     fn meow() -> uint {
       debug!("Meow");
       *self.meows += 1u;
@@ -42,13 +62,6 @@ fn meow() -> uint {
       }
       *self.meows
     }
-  }
-
-  how_hungry : @mut int,
-  name : ~str,
-
-  fn speak() -> int { self.meow() as int }
-  fn meow_count() -> uint { *self.meows }
 }
 
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
index 5be8454d65b5282377cdee4a15fdf931c2c23a33..422dd6142f049ac343cf650cfe65bbc4a0995337 100644 (file)
@@ -2,23 +2,20 @@ trait noisy {
   fn speak();
 }
 
-struct cat : noisy {
+struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : ~str,
+}
 
+impl cat : noisy {
   fn speak() { self.meow(); }
+}
 
+impl cat {
   fn eat() -> bool {
     if self.how_hungry > 0 {
         error!("OM NOM NOM");
@@ -32,6 +29,16 @@ fn eat() -> bool {
   }
 }
 
+priv impl cat {
+    fn meow() {
+      error!("Meow");
+      self.meows += 1u;
+      if self.meows % 5u == 0u {
+          self.how_hungry += 1;
+      }
+    }
+}
+
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
     cat {
         meows: in_x,
index 46b93b2f524af5a61de49bfee079023e98992659..ef03681197623c83cb8624ff91d7501ea2f59966 100644 (file)
@@ -8,7 +8,9 @@ mod kitty {
   struct cat {
     meows: uint,
     name: ~str,
+  }
 
+  impl cat {
     fn get_name() -> ~str {  self.name }
   }
 
index 665ee3cfe25a82d8bfa83927e904cd6dd803f24e..ce6074ad4a77bc50c33f67dc74848e52d814ad90 100644 (file)
@@ -14,22 +14,17 @@ impl cat_type : cmp::Eq {
 // for any int value that's less than the meows field
 
 // ok: T should be in scope when resolving the trait ref for map
-struct cat<T: Copy> : map<int, T> {
+struct cat<T: Copy> {
   priv {
     // Yes, you can have negative meows
     mut meows : int,
-    fn meow() {
-      self.meows += 1;
-      error!("Meow %d", self.meows);
-      if self.meows % 5 == 0 {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : T,
+}
 
+impl<T: Copy> cat<T> {
   fn speak() { self.meow(); }
 
   fn eat() -> bool {
@@ -43,7 +38,9 @@ fn eat() -> bool {
         return false;
     }
   }
+}
 
+impl<T: Copy> cat<T> : map<int, T> {
   pure fn size() -> uint { self.meows as uint }
   fn insert(+k: int, +_v: T) -> bool {
     self.meows += k;
@@ -94,6 +91,16 @@ fn remove(+k:int) -> bool {
   fn clear() { }
 }
 
+priv impl<T: Copy> cat<T> {
+    fn meow() {
+      self.meows += 1;
+      error!("Meow %d", self.meows);
+      if self.meows % 5 == 0 {
+          self.how_hungry += 1;
+      }
+    }
+}
+
 fn cat<T: Copy>(in_x : int, in_y : int, in_name: T) -> cat<T> {
     cat {
         meows: in_x,
index 0551ebc62d44e5c2747d671f30ab55202b082a6f..a1c2b420c46e3f061ed8ce3613c8bb83febf71d5 100644 (file)
@@ -3,23 +3,16 @@
 use cci_class_trait;
 use cci_class_trait::animals::*;
 
-struct cat : noisy {
+struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : ~str,
+}
 
-  fn speak() { self.meow(); }
-
+impl cat {
   fn eat() -> bool {
     if self.how_hungry > 0 {
         error!("OM NOM NOM");
@@ -33,6 +26,22 @@ fn eat() -> bool {
   }
 }
 
+impl cat : noisy {
+
+  fn speak() { self.meow(); }
+
+}
+
+priv impl cat {
+    fn meow() {
+      error!("Meow");
+      self.meows += 1u;
+      if self.meows % 5u == 0u {
+          self.how_hungry += 1;
+      }
+    }
+}
+
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
     cat {
         meows: in_x,
index 1e40ae872ad16afc0a14de6c942c722bbaa09189..e31501d02f52f515d5e846e67804288bf24d2c15 100644 (file)
@@ -2,9 +2,16 @@ trait noisy {
   fn speak();
 }
 
-struct cat : noisy {
+struct cat {
   priv {
     mut meows : uint,
+  }
+
+  mut how_hungry : int,
+  name : ~str,
+}
+
+priv impl cat {
     fn meow() {
       error!("Meow");
       self.meows += 1u;
@@ -12,13 +19,9 @@ fn meow() {
           self.how_hungry += 1;
       }
     }
-  }
-
-  mut how_hungry : int,
-  name : ~str,
-
-  fn speak() { self.meow(); }
+}
 
+impl cat {
   fn eat() -> bool {
     if self.how_hungry > 0 {
         error!("OM NOM NOM");
@@ -32,6 +35,10 @@ fn eat() -> bool {
   }
 }
 
+impl cat : noisy {
+  fn speak() { self.meow(); }
+}
+
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
     cat {
         meows: in_x,
index e95b1dbc91ce7545342b7d86378799724fbc2f00..d5cee133097f92af04efb0ff05852e509c3aa02b 100644 (file)
@@ -4,6 +4,9 @@ struct cat {
   }
 
   how_hungry : int,
+}
+
+impl cat {
 
   fn speak() { self.meows += 1u; }
   fn meow_count() -> uint { self.meows }
index 586dd3e736108bb6b0b0f0bebfa2f62084ed7512..0f07b36e6c141f9fd1c4550ab39d9f435b425a43 100644 (file)
@@ -5,7 +5,9 @@ struct cat<U> {
   }
 
   how_hungry : int,
+}
 
+impl<U> cat<U> {
   fn speak<T>(stuff: ~[T]) {
     self.meows += stuff.len();
   }
index dcbaffc2c3029e98dcb71c1415ba1dbdabd747a1..47fd98b49a89ec1fa750e6362f2c48e3ac094ce9 100644 (file)
@@ -5,17 +5,13 @@
 struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : ~str,
+}
+
+impl cat {
 
   fn speak() { self.meow(); }
 
@@ -32,6 +28,16 @@ fn eat() -> bool {
   }
 }
 
+priv impl cat {
+    fn meow() {
+      error!("Meow");
+      self.meows += 1u;
+      if self.meows % 5u == 0u {
+          self.how_hungry += 1;
+      }
+    }
+}
+
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
     cat {
         meows: in_x,
index e736ac7308add3a1ea518a226816117f4952b2c5..d11b1761b3cd7f489d0fe74370ce3ed1797f13ff 100644 (file)
@@ -4,7 +4,9 @@ struct cat<U> {
   }
 
   how_hungry : int,
+}
 
+impl<U> cat<U> {
   fn speak() {
     self.meows += 1u;
   }
index f1dc265c953e759ae07fb7b3dda1f0fdb58d5bbe..4cee896f23a3d4edafa9e0e3c96b7c79ac2aba28 100644 (file)
@@ -4,7 +4,9 @@ struct cat {
   }
 
   how_hungry : int,
+}
 
+impl cat {
   fn speak() {}
 }
 
index bf58e9fe35f3440775be39b5046fb829d2238298..0ade8e57f9ca1dc360c1f3c6023f0b34b297718b 100644 (file)
@@ -1,17 +1,13 @@
 struct cat {
   priv {
     mut meows : uint,
-    fn meow() {
-      error!("Meow");
-      self.meows += 1u;
-      if self.meows % 5u == 0u {
-          self.how_hungry += 1;
-      }
-    }
   }
 
   mut how_hungry : int,
   name : ~str,
+}
+
+impl cat {
 
   fn speak() { self.meow(); }
 
@@ -28,6 +24,16 @@ fn eat() -> bool {
   }
 }
 
+priv impl cat {
+    fn meow() {
+      error!("Meow");
+      self.meows += 1u;
+      if self.meows % 5u == 0u {
+          self.how_hungry += 1;
+      }
+    }
+}
+
 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
     cat {
         meows: in_x,
index f4d045bb44417a124a74f21c3cc41744f51948a5..fb88ee6e8ff71866f11e95fd3bdeb779ee71cec6 100644 (file)
@@ -1,8 +1,11 @@
 trait clam<A: Copy> {
   fn chowder(y: A);
 }
-struct foo<A: Copy> : clam<A> {
+struct foo<A: Copy> {
   x: A,
+}
+
+impl<A: Copy> foo<A> : clam<A> {
   fn chowder(y: A) {
   }
 }
index ef3752d5fa741772a7d38ea8101d91149fc71398..9c3ea2b2b7e4a1023d09abae028df6245a6e008a 100644 (file)
@@ -1,6 +1,9 @@
 trait clam<A: Copy> { }
 struct foo<A: Copy> {
     x: A,
+}
+
+impl<A: Copy> foo<A> {
    fn bar<B,C:clam<A>>(c: C) -> B {
      fail;
    }
index 0b6502860204b2b571fdde4348c782648ebe097d..f52cec96f44e05c99243c5077919271d3fb0ecec 100644 (file)
@@ -1,5 +1,8 @@
 struct c1<T: Copy> {
     x: T,
+}
+
+impl<T: Copy> c1<T> {
     fn f1(x: int) {
     }
 }
index ae6cdf34e4d329ff367cd3ab08fb4e197697536a..b5e21e32729fd22e54e50c0680692b8e52a35c05 100644 (file)
@@ -2,6 +2,9 @@
 
 struct c1<T: Copy> {
     x: T,
+}
+
+impl<T: Copy> c1<T> {
     fn f1(x: T) {}
 }
 
index a8c6e5b1a0de49cd30ed58ce43418553a0f0fbc7..8a21f128a99165de82ec4127ee3d6ab52b6def5b 100644 (file)
@@ -2,6 +2,9 @@ struct socket {
     sock: int,
 
     drop { }
+}
+
+impl socket {
 
     fn set_identity()  {
         do closure {
index d58f5a8ecb2b96f34ea81bc244ca7e3649b973f6..64028890df027281813eae84572b2023de0b7885 100644 (file)
@@ -1,6 +1,8 @@
 struct font {
     fontbuf: &self/~[u8],
+}
 
+impl font {
     fn buf() -> &self/~[u8] {
         self.fontbuf
     }
index d878d3fcf4b63533197dd936ead360f92531dc9c..6f6b6e2cd393f34f8cbf29dca50e85d066deae50 100644 (file)
@@ -145,6 +145,9 @@ struct send_packet<T: Send> {
                 sender_terminate(option::unwrap(p))
             }
         }
+    }
+
+    impl<T: Send> send_packet<T> {
         fn unwrap() -> *packet<T> {
             let mut p = None;
             p <-> self.p;
@@ -167,6 +170,9 @@ struct recv_packet<T: Send> {
                 receiver_terminate(option::unwrap(p))
             }
         }
+    }
+
+    impl<T: Send> recv_packet<T> {
         fn unwrap() -> *packet<T> {
             let mut p = None;
             p <-> self.p;
index e76a3088f81f754ba2b1aa1f018896ea0379b067..c4b6ef99e706e3624efb8fefb57a50c4499048e5 100644 (file)
@@ -6,8 +6,11 @@ fn foo<T, U: bar<T>>(b: U) -> T {
     b.get_bar()
 }
 
-struct cbar : bar<int> {
+struct cbar {
     x: int,
+}
+
+impl cbar : bar<int> {
     fn get_bar() -> int {
         self.x
     }
index 6c30ee106d4241341027fe3dc5d3e6e88038c5c3..4fc49383adc48613643cd6ac0ed26c473deedfb4 100644 (file)
@@ -2,6 +2,9 @@ fn main() {
   
   struct b {
     i: int,
+  }
+
+  impl b {
     fn do_stuff() -> int { return 37; }
   }
 
index 4b54a473faaa5d1981428ccda79d3efc366c6545..735545a580c16f37b3cc03c9dbda7c4ea5ad6c96 100644 (file)
@@ -4,7 +4,9 @@ struct cat {
   }
 
   how_hungry : int,
+}
 
+impl cat {
   fn meow_count() -> uint { self.meows }
 }
 
index ba11df9425658a0708681e3d42ca2a9a3dfcab26..23789676549b62dc44c33c48a1872bc0fa3f459b 100644 (file)
@@ -1,17 +1,22 @@
 struct cat {
   priv {
       mut meows : uint,
-      fn nap() { for uint::range(1u, 10u) |_i| { }}
   }
 
   how_hungry : int,
+}
 
+impl cat {
   fn play() {
     self.meows += 1u;
     self.nap();
   }
 }
 
+priv impl cat {
+    fn nap() { for uint::range(1u, 10u) |_i| { }}
+}
+
 fn cat(in_x : uint, in_y : int) -> cat {
     cat {
         meows: in_x,
index 4d51f1f554167e21bf02dca4fe1d8f2a26cb4625..3f3417fd703fd68b264535c300af20c649efa7de 100644 (file)
@@ -1,9 +1,12 @@
 struct shrinky_pointer {
   i: @@mut int,
-  fn look_at() -> int { return **(self.i); }
   drop { log(error, ~"Hello!"); **(self.i) -= 1; }
 }
 
+impl shrinky_pointer {
+  fn look_at() -> int { return **(self.i); }
+}
+
 fn shrinky_pointer(i: @@mut int) -> shrinky_pointer {
     shrinky_pointer {
         i: i
index 8927254886a9430c074edc8e363b6d928b2f8a18..8252922194333251192a02823d13d5ce453d9447 100644 (file)
@@ -1,6 +1,6 @@
 use std;
 use pipes::send;
-use pipes::chan;
+use pipes::Chan;
 use pipes::recv;
 
 fn main() { test00(); }