Remove the class keyword

This commit is contained in:
Brian Anderson 2012-08-15 18:46:55 -07:00
parent 6d7b143036
commit 3ab4b014cf
143 changed files with 185 additions and 421 deletions

View File

@ -211,7 +211,7 @@ The keywords in [source files](#source-files) are the following strings:
~~~~~~~~ {.keyword}
again assert
break
check class const copy
check const copy
drop
else enum export extern
fail false fn for
@ -220,6 +220,7 @@ let log loop
match mod mut
pure
return
struct
true trait type
unchecked unsafe
while
@ -1097,151 +1098,6 @@ enum list<T> {
let a: list<int> = cons(7, @cons(13, @nil));
~~~~
### Classes
A _class_ is a named record type that collects together fields and
methods. It must have a _constructor_ (a function called `new` that
returns a new instance of the class), and may have a destructor (a
nullary function called `drop` that executes before the memory manager
frees the memory for a given class). For historical reasons, we may
call a class with a destructor and a single field a "resource".
A _class item_ declares a class type:
~~~~
class file_descriptor {
let fd: libc::c_int;
new(fd: libc::c_int) { self.fd = fd; }
drop { libc::close(self.fd); }
}
~~~~
Calling the `file_descriptor` constructor function on an integer will
produce a value with the `file_descriptor` type.
_Fields_ are immutable by default, so instances of `file_descriptor`
can't have their `fd` fields reassigned. A mutable field declaration
looks like:
~~~~
let mut fd: libc::c_int;
~~~~
The only exception is that the body of the class constructor begins
with all the class's fields uninitialized, and is allowed to -- in
fact, must -- initialize all the fields. The compiler enforces this
invariant.
Usually, the class constructor stores its argument or arguments in the
class's named fields. In this case, the `file_descriptor`'s data field
would be accessed like `f.fd`, if `f` is a value of type
`file_descriptor`. By default, class fields are _public_: they can be
accessed both from methods inside the class, and code outside the
class. Classes can also have private fields:
~~~~
class file_descriptor {
let fd: *libc::FILE;
new(fd: *libc::FILE) {
self.fd = fd; self.name = none;
}
priv {
let mut name: option<~str>;
}
fn get_name() -> ~str {
match self.name {
none => fail ~"File has no name!",
some(n) => n
}
}
}
~~~~
Private fields are instance-private: methods in a class `C` can access
`self`'s private fields, but not private fields of other values of
type `C`. Code outside a class can't access any private fields.
A class item may contain _methods_, which take an implicit `self`
argument:
~~~~
class file_descriptor {
let fd: *libc::FILE;
new(fd: *libc::FILE) { self.fd = fd; }
fn flush() {
libc::fflush(self.fd);
}
}
~~~~
In this case, ```open``` is a nullary method that calls the
```fopen``` function, defined in another library, on the ```fd```
field. As in this example, methods must refer to their self's fields
as fields of ```self```; bare references to ```fd``` can't
occur. Methods can be public or private; just like fields, they are
public by default and private if enclosed in a `priv` section.
Classes may be polymorphic:
~~~~
class file<A: copy> {
let data: A;
let fd: *libc::FILE;
new(data: A, fd: *libc::FILE) { self.data = data; self.fd = fd; }
}
~~~~
Methods may also be polymorphic, and can have additional type
parameters other than those bound in the class:
~~~~
class file<A: copy> {
let data: A;
let fd: *libc::FILE;
new(fd: *libc::FILE, data: A) { self.fd = fd; self.data = data; }
fn map_data<B>(f: fn(A) -> B) -> B {
f(self.data)
}
}
~~~~
Classes do not support inheritance, except through traits. As a
result, all class method dispatch is static (non-virtual).
A class may implement a trait (see [traits](#traits)):
~~~~
trait to_str {
fn to_str() -> ~str;
}
class file : to_str {
let fd: *libc::FILE;
new(fd: *libc::FILE) { self.fd = fd; }
fn to_str() -> ~str { ~"a file" }
}
~~~~
The syntax `class file: to_str` is pronounced "class `file`
implements trait `to_str`".
Class instances may be allocated on the stack, in the exchange heap,
or on the task heap. A value with a class type ```C``` has a
noncopyable [type kind](#type-kinds) if ```C``` has a destructor, and
thus may not be copied. Class types that don't have destructors may be
copied if all their fields are copyable.
The semantics guarantee that for each constructed resource value, the
destructor will run once: when the value is disposed of (barring
drastic program termination that somehow prevents unwinding from
taking place). For stack-allocated values, disposal happens when the
value goes out of scope. For values in shared boxes, it happens when
the reference count of the box reaches zero.
The order of fields in a class instance is significant; its runtime
representation is the same as that of a record with identical fields
laid out in the same order.
### Traits
A _trait item_ describes a set of method types. [_implementation
@ -1348,7 +1204,7 @@ trait. The methods in such an implementation can only be used
statically (as direct calls on the values of the type that the
implementation targets). In such an implementation, the `of` clause is
not given, and the name is mandatory. Such implementations are
limited to nominal types (enums, classes) and the implementation must
limited to nominal types (enums, structs) and the implementation must
appear in the same module or a sub-module as the receiver type.
_When_ a trait is specified, all methods declared as part of the
@ -2744,9 +2600,9 @@ fn main() {
In this example, the trait `printable` occurs as a type in both the type signature of
`print`, and the cast expression in `main`.
### Class types
### Struct types
Every class item defines a type. See [classes](#classes).
Every struct item defines a type.
### Type parameters
@ -2766,7 +2622,7 @@ type `~[B]`, a vector type with element type `B`.
### Self type
The special type `self` has a meaning within methods inside a class or
The special type `self` has a meaning within methods inside an
impl item. It refers to the type of the implicit `self` argument. For
example, in:
@ -2781,19 +2637,7 @@ impl ~str: printable {
~~~~~~
`self` refers to the value of type `str` that is the receiver for a
call to the method `to_str`. Similarly, in a class declaration:
~~~~~~
class cat {
let mut meows: uint;
new() { self.meows = 0; }
fn meow() { self.meows = self.meows + 1; }
}
~~~~~~
`self` refers to the class instance that is the receiver of the method
(except in the constructor `new`, where `self` is the class instance
that the constructor implicitly returns).
call to the method `to_str`.
## Type kinds

View File

@ -1821,85 +1821,6 @@ fn contains(v: ~[int], elt: int) -> bool {
`for` syntax only works with stack closures.
# Classes
Rust lets users define new types with fields and methods, called 'classes', in
the style of object-oriented languages.
> ***Warning:*** Rust's classes are in the process of changing rapidly. Some more
> information about some of the potential changes is [here][classchanges].
[classchanges]: http://pcwalton.github.com/blog/2012/06/03/maximally-minimal-classes-for-rust/
An example of a class:
~~~~
class example {
let mut x: int;
let y: int;
priv {
let mut private_member: int;
fn private_method() {}
}
new(x: int) {
// Constructor
self.x = x;
self.y = 7;
self.private_member = 8;
}
fn a() {
io::println(~"a");
}
drop {
// Destructor
self.x = 0;
}
}
fn main() {
let x: example = example(1);
let y: @example = @example(2);
x.a();
x.x = 5;
}
~~~~
Fields and methods are declared just like functions and local variables, using
'fn' and 'let'. As usual, 'let mut' can be used to create mutable fields. At
minimum, Rust classes must have at least one field.
Rust classes must also have a constructor, and can optionally have a destructor
as well. The constructor and destructor are declared as shown in the example:
like methods named 'new' and 'drop', but without 'fn', and without arguments
for drop.
In the constructor, the compiler will enforce that all fields are initialized
before doing anything that might allow them to be accessed. This includes
returning from the constructor, calling any method on 'self', calling any
function with 'self' as an argument, or taking a reference to 'self'. Mutation
of immutable fields is possible only in the constructor, and only before doing
any of these things; afterwards it is an error.
Private fields and methods are declared as shown above, using a `priv { ... }`
block within the class. They are accessible only from within the same instance
of the same class. (For example, even from within class A, you cannot call
private methods, or access private fields, on other instances of class A; only
on `self`.) This accessibility restriction may change in the future.
As mentioned below, in the section on copying types, classes with destructors
are considered 'resource' types and are not copyable.
Declaring a class also declares its constructor as a function of the same name.
You can construct an instance of the class, as in the example, by calling that
function. The function and the type, though they have the same name, are
otherwise independent. As with other Rust types, you can use `@` or `~` to
construct a heap-allocated instance of a class, either shared or unique; just
call e.g. `@example(...)` as shown above.
# Argument passing
Rust datatypes are not trivial to copy (the way, for example,

View File

@ -97,7 +97,7 @@ fn listen<T: send, U>(f: fn(Chan<T>) -> U) -> U {
f(po.chan())
}
class PortPtr<T:send> {
struct PortPtr<T:send> {
let po: *rust_port;
new(po: *rust_port) { self.po = po; }
drop unsafe {
@ -132,7 +132,7 @@ class PortPtr<T:send> {
*/
fn as_raw_port<T: send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
class PortRef {
struct PortRef {
let p: *rust_port;
new(p: *rust_port) { self.p = p; }
drop {

View File

@ -237,7 +237,7 @@ impl<T: Reader, C> {base: T, cleanup: C}: Reader {
fn tell() -> uint { self.base.tell() }
}
class FILERes {
struct FILERes {
let f: *libc::FILE;
new(f: *libc::FILE) { self.f = f; }
drop { libc::fclose(self.f); }
@ -415,7 +415,7 @@ impl fd_t: Writer {
}
}
class FdRes {
struct FdRes {
let fd: fd_t;
new(fd: fd_t) { self.fd = fd; }
drop { libc::close(self.fd); }
@ -764,7 +764,7 @@ mod fsync {
// Artifacts that need to fsync on destruction
class Res<t> {
struct Res<t> {
let arg: Arg<t>;
new(-arg: Arg<t>) { self.arg <- arg; }
drop {

View File

@ -264,7 +264,7 @@ fn test_unwrap_str() {
#[test]
fn test_unwrap_resource() {
class r {
struct r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) += 1; }

View File

@ -194,7 +194,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
let _unweaken = Unweaken(ch);
f(po);
class Unweaken {
struct Unweaken {
let ch: comm::Chan<()>;
new(ch: comm::Chan<()>) { self.ch = ch; }
drop unsafe {

View File

@ -243,7 +243,7 @@ impl Rng {
}
class RandRes {
struct RandRes {
let c: *rctx;
new(c: *rctx) { self.c = c; }
drop { rustrt::rand_free(self.c); }

View File

@ -225,7 +225,7 @@ fn start_program(prog: &str, args: &[~str]) -> Program {
libc::fclose(r.out_file);
libc::fclose(r.err_file);
}
class ProgRes {
struct ProgRes {
let r: ProgRepr;
new(+r: ProgRepr) { self.r = r; }
drop { destroy_repr(&self.r); }

View File

@ -6,7 +6,7 @@ import sys::size_of;
type Word = uint;
class Frame {
struct Frame {
let fp: *Word;
new(fp: *Word) {

View File

@ -578,7 +578,7 @@ fn get_task() -> Task {
* ~~~
*/
unsafe fn unkillable<U>(f: fn() -> U) -> U {
class AllowFailure {
struct AllowFailure {
let t: *rust_task;
new(t: *rust_task) { self.t = t; }
drop { rustrt::rust_task_allow_kill(self.t); }
@ -592,7 +592,7 @@ unsafe fn unkillable<U>(f: fn() -> U) -> U {
/// The inverse of unkillable. Only ever to be used nested in unkillable().
unsafe fn rekillable<U>(f: fn() -> U) -> U {
class DisallowFailure {
struct DisallowFailure {
let t: *rust_task;
new(t: *rust_task) { self.t = t; }
drop { rustrt::rust_task_inhibit_kill(self.t); }
@ -609,7 +609,7 @@ unsafe fn rekillable<U>(f: fn() -> U) -> U {
* For use with exclusive ARCs, which use pthread mutexes directly.
*/
unsafe fn atomically<U>(f: fn() -> U) -> U {
class DeferInterrupts {
struct DeferInterrupts {
let t: *rust_task;
new(t: *rust_task) { self.t = t; }
drop {
@ -911,7 +911,7 @@ fn each_ancestor(list: &mut AncestorList,
}
// One of these per task.
class Tcb {
struct Tcb {
let me: *rust_task;
// List of tasks with whose fates this one's is intertwined.
let tasks: TaskGroupArc; // 'none' means the group has failed.
@ -952,7 +952,7 @@ class Tcb {
}
}
class AutoNotify {
struct AutoNotify {
let notify_chan: comm::Chan<Notification>;
let mut failed: bool;
new(chan: comm::Chan<Notification>) {

View File

@ -74,7 +74,7 @@ type ArcData<T> = {
data: T
};
class ArcDestruct<T> {
struct ArcDestruct<T> {
let data: *libc::c_void;
new(data: *libc::c_void) { self.data = data; }
drop unsafe {
@ -162,7 +162,7 @@ extern mod rustrt {
fn rust_unlock_little_lock(lock: rust_little_lock);
}
class LittleLock {
struct LittleLock {
let l: rust_little_lock;
new() {
self.l = rustrt::rust_create_little_lock();
@ -173,7 +173,7 @@ class LittleLock {
impl LittleLock {
#[inline(always)]
unsafe fn lock<T>(f: fn() -> T) -> T {
class Unlock {
struct Unlock {
let l: rust_little_lock;
new(l: rust_little_lock) { self.l = l; }
drop { rustrt::rust_unlock_little_lock(self.l); }

View File

@ -33,7 +33,7 @@ fn replace<T>(dest: &mut T, +src: T) -> T {
}
/// A non-copyable dummy type.
class NonCopyable {
struct NonCopyable {
i: ();
new() { self.i = (); }
drop { }

View File

@ -19,7 +19,7 @@ export to_str;
export eq_vec;
export methods;
class small_bitv {
struct small_bitv {
let mut bits: u32;
new(bits: u32) { self.bits = bits; }
priv {
@ -78,7 +78,7 @@ class small_bitv {
fn invert() { self.bits = !self.bits; }
}
class big_bitv {
struct big_bitv {
// only mut b/c of clone and lack of other constructor
let mut storage: ~[mut uint];
new(-storage: ~[mut uint]) {
@ -153,7 +153,7 @@ enum a_bitv { big(~big_bitv), small(~small_bitv) }
enum op {union, intersect, assign, difference}
// The bitvector type
class bitv {
struct bitv {
let rep: a_bitv;
let nbits: uint;

View File

@ -42,7 +42,7 @@ enum c_vec<T> {
c_vec_({ base: *mut T, len: uint, rsrc: @dtor_res})
}
class dtor_res {
struct dtor_res {
let dtor: option<fn@()>;
new(dtor: option<fn@()>) { self.dtor = dtor; }
drop {

View File

@ -38,7 +38,7 @@ extern mod rustrt {
* underlying libuv data structures when it goes out of scope. This is the
* data structure that is used for read/write operations over a TCP stream.
*/
class tcp_socket {
struct tcp_socket {
let socket_data: @tcp_socket_data;
new(socket_data: @tcp_socket_data) { self.socket_data = socket_data; }
drop {
@ -54,7 +54,7 @@ class tcp_socket {
* It is created with a call to `net::tcp::socket_buf()` and has impls that
* satisfy both the `io::reader` and `io::writer` traits.
*/
class tcp_socket_buf {
struct tcp_socket_buf {
let data: @tcp_buffered_socket_data;
new(data: @tcp_buffered_socket_data) { self.data = data; }
}

View File

@ -109,7 +109,7 @@ fn protocol(name: ident, +span: span) -> protocol {
@protocol_(name, span)
}
class protocol_ {
struct protocol_ {
let name: ident;
let span: span;
let states: DVec<state>;

View File

@ -180,7 +180,7 @@ pure fn maybe_append(+lhs: ~[attribute], rhs: option<~[attribute]>)
/* ident is handled by common.rs */
class parser {
struct parser {
let sess: parse_sess;
let cfg: crate_cfg;
let file_type: file_type;
@ -3201,8 +3201,7 @@ class parser {
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs)));
} else if items_allowed &&
(self.eat_keyword(~"class") || self.eat_keyword(~"struct")) {
} else if items_allowed && self.eat_keyword(~"struct") {
let (ident, item_, extra_attrs) = self.parse_item_class();
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
visibility,

View File

@ -335,7 +335,7 @@ fn restricted_keyword_table() -> hashmap<~str, ()> {
let keys = ~[
~"again", ~"assert",
~"break",
~"check", ~"class", ~"const", ~"copy",
~"check", ~"const", ~"copy",
~"do", ~"drop",
~"else", ~"enum", ~"export", ~"extern",
~"fail", ~"false", ~"fn", ~"for",

View File

@ -230,7 +230,7 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
diagnostic::emit(cmsp, msg, lvl);
};
class finally {
struct finally {
let ch: comm::Chan<monitor_msg>;
new(ch: comm::Chan<monitor_msg>) { self.ch = ch; }
drop { comm::send(self.ch, done); }

View File

@ -1122,7 +1122,7 @@ fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] unsafe {
/* Memory-managed interface to target data. */
class target_data_res {
struct target_data_res {
let TD: TargetDataRef;
new(TD: TargetDataRef) { self.TD = TD; }
drop { llvm::LLVMDisposeTargetData(self.TD); }
@ -1138,7 +1138,7 @@ fn mk_target_data(string_rep: ~str) -> target_data {
/* Memory-managed interface to pass managers. */
class pass_manager_res {
struct pass_manager_res {
let PM: PassManagerRef;
new(PM: PassManagerRef) { self.PM = PM; }
drop { llvm::LLVMDisposePassManager(self.PM); }
@ -1153,7 +1153,7 @@ fn mk_pass_manager() -> pass_manager {
/* Memory-managed interface to object files. */
class object_file_res {
struct object_file_res {
let ObjectFile: ObjectFileRef;
new(ObjectFile: ObjectFileRef) { self.ObjectFile = ObjectFile; }
drop { llvm::LLVMDisposeObjectFile(self.ObjectFile); }
@ -1169,7 +1169,7 @@ fn mk_object_file(llmb: MemoryBufferRef) -> option<object_file> {
/* Memory-managed interface to section iterators. */
class section_iter_res {
struct section_iter_res {
let SI: SectionIteratorRef;
new(SI: SectionIteratorRef) { self.SI = SI; }
drop { llvm::LLVMDisposeSectionIterator(self.SI); }

View File

@ -403,7 +403,7 @@ fn def_like_to_def(def_like: def_like) -> ast::def {
}
// A path.
class path_entry {
struct path_entry {
// The full path, separated by '::'.
let path_string: ~str;
// The definition, implementation, or field that this path corresponds to.

View File

@ -22,7 +22,7 @@ import syntax::visit::{visit_crate, visit_item};
import std::map::{hashmap, str_hash};
import str_eq = str::eq;
class LanguageItems {
struct LanguageItems {
let mut const_trait: option<def_id>;
let mut copy_trait: option<def_id>;
let mut send_trait: option<def_id>;
@ -62,7 +62,7 @@ class LanguageItems {
}
}
class LanguageItemCollector {
struct LanguageItemCollector {
let items: &LanguageItems;
let crate: @crate;

View File

@ -208,7 +208,7 @@ fn relevant_def(def: def) -> option<relevant_def> {
}
}
class ir_maps {
struct ir_maps {
let tcx: ty::ctxt;
let method_map: typeck::method_map;
let last_use_map: last_use_map;
@ -505,7 +505,7 @@ const ACC_READ: uint = 1u;
const ACC_WRITE: uint = 2u;
const ACC_USE: uint = 4u;
class liveness {
struct liveness {
let tcx: ty::ctxt;
let ir: @ir_maps;
let s: specials;

View File

@ -249,7 +249,7 @@ fn Atom(n: uint) -> Atom {
return n;
}
class AtomTable {
struct AtomTable {
let atoms: hashmap<@~str,Atom>;
let strings: DVec<@~str>;
let mut atom_count: uint;
@ -312,7 +312,7 @@ fn atom_hashmap<V:copy>() -> hashmap<Atom,V> {
}
/// One local scope.
class Rib {
struct Rib {
let bindings: hashmap<Atom,def_like>;
let kind: RibKind;
@ -323,7 +323,7 @@ class Rib {
}
/// One import directive.
class ImportDirective {
struct ImportDirective {
let module_path: @DVec<Atom>;
let subclass: @ImportDirectiveSubclass;
let span: span;
@ -339,7 +339,7 @@ class ImportDirective {
}
/// The item that an import resolves to.
class Target {
struct Target {
let target_module: @Module;
let bindings: @NameBindings;
@ -349,7 +349,7 @@ class Target {
}
}
class ImportResolution {
struct ImportResolution {
let span: span;
// The number of outstanding references to this name. When this reaches
@ -402,7 +402,7 @@ enum ParentLink {
}
/// One node in the tree of modules.
class Module {
struct Module {
let parent_link: ParentLink;
let mut def_id: option<def_id>;
@ -491,7 +491,7 @@ fn unused_import_lint_level(session: session) -> level {
// Records the definitions (at most one for each namespace) that a name is
// bound to.
class NameBindings {
struct NameBindings {
let mut module_def: ModuleDef; //< Meaning in the module namespace.
let mut type_def: option<def>; //< Meaning in the type namespace.
let mut value_def: option<def>; //< Meaning in the value namespace.
@ -611,7 +611,7 @@ class NameBindings {
}
/// Interns the names of the primitive types.
class PrimitiveTypeTable {
struct PrimitiveTypeTable {
let primitive_types: hashmap<Atom,prim_ty>;
new(atom_table: @AtomTable) {
@ -652,7 +652,7 @@ fn namespace_to_str(ns: Namespace) -> ~str {
}
/// The main resolver class.
class Resolver {
struct Resolver {
let session: session;
let lang_items: LanguageItems;
let crate: @crate;

View File

@ -83,7 +83,7 @@ fn dup_for_join(dest: dest) -> dest {
}
}
class icx_popper {
struct icx_popper {
let ccx: @crate_ctxt;
new(ccx: @crate_ctxt) { self.ccx = ccx; }
drop {

View File

@ -72,7 +72,7 @@ type stats =
llvm_insns: hashmap<~str, uint>,
fn_times: @mut ~[{ident: ~str, time: int}]};
class BuilderRef_res {
struct BuilderRef_res {
let B: BuilderRef;
new(B: BuilderRef) { self.B = B; }
drop { llvm::LLVMDisposeBuilder(self.B); }
@ -390,7 +390,7 @@ type node_info = {
// code. Each basic block we generate is attached to a function, typically
// with many basic blocks per function. All the basic blocks attached to a
// function are organized as a directed graph.
class block_ {
struct block_ {
// The BasicBlockRef returned from a call to
// llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic
// block to the function pointed to by llfn. We insert

View File

@ -56,7 +56,7 @@ fn transform_self_type_for_method
}
}
class lookup {
struct lookup {
let fcx: @fn_ctxt;
let expr: @ast::expr;
let self_expr: @ast::expr;

View File

@ -118,7 +118,7 @@ fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
}
}
class CoherenceInfo {
struct CoherenceInfo {
// Contains implementations of methods that are inherent to a type.
// Methods in these implementations don't need to be exported.
let inherent_methods: hashmap<def_id,@DVec<@Impl>>;
@ -133,7 +133,7 @@ class CoherenceInfo {
}
}
class CoherenceChecker {
struct CoherenceChecker {
let crate_context: @crate_ctxt;
let inference_context: infer_ctxt;

View File

@ -14,7 +14,7 @@ fn indent<R>(op: fn() -> R) -> R {
return r;
}
class _indenter {
struct _indenter {
let _i: ();
new(_i: ()) { self._i = (); }
drop { debug!{"<<"}; }

View File

@ -111,7 +111,7 @@ mod blade_runner {
* eget ante feugiat tortor congue auctor ac quis ante. Proin
* condimentum lacinia tincidunt.
*/
class bored {
struct bored {
let bored: bool;
new(bored: bool) { self.bored = bored; }
drop { log(error, self.bored); }

View File

@ -1,6 +1,6 @@
mod kitties {
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,6 +1,6 @@
mod kitties {
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,6 +1,6 @@
mod kitties {
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,6 +1,6 @@
mod kitties {
class cat {
struct cat {
priv {
let mut meows : uint;
fn meow() {

View File

@ -1,6 +1,6 @@
mod kitties {
class cat {
struct cat {
priv {
let mut meows : uint;
fn nap() { for uint::range(1u, 10000u) |_i|{}}

View File

@ -1,6 +1,6 @@
mod kitties {
class cat<U> {
struct cat<U> {
priv {
let mut info : ~[U];
let mut meows : uint;

View File

@ -3,7 +3,7 @@ import to_str::ToStr;
mod kitty {
class cat : ToStr {
struct cat : ToStr {
priv {
let mut meows : uint;
fn meow() {

View File

@ -7,7 +7,7 @@ use std;
export context;
class arc_destruct<T:const> {
struct arc_destruct<T:const> {
let _data: int;
new(data: int) { self._data = data; }
drop {}
@ -21,7 +21,7 @@ fn init() -> arc_destruct<context_res> unsafe {
arc(context_res())
}
class context_res {
struct context_res {
let ctx : int;
new() { self.ctx = 0; }

View File

@ -5,7 +5,7 @@ mod socket {
export socket_handle;
class socket_handle {
struct socket_handle {
let sockfd: libc::c_int;
new(x: libc::c_int) {self.sockfd = x;}
drop { /* c::close(self.sockfd); */ }

View File

@ -3,7 +3,7 @@ export rsrc;
fn foo(_x: i32) {
}
class rsrc {
struct rsrc {
let x: i32;
new(x: i32) { self.x = x; }
drop { foo(self.x); }

View File

@ -27,7 +27,7 @@ fn port<T: send>() -> port<T> {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
}
class port_ptr<T:send> {
struct port_ptr<T:send> {
let po: *rust_port;
new(po: *rust_port) {
debug!{"in the port_ptr constructor"};

View File

@ -40,7 +40,7 @@ enum st {
})
}
class r {
struct r {
let _l: @nillist;
new(l: @nillist) { self._l = l; }
drop {}

View File

@ -104,7 +104,7 @@ fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
io::println(fmt!{"%s\t%?", word, count});
}
class box<T> {
struct box<T> {
let mut contents: option<T>;
new(+x: T) { self.contents = some(x); }
@ -350,7 +350,7 @@ fn is_word_char(c: char) -> bool {
char::is_alphabetic(c) || char::is_digit(c) || c == '_'
}
class random_word_reader: word_reader {
struct random_word_reader: word_reader {
let mut remaining: uint;
let rng: rand::Rng;
new(count: uint) {

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,6 +1,6 @@
// error-pattern:mismatched types: expected `()` but found `bool`
class r {
struct r {
new() {}
drop { true }
}

View File

@ -1,4 +1,4 @@
class noncopyable {
struct noncopyable {
i: (); new() { self.i = (); } drop { #error["dropped"]; }
}
enum wrapper = noncopyable;

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class foo { let x: int; new(x: int) { self.x = x; } drop { } }
struct foo { let x: int; new(x: int) { self.x = x; } drop { } }
fn to_lambda2(b: foo) -> fn@(uint) -> uint {
// test case where copy clause specifies a value that is not used

View File

@ -3,7 +3,7 @@ trait noisy {
fn speak();
}
class cat : noisy {
struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {

View File

@ -1,4 +1,4 @@
class cat : int { //~ ERROR trait
struct cat : int { //~ ERROR trait
let meows: uint;
new(in_x : uint) { self.meows = in_x; }
}

View File

@ -3,7 +3,7 @@ trait animal {
fn eat();
}
class cat : animal {
struct cat : animal {
let meows: uint;
new(in_x : uint) { self.meows = in_x; }
}

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
priv {
let mut meows : uint;
fn sleep() { loop{} }

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class foo {
struct foo {
let i: int;
new(i:int) { self.i = i; }
drop {}

View File

@ -1,7 +1,7 @@
// test that autoderef of a type like this does not
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
class t { //~ ERROR this type cannot be instantiated
struct t { //~ ERROR this type cannot be instantiated
let x: x;
let to_str: ();
new(x: x) { self.x = x; self.to_str = (); }

View File

@ -1,5 +1,5 @@
// error-pattern: type cat cannot be dereferenced
class cat { new() {} }
struct cat { new() {} }
fn main() {
let kitty : cat = cat();

View File

@ -1,5 +1,5 @@
// error-pattern: type cat cannot be dereferenced
class cat { new() {} }
struct cat { new() {} }
fn main() {
let nyan = cat();

View File

@ -1,4 +1,4 @@
class socket {
struct socket {
let sock: int;
new() { self.sock = 1; }

View File

@ -1,4 +1,4 @@
class c { //~ ERROR a struct must have at least one field
struct c { //~ ERROR a struct must have at least one field
new() { }
}

View File

@ -1,4 +1,4 @@
class send_packet<T: copy> {
struct send_packet<T: copy> {
let p: T;
new(p: T) { self.p = p; }
}

View File

@ -1,4 +1,4 @@
class example {
struct example {
let x: int;
new() {
self.x = 1;

View File

@ -1,4 +1,4 @@
class example {
struct example {
let x: int;
new() { //~ ERROR First constructor declared here
self.x = 1;

View File

@ -2,7 +2,7 @@ use std;
fn siphash(k0 : u64) {
class siphash {
struct siphash {
let mut v0: u64;
fn reset() {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture

View File

@ -1,5 +1,5 @@
#[forbid(non_camel_case_types)]
class foo { //~ ERROR type, variant, or trait must be camel case
struct foo { //~ ERROR type, variant, or trait must be camel case
let bar: int;
new() {

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
let how_hungry : int;
fn meow() {}
new() {

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
let how_hungry : int;
new() {} //~ ERROR field `self.how_hungry` is never initialized
}

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
let mut a: int;
let mut b: int;
let mut c: int;

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -35,7 +35,7 @@ fn f4() {
}
// leave this in here just to trigger compile-fail:
class r {
struct r {
let x: ();
new() { self.x = (); }
drop {}

View File

@ -1,5 +1,5 @@
// error-pattern:assigning to immutable field
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,5 +1,5 @@
// error-pattern:assigning to immutable field
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,5 +1,5 @@
fn main() {
class foo {
struct foo {
let _x: comm::Port<()>;
new(x: comm::Port<()>) { self._x = x; }
drop {}

View File

@ -2,13 +2,13 @@
fn foo<T: const>(_x: T) { }
class r {
struct r {
let x:int;
new(x:int) { self.x = x; }
drop {}
}
class r2 {
struct r2 {
let x:@mut int;
new(x:@mut int) { self.x = x; }
drop {}

View File

@ -2,13 +2,13 @@
// Test that a class with a non-copyable field can't be
// copied
class bar {
struct bar {
let x: int;
new(x:int) {self.x = x;}
drop {}
}
class foo {
struct foo {
let i: int;
let j: bar;
new(i:int) { self.i = i; self.j = bar(5); }

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class r {
struct r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }

View File

@ -1,5 +1,5 @@
// error-pattern:no public field or method with that name
class cat {
struct cat {
priv {
let mut meows : uint;
}

View File

@ -1,5 +1,5 @@
// error-pattern:call to private method not allowed
class cat {
struct cat {
priv {
let mut meows : uint;
fn nap() { uint::range(1u, 10000u, |_i|{})}

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class my_resource {
struct my_resource {
let x: int;
new(x: int) { self.x = x; }
drop { log(error, self.x); }

View File

@ -1,4 +1,4 @@
class dog {
struct dog {
let mut cats_chased: uint;
new() {

View File

@ -1,4 +1,4 @@
class dog {
struct dog {
let mut food: uint;
new() {

View File

@ -4,7 +4,7 @@
enum an_enum = &int;
trait a_trait { fn foo() -> &self/int; }
class a_class { let x:&self/int; new(x:&self/int) { self.x = x; } }
struct a_class { let x:&self/int; new(x:&self/int) { self.x = x; } }
fn a_fn1(e: an_enum/&a) -> an_enum/&b {
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`

View File

@ -1,16 +1,16 @@
class yes0 {
struct yes0 {
let x: &uint;
new(x: &uint) { self.x = x; }
drop {}
}
class yes1 {
struct yes1 {
let x: &self/uint;
new(x: &self/uint) { self.x = x; }
drop {}
}
class yes2 {
struct yes2 {
let x: &foo/uint; //~ ERROR named regions other than `self` are not allowed as part of a type declaration
new(x: &foo/uint) { self.x = x; } //~ ERROR named regions other than `self` are not allowed as part of a type declaration
drop {}

View File

@ -1,4 +1,4 @@
class box_impl<T> {
struct box_impl<T> {
let mut f: T;
new(f: T) {

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class r {
struct r {
let b:bool;
new(b: bool) { self.b = b; }
drop {}

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class r {
struct r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }

View File

@ -1,7 +1,7 @@
// Test that a class with an unsendable field can't be
// sent
class foo {
struct foo {
let i: int;
let j: @~str;
new(i:int, j: @~str) { self.i = i; self.j = j; }

View File

@ -1,6 +1,6 @@
// error-pattern: copying a noncopyable value
class r {
struct r {
let i:int;
new(i:int) {self.i = i;}
drop {}

View File

@ -20,7 +20,7 @@ fn getbig_call_c_and_fail(i: int) {
}
}
class and_then_get_big_again {
struct and_then_get_big_again {
let x:int;
new(x:int) {self.x = x;}
drop {

View File

@ -13,7 +13,7 @@ fn getbig_and_fail(&&i: int) {
}
}
class and_then_get_big_again {
struct and_then_get_big_again {
let x:int;
new(x:int) {self.x = x;}
drop {

View File

@ -13,7 +13,7 @@ fn getbig_and_fail(&&i: int) {
}
}
class and_then_get_big_again {
struct and_then_get_big_again {
let x:int;
new(x:int) {self.x = x;}
drop {}

View File

@ -1,6 +1,6 @@
// error-pattern:whatever
class r {
struct r {
let x:int;
// Setting the exit status after the runtime has already
// failed has no effect and the process exits with the

View File

@ -4,7 +4,7 @@ fn failfn() {
fail;
}
class r {
struct r {
let v: *int;
new(v: *int) { self.v = v; }
drop unsafe {

View File

@ -125,7 +125,7 @@ fn test_foreign_fn() {
assert test::rust_get_sched_id == test::rust_get_sched_id;
}
class p {
struct p {
let mut x: int;
let mut y: int;
new(x: int, y: int) { self.x = x; self.y = y; }

View File

@ -7,7 +7,7 @@ type Tree<T> = {
fn empty<T>() -> Tree<T> { fail }
class Box {
struct Box {
let tree: Tree<@Box>;
new() {

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
let name: ~str;
#[cat_maker]
/**

View File

@ -2,7 +2,7 @@ trait noisy {
fn speak() -> int;
}
class dog : noisy {
struct dog : noisy {
priv {
let barks : @mut uint;
fn bark() -> int {
@ -26,7 +26,7 @@ class dog : noisy {
fn speak() -> int { self.bark() }
}
class cat : noisy {
struct cat : noisy {
priv {
let meows : @mut uint;
fn meow() -> uint {

View File

@ -2,7 +2,7 @@ trait noisy {
fn speak();
}
class cat : noisy {
struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {

View File

@ -1,4 +1,4 @@
class cat {
struct cat {
let done : extern fn(uint);
let meows : uint;
new(done: extern fn(uint)) {

View File

@ -5,7 +5,7 @@ import kitty::*;
mod kitty {
export cat;
class cat {
struct cat {
let meows: uint;
let name: ~str;

View File

@ -7,7 +7,7 @@ enum cat_type { tuxedo, tabby, tortoiseshell }
// for any int value that's less than the meows field
// ok: T should be in scope when resolving the trait ref for map
class cat<T: copy> : map<int, T> {
struct cat<T: copy> : map<int, T> {
priv {
// Yes, you can have negative meows
let mut meows : int;

View File

@ -3,7 +3,7 @@
use cci_class_trait;
import cci_class_trait::animals::*;
class cat : noisy {
struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {

View File

@ -2,7 +2,7 @@ trait noisy {
fn speak();
}
class cat : noisy {
struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {

Some files were not shown because too many files have changed in this diff Show More