~~~~~~~~ {.keyword}
again assert
break
-check class const copy
+check const copy
drop
else enum export extern
fail false fn for
match mod mut
pure
return
+struct
true trait type
unchecked unsafe
while
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
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
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
### 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:
~~~~~~
`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
`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,
f(po.chan())
}
-class PortPtr<T:send> {
+struct PortPtr<T:send> {
let po: *rust_port;
new(po: *rust_port) { self.po = po; }
drop unsafe {
*/
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 {
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); }
}
}
-class FdRes {
+struct FdRes {
let fd: fd_t;
new(fd: fd_t) { self.fd = fd; }
drop { libc::close(self.fd); }
// 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 {
#[test]
fn test_unwrap_resource() {
- class r {
+ struct r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) += 1; }
let _unweaken = Unweaken(ch);
f(po);
- class Unweaken {
+ struct Unweaken {
let ch: comm::Chan<()>;
new(ch: comm::Chan<()>) { self.ch = ch; }
drop unsafe {
}
-class RandRes {
+struct RandRes {
let c: *rctx;
new(c: *rctx) { self.c = c; }
drop { rustrt::rand_free(self.c); }
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); }
type Word = uint;
-class Frame {
+struct Frame {
let fp: *Word;
new(fp: *Word) {
* ~~~
*/
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); }
/// 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); }
* 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 {
}
// 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.
}
}
-class AutoNotify {
+struct AutoNotify {
let notify_chan: comm::Chan<Notification>;
let mut failed: bool;
new(chan: comm::Chan<Notification>) {
data: T
};
-class ArcDestruct<T> {
+struct ArcDestruct<T> {
let data: *libc::c_void;
new(data: *libc::c_void) { self.data = data; }
drop unsafe {
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();
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); }
}
/// A non-copyable dummy type.
-class NonCopyable {
+struct NonCopyable {
i: ();
new() { self.i = (); }
drop { }
export eq_vec;
export methods;
-class small_bitv {
+struct small_bitv {
let mut bits: u32;
new(bits: u32) { self.bits = bits; }
priv {
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]) {
enum op {union, intersect, assign, difference}
// The bitvector type
-class bitv {
+struct bitv {
let rep: a_bitv;
let nbits: uint;
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 {
* 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 {
* 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; }
}
@protocol_(name, span)
}
-class protocol_ {
+struct protocol_ {
let name: ident;
let span: span;
let states: DVec<state>;
/* ident is handled by common.rs */
-class parser {
+struct parser {
let sess: parse_sess;
let cfg: crate_cfg;
let file_type: file_type;
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,
let keys = ~[
~"again", ~"assert",
~"break",
- ~"check", ~"class", ~"const", ~"copy",
+ ~"check", ~"const", ~"copy",
~"do", ~"drop",
~"else", ~"enum", ~"export", ~"extern",
~"fail", ~"false", ~"fn", ~"for",
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); }
/* 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); }
/* 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); }
/* 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); }
/* 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); }
}
// 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.
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>;
}
}
-class LanguageItemCollector {
+struct LanguageItemCollector {
let items: &LanguageItems;
let crate: @crate;
}
}
-class ir_maps {
+struct ir_maps {
let tcx: ty::ctxt;
let method_map: typeck::method_map;
let last_use_map: last_use_map;
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;
return n;
}
-class AtomTable {
+struct AtomTable {
let atoms: hashmap<@~str,Atom>;
let strings: DVec<@~str>;
let mut atom_count: uint;
}
/// One local scope.
-class Rib {
+struct Rib {
let bindings: hashmap<Atom,def_like>;
let kind: RibKind;
}
/// One import directive.
-class ImportDirective {
+struct ImportDirective {
let module_path: @DVec<Atom>;
let subclass: @ImportDirectiveSubclass;
let span: span;
}
/// The item that an import resolves to.
-class Target {
+struct Target {
let target_module: @Module;
let bindings: @NameBindings;
}
}
-class ImportResolution {
+struct ImportResolution {
let span: span;
// The number of outstanding references to this name. When this reaches
}
/// One node in the tree of modules.
-class Module {
+struct Module {
let parent_link: ParentLink;
let mut def_id: option<def_id>;
// 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.
}
/// Interns the names of the primitive types.
-class PrimitiveTypeTable {
+struct PrimitiveTypeTable {
let primitive_types: hashmap<Atom,prim_ty>;
new(atom_table: @AtomTable) {
}
/// The main resolver class.
-class Resolver {
+struct Resolver {
let session: session;
let lang_items: LanguageItems;
let crate: @crate;
}
}
-class icx_popper {
+struct icx_popper {
let ccx: @crate_ctxt;
new(ccx: @crate_ctxt) { self.ccx = ccx; }
drop {
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); }
// 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
}
}
-class lookup {
+struct lookup {
let fcx: @fn_ctxt;
let expr: @ast::expr;
let self_expr: @ast::expr;
}
}
-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>>;
}
}
-class CoherenceChecker {
+struct CoherenceChecker {
let crate_context: @crate_ctxt;
let inference_context: infer_ctxt;
return r;
}
-class _indenter {
+struct _indenter {
let _i: ();
new(_i: ()) { self._i = (); }
drop { debug!{"<<"}; }
* 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); }
mod kitties {
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
mod kitties {
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
mod kitties {
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
mod kitties {
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn meow() {
mod kitties {
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn nap() { for uint::range(1u, 10000u) |_i|{}}
mod kitties {
-class cat<U> {
+struct cat<U> {
priv {
let mut info : ~[U];
let mut meows : uint;
mod kitty {
-class cat : ToStr {
+struct cat : ToStr {
priv {
let mut meows : uint;
fn meow() {
export context;
-class arc_destruct<T:const> {
+struct arc_destruct<T:const> {
let _data: int;
new(data: int) { self._data = data; }
drop {}
arc(context_res())
}
-class context_res {
+struct context_res {
let ctx : int;
new() { self.ctx = 0; }
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); */ }
fn foo(_x: i32) {
}
-class rsrc {
+struct rsrc {
let x: i32;
new(x: i32) { self.x = x; }
drop { foo(self.x); }
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"};
})
}
-class r {
+struct r {
let _l: @nillist;
new(l: @nillist) { self._l = l; }
drop {}
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); }
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) {
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
// error-pattern:mismatched types: expected `()` but found `bool`
-class r {
+struct r {
new() {}
drop { true }
}
-class noncopyable {
+struct noncopyable {
i: (); new() { self.i = (); } drop { #error["dropped"]; }
}
enum wrapper = noncopyable;
// 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
fn speak();
}
-class cat : noisy {
+struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {
-class cat : int { //~ ERROR trait
+struct cat : int { //~ ERROR trait
let meows: uint;
new(in_x : uint) { self.meows = in_x; }
}
fn eat();
}
-class cat : animal {
+struct cat : animal {
let meows: uint;
new(in_x : uint) { self.meows = in_x; }
}
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn sleep() { loop{} }
// error-pattern: copying a noncopyable value
-class foo {
+struct foo {
let i: int;
new(i:int) { self.i = i; }
drop {}
// 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 = (); }
// error-pattern: type cat cannot be dereferenced
-class cat { new() {} }
+struct cat { new() {} }
fn main() {
let kitty : cat = cat();
// error-pattern: type cat cannot be dereferenced
-class cat { new() {} }
+struct cat { new() {} }
fn main() {
let nyan = cat();
-class socket {
+struct socket {
let sock: int;
new() { self.sock = 1; }
-class c { //~ ERROR a struct must have at least one field
+struct c { //~ ERROR a struct must have at least one field
new() { }
}
-class send_packet<T: copy> {
+struct send_packet<T: copy> {
let p: T;
new(p: T) { self.p = p; }
}
-class example {
+struct example {
let x: int;
new() {
self.x = 1;
-class example {
+struct example {
let x: int;
new() { //~ ERROR First constructor declared here
self.x = 1;
fn siphash(k0 : u64) {
- class siphash {
+ struct siphash {
let mut v0: u64;
fn reset() {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
#[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() {
-class cat {
+struct cat {
let how_hungry : int;
fn meow() {}
new() {
-class cat {
+struct cat {
let how_hungry : int;
new() {} //~ ERROR field `self.how_hungry` is never initialized
}
-class cat {
+struct cat {
let mut a: int;
let mut b: int;
let mut c: int;
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
}
// leave this in here just to trigger compile-fail:
-class r {
+struct r {
let x: ();
new() { self.x = (); }
drop {}
// error-pattern:assigning to immutable field
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
// error-pattern:assigning to immutable field
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
fn main() {
- class foo {
+ struct foo {
let _x: comm::Port<()>;
new(x: comm::Port<()>) { self._x = x; }
drop {}
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 {}
// 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); }
// 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; }
// error-pattern:no public field or method with that name
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
// error-pattern:call to private method not allowed
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn nap() { uint::range(1u, 10000u, |_i|{})}
// 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); }
-class dog {
+struct dog {
let mut cats_chased: uint;
new() {
-class dog {
+struct dog {
let mut food: uint;
new() {
enum an_enum = ∫
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`
-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 {}
-class box_impl<T> {
+struct box_impl<T> {
let mut f: T;
new(f: T) {
// error-pattern: copying a noncopyable value
-class r {
+struct r {
let b:bool;
new(b: bool) { self.b = b; }
drop {}
// 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; }
// 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; }
// error-pattern: copying a noncopyable value
-class r {
+struct r {
let i:int;
new(i:int) {self.i = i;}
drop {}
}
}
-class and_then_get_big_again {
+struct and_then_get_big_again {
let x:int;
new(x:int) {self.x = x;}
drop {
}
}
-class and_then_get_big_again {
+struct and_then_get_big_again {
let x:int;
new(x:int) {self.x = x;}
drop {
}
}
-class and_then_get_big_again {
+struct and_then_get_big_again {
let x:int;
new(x:int) {self.x = x;}
drop {}
// 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
fail;
}
-class r {
+struct r {
let v: *int;
new(v: *int) { self.v = v; }
drop unsafe {
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; }
fn empty<T>() -> Tree<T> { fail }
-class Box {
+struct Box {
let tree: Tree<@Box>;
new() {
-class cat {
+struct cat {
let name: ~str;
#[cat_maker]
/**
fn speak() -> int;
}
-class dog : noisy {
+struct dog : noisy {
priv {
let barks : @mut uint;
fn bark() -> int {
fn speak() -> int { self.bark() }
}
-class cat : noisy {
+struct cat : noisy {
priv {
let meows : @mut uint;
fn meow() -> uint {
fn speak();
}
-class cat : noisy {
+struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {
-class cat {
+struct cat {
let done : extern fn(uint);
let meows : uint;
new(done: extern fn(uint)) {
mod kitty {
export cat;
- class cat {
+ struct cat {
let meows: uint;
let name: ~str;
// 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;
use cci_class_trait;
import cci_class_trait::animals::*;
-class cat : noisy {
+struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {
fn speak();
}
-class cat : noisy {
+struct cat : noisy {
priv {
let mut meows : uint;
fn meow() {
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
-class cat<U> {
+struct cat<U> {
priv {
let mut info : ~[U];
let mut meows : uint;
import to_str::*;
import to_str::ToStr;
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn meow() {
-class cat {
+struct cat {
let name : ~str;
-class cat<U> {
+struct cat<U> {
priv {
let mut meows : uint;
}
-class kitten {
+struct kitten {
let cat: option<cat>;
new(cat: option<cat>) {
self.cat = cat;
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn meow() {
enum tg { bar, }
#[cfg(bogus)]
-class r {
+struct r {
let i: int;
new(i:int) { self.i = i; }
}
-class r {
+struct r {
let i: int;
new(i:int) { self.i = i; }
}
// Resources can't be copied, but storing into data structures counts
// as a move unless the stored thing is used afterwards.
-class r {
+struct r {
let i: @mut int;
new(i: @mut int) {
self.i = i;
trait clam<A: copy> {
fn chowder(y: A);
}
-class foo<A: copy> : clam<A> {
+struct foo<A: copy> : clam<A> {
let x: A;
new(b: A) { self.x = b; }
fn chowder(y: A) {
trait clam<A: copy> { }
-class foo<A: copy> {
+struct foo<A: copy> {
let x: A;
new(b: A) { self.x = b; }
fn bar<B,C:clam<A>>(c: C) -> B {
-class c1<T: copy> {
+struct c1<T: copy> {
let x: T;
new(x: T) {self.x = x;}
import dvec::dvec;
-class c1<T: copy> {
+struct c1<T: copy> {
let x: T;
new(x: T) {self.x = x;}
-class socket {
+struct socket {
let sock: int;
new() { self.sock = 1; }
-class font {
+struct font {
let fontbuf: &self/~[u8];
new(fontbuf: &self/~[u8]) {
-class C {
+struct C {
let x: uint;
new(x: uint) {
-class cat {
+struct cat {
let mut meow: fn@();
new() { self.meow = fn@() { error!{"meow"}; };}
}
-class Font {
+struct Font {
let fontbuf: uint;
let cairo_font: uint;
let font_dtor: uint;
}
}
- class send_packet<T: send> {
+ struct send_packet<T: send> {
let mut p: option<*packet<T>>;
new(p: *packet<T>) { self.p = some(p); }
drop {
}
}
- class recv_packet<T: send> {
+ struct recv_packet<T: send> {
let mut p: option<*packet<T>>;
new(p: *packet<T>) { self.p = some(p); }
drop {
// This test should behave exactly like issue-2735-3
-class defer {
+struct defer {
let b: &mut bool;
new(b: &mut bool) {
self.b = b;
// This test should behave exactly like issue-2735-2
-class defer {
+struct defer {
let b: &mut bool;
new(b: &mut bool) {
self.b = b;
-class CMap {
+struct CMap {
let buf: &[u8];
new(buf: &self/[u8]) {
-class r {
+struct r {
let b: @mut int;
new(b: @mut int) {
self.b = b;
fn main() {
- class b {
+ struct b {
let i: int;
fn do_stuff() -> int { return 37; }
new(i:int) { self.i = i; }
-class cat {
+struct cat {
priv {
let mut meows : uint;
}
-class cat {
+struct cat {
priv {
let mut meows : uint;
fn nap() { for uint::range(1u, 10u) |_i| { }}
-class r {
+struct r {
let i: @mut int;
new(i: @mut int) {
self.i = i;
// Don't leak the unique pointers
-class r {
+struct r {
let v: *int;
new(v: *int) unsafe {
self.v = v;
c: *int
};
-class r {
+struct r {
let v: u;
new(v: u) { self.v = v; }
drop unsafe {
c: *int
};
-class r {
+struct r {
let v: u;
let w: int;
let x: *int;
-class shrinky_pointer {
+struct shrinky_pointer {
let i: @@mut int;
fn look_at() -> int { return **(self.i); }
new(i: @@mut int) { self.i = i; }
-class finish<T: copy> {
+struct finish<T: copy> {
let arg: {val: T, fin: extern fn(T)};
new(arg: {val: T, fin: extern fn(T)}) {
self.arg = arg;
type closable = @mut bool;
-class close_res {
+struct close_res {
let i: closable;
new(i: closable) { self.i = i; }
import task::*;
import comm::*;
-class test {
+struct test {
let f: int;
new(f: int) { self.f = f; }
drop {}
// Test that a class with only sendable fields can be sent
-class foo {
+struct foo {
let i: int;
let j: char;
new(i:int, j: char) { self.i = i; self.j = j; }
use std;
import task;
-class notify {
+struct notify {
let ch: comm::Chan<bool>; let v: @mut bool;
new(ch: comm::Chan<bool>, v: @mut bool) { self.ch = ch; self.v = v; }
drop {
fn s_foo<T: copy>(shared: T) { }
fn u_foo<T: send>(unique: T) { }
-class r {
+struct r {
let i: int;
new(i:int) { self.i = i; }
drop {}
-class r {
+struct r {
let i: @mut int;
new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
import task;
import comm;
-class complainer {
+struct complainer {
let c: comm::Chan<bool>;
new(c: comm::Chan<bool>) {
error!{"Hello!"};
import task;
import comm;
-class complainer {
+struct complainer {
let c: @int;
new(c: @int) { self.c = c; }
drop {}
// Make sure that destructors get run on slice literals
-class foo {
+struct foo {
let x: @mut int;
new(x: @mut int) { self.x = x; }
drop { *self.x += 1; }