@protocol_(name, span)
}
+fn protocol_(name: ~str, span: span) -> protocol_ {
+ protocol_ {
+ name: name,
+ span: span,
+ states: DVec(),
+ bounded: None
+ }
+}
+
struct protocol_ {
let name: ~str;
let span: span;
let mut bounded: Option<bool>;
- new(name: ~str, span: span) {
- self.name = name;
- self.span = span;
- self.states = DVec();
- self.bounded = None;
- }
-
/// Get a state.
fn get_state(name: ~str) -> state {
self.states.find(|i| i.name == name).get()
/* ident is handled by common.rs */
+fn parser(sess: parse_sess, cfg: ast::crate_cfg,
+ +rdr: reader, ftype: file_type) -> parser {
+
+ let tok0 = rdr.next_token();
+ let span0 = tok0.sp;
+ let interner = rdr.interner();
+
+ parser {
+ reader: move rdr,
+ interner: move interner,
+ sess: sess,
+ cfg: cfg,
+ file_type: ftype,
+ token: tok0.tok,
+ span: span0,
+ last_span: span0,
+ buffer: [mut
+ {tok: tok0.tok, sp: span0},
+ {tok: tok0.tok, sp: span0},
+ {tok: tok0.tok, sp: span0},
+ {tok: tok0.tok, sp: span0}
+ ]/4,
+ buffer_start: 0,
+ buffer_end: 0,
+ restriction: UNRESTRICTED,
+ quote_depth: 0u,
+ keywords: token::keyword_table(),
+ restricted_keywords: token::restricted_keyword_table()
+ }
+}
+
struct parser {
let sess: parse_sess;
let cfg: crate_cfg;
let keywords: hashmap<~str, ()>;
let restricted_keywords: hashmap<~str, ()>;
- new(sess: parse_sess, cfg: ast::crate_cfg, +rdr: reader, ftype: file_type)
- {
- self.reader <- rdr;
- self.interner = self.reader.interner();
- let tok0 = self.reader.next_token();
- let span0 = tok0.sp;
- self.sess = sess;
- self.cfg = cfg;
- self.file_type = ftype;
- self.token = tok0.tok;
- self.span = span0;
- self.last_span = span0;
- self.buffer = [mut
- {tok: tok0.tok, sp: span0},
- {tok: tok0.tok, sp: span0},
- {tok: tok0.tok, sp: span0},
- {tok: tok0.tok, sp: span0}
- ]/4;
- self.buffer_start = 0;
- self.buffer_end = 0;
- self.restriction = UNRESTRICTED;
- self.quote_depth = 0u;
- self.keywords = token::keyword_table();
- self.restricted_keywords = token::restricted_keyword_table();
- }
-
drop {} /* do not copy the parser; its state is tied to outside state */
fn bump() {
let class_name = self.parse_value_ident();
self.parse_region_param();
let ty_params = self.parse_ty_params();
- let class_path = self.ident_to_path_tys(class_name, ty_params);
let traits : ~[@trait_ref] = if self.eat(token::COLON)
{ self.parse_trait_ref_list(token::LBRACE) }
else { ~[] };
// It's a record-like struct.
fields = ~[];
while self.token != token::RBRACE {
- match self.parse_class_item(class_path) {
+ match self.parse_class_item() {
ctor_decl(a_fn_decl, attrs, blk, s) => {
match the_ctor {
Some((_, _, _, s_first)) => {
}
}
- fn parse_ctor(attrs: ~[attribute],
- result_ty: ast::ty_) -> class_contents {
- let lo = self.last_span.lo;
- let (decl_, _) = self.parse_fn_decl(|p| p.parse_arg());
- let decl = {output: @{id: self.get_id(),
- node: result_ty, span: decl_.output.span},
- .. decl_};
- let body = self.parse_block();
- ctor_decl(decl, attrs, body, mk_sp(lo, self.last_span.hi))
- }
-
fn parse_dtor(attrs: ~[attribute]) -> class_contents {
let lo = self.last_span.lo;
let body = self.parse_block();
dtor_decl(body, attrs, mk_sp(lo, self.last_span.hi))
}
- fn parse_class_item(class_name_with_tps: @path) -> class_contents {
+ fn parse_class_item() -> class_contents {
if self.eat_keyword(~"priv") {
// XXX: Remove after snapshot.
match self.token {
let attrs = self.parse_outer_attributes();
- if self.eat_keyword(~"new") {
- // result type is always the type of the class
- return self.parse_ctor(attrs, ty_path(class_name_with_tps,
- self.get_id()));
- }
- else if self.eat_keyword(~"drop") {
+ if self.eat_keyword(~"drop") {
return self.parse_dtor(attrs);
}
else {
}
}
- fn parse_struct_def(path: @path) -> @struct_def {
+ fn parse_struct_def() -> @struct_def {
let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
let mut fields: ~[@struct_field] = ~[];
let mut methods: ~[@method] = ~[];
while self.token != token::RBRACE {
- match self.parse_class_item(path) {
+ match self.parse_class_item() {
ctor_decl(*) => {
self.span_fatal(copy self.span,
~"deprecated explicit \
};
}
- fn parse_enum_def(ident: ast::ident, ty_params: ~[ast::ty_param])
+ fn parse_enum_def(ty_params: ~[ast::ty_param])
-> enum_def {
let mut variants: ~[variant] = ~[];
let mut all_nullary = true, have_disr = false;
self.fatal(~"duplicate declaration of shared fields");
}
self.expect(token::LBRACE);
- let path = self.ident_to_path_tys(ident, ty_params);
- common_fields = Some(self.parse_struct_def(path));
+ common_fields = Some(self.parse_struct_def());
again;
}
if self.eat_keyword(~"enum") {
ident = self.parse_ident();
self.expect(token::LBRACE);
- let nested_enum_def = self.parse_enum_def(ident, ty_params);
+ let nested_enum_def = self.parse_enum_def(ty_params);
kind = enum_variant_kind(move nested_enum_def);
needs_comma = false;
} else {
if self.eat(token::LBRACE) {
// Parse a struct variant.
all_nullary = false;
- let path = self.ident_to_path_tys(ident, ty_params);
- kind = struct_variant_kind(self.parse_struct_def(path));
+ kind = struct_variant_kind(self.parse_struct_def());
} else if self.token == token::LPAREN {
all_nullary = false;
let arg_tys = self.parse_unspanned_seq(
}
self.expect(token::LBRACE);
- let enum_definition = self.parse_enum_def(id, ty_params);
+ let enum_definition = self.parse_enum_def(ty_params);
(id, item_enum(enum_definition, ty_params), None)
}
~"if", ~"impl", ~"import",
~"let", ~"log", ~"loop",
~"match", ~"mod", ~"module", ~"move", ~"mut",
- ~"new",
~"owned",
~"pure",
~"ref", ~"return",
struct finally {
let ch: comm::Chan<monitor_msg>;
- new(ch: comm::Chan<monitor_msg>) { self.ch = ch; }
drop { comm::send(self.ch, done); }
}
- let _finally = finally(ch);
+ let _finally = finally { ch: ch };
f(demitter)
} {
struct target_data_res {
let TD: TargetDataRef;
- new(TD: TargetDataRef) { self.TD = TD; }
drop { llvm::LLVMDisposeTargetData(self.TD); }
}
+fn target_data_res(TD: TargetDataRef) -> target_data_res {
+ target_data_res {
+ TD: TD
+ }
+}
+
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
fn mk_target_data(string_rep: ~str) -> target_data {
struct pass_manager_res {
let PM: PassManagerRef;
- new(PM: PassManagerRef) { self.PM = PM; }
drop { llvm::LLVMDisposePassManager(self.PM); }
}
+fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
+ pass_manager_res {
+ PM: PM
+ }
+}
+
type pass_manager = {llpm: PassManagerRef, dtor: @pass_manager_res};
fn mk_pass_manager() -> pass_manager {
struct object_file_res {
let ObjectFile: ObjectFileRef;
- new(ObjectFile: ObjectFileRef) { self.ObjectFile = ObjectFile; }
drop { llvm::LLVMDisposeObjectFile(self.ObjectFile); }
}
+fn object_file_res(ObjectFile: ObjectFileRef) -> object_file_res{
+ object_file_res {
+ ObjectFile: ObjectFile
+ }
+}
+
type object_file = {llof: ObjectFileRef, dtor: @object_file_res};
fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
struct section_iter_res {
let SI: SectionIteratorRef;
- new(SI: SectionIteratorRef) { self.SI = SI; }
drop { llvm::LLVMDisposeSectionIterator(self.SI); }
}
+fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
+ section_iter_res {
+ SI: SI
+ }
+}
+
type section_iter = {llsi: SectionIteratorRef, dtor: @section_iter_res};
fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
let path_string: ~str;
// The definition, implementation, or field that this path corresponds to.
let def_like: def_like;
+}
- new(path_string: ~str, def_like: def_like) {
- self.path_string = path_string;
- self.def_like = def_like;
+fn path_entry(path_string: ~str, def_like: def_like) -> path_entry {
+ path_entry {
+ path_string: path_string,
+ def_like: def_like
}
}
}
}
+fn LanguageItemCollector(crate: @crate, session: session,
+ items: &r/LanguageItems)
+ -> LanguageItemCollector/&r {
+
+ let item_refs = str_hash();
+
+ item_refs.insert(~"const", &mut items.const_trait);
+ item_refs.insert(~"copy", &mut items.copy_trait);
+ item_refs.insert(~"send", &mut items.send_trait);
+ item_refs.insert(~"owned", &mut items.owned_trait);
+
+ item_refs.insert(~"add", &mut items.add_trait);
+ item_refs.insert(~"sub", &mut items.sub_trait);
+ item_refs.insert(~"mul", &mut items.mul_trait);
+ item_refs.insert(~"div", &mut items.div_trait);
+ item_refs.insert(~"modulo", &mut items.modulo_trait);
+ item_refs.insert(~"neg", &mut items.neg_trait);
+ item_refs.insert(~"bitxor", &mut items.bitxor_trait);
+ item_refs.insert(~"bitand", &mut items.bitand_trait);
+ item_refs.insert(~"bitor", &mut items.bitor_trait);
+ item_refs.insert(~"shl", &mut items.shl_trait);
+ item_refs.insert(~"shr", &mut items.shr_trait);
+ item_refs.insert(~"index", &mut items.index_trait);
+
+ item_refs.insert(~"eq", &mut items.eq_trait);
+ item_refs.insert(~"ord", &mut items.ord_trait);
+
+ LanguageItemCollector {
+ crate: crate,
+ session: session,
+ items: items,
+ item_refs: item_refs
+ }
+}
+
struct LanguageItemCollector {
let items: &LanguageItems;
let item_refs: hashmap<~str,&mut Option<def_id>>;
- new(crate: @crate, session: session, items: &self/LanguageItems) {
- self.crate = crate;
- self.session = session;
- self.items = items;
- self.item_refs = str_hash();
-
- self.item_refs.insert(~"const", &mut self.items.const_trait);
- self.item_refs.insert(~"copy", &mut self.items.copy_trait);
- self.item_refs.insert(~"send", &mut self.items.send_trait);
- self.item_refs.insert(~"owned", &mut self.items.owned_trait);
-
- self.item_refs.insert(~"add", &mut self.items.add_trait);
- self.item_refs.insert(~"sub", &mut self.items.sub_trait);
- self.item_refs.insert(~"mul", &mut self.items.mul_trait);
- self.item_refs.insert(~"div", &mut self.items.div_trait);
- self.item_refs.insert(~"modulo", &mut self.items.modulo_trait);
- self.item_refs.insert(~"neg", &mut self.items.neg_trait);
- self.item_refs.insert(~"bitxor", &mut self.items.bitxor_trait);
- self.item_refs.insert(~"bitand", &mut self.items.bitand_trait);
- self.item_refs.insert(~"bitor", &mut self.items.bitor_trait);
- self.item_refs.insert(~"shl", &mut self.items.shl_trait);
- self.item_refs.insert(~"shr", &mut self.items.shr_trait);
- self.item_refs.insert(~"index", &mut self.items.index_trait);
-
- self.item_refs.insert(~"eq", &mut self.items.eq_trait);
- self.item_refs.insert(~"ord", &mut self.items.ord_trait);
- }
-
fn match_and_collect_meta_item(item_def_id: def_id,
meta_item: meta_item) {
struct Rib {
let bindings: hashmap<Atom,def_like>;
let kind: RibKind;
+}
- new(kind: RibKind) {
- self.bindings = atom_hashmap();
- self.kind = kind;
+fn Rib(kind: RibKind) -> Rib {
+ Rib {
+ bindings: atom_hashmap(),
+ kind: kind
}
}
+
/// One import directive.
struct ImportDirective {
let module_path: @DVec<Atom>;
let subclass: @ImportDirectiveSubclass;
let span: span;
+}
- new(module_path: @DVec<Atom>,
- subclass: @ImportDirectiveSubclass,
- span: span) {
-
- self.module_path = module_path;
- self.subclass = subclass;
- self.span = span;
+fn ImportDirective(module_path: @DVec<Atom>,
+ subclass: @ImportDirectiveSubclass,
+ span: span) -> ImportDirective {
+ ImportDirective {
+ module_path: module_path,
+ subclass: subclass,
+ span: span
}
}
struct Target {
let target_module: @Module;
let bindings: @NameBindings;
+}
- new(target_module: @Module, bindings: @NameBindings) {
- self.target_module = target_module;
- self.bindings = bindings;
+fn Target(target_module: @Module, bindings: @NameBindings) -> Target {
+ Target {
+ target_module: target_module,
+ bindings: bindings
}
}
let mut used: bool;
- new(span: span) {
- self.span = span;
-
- self.outstanding_references = 0u;
-
- self.module_target = None;
- self.value_target = None;
- self.type_target = None;
-
- self.used = false;
- }
-
fn target_for_namespace(namespace: Namespace) -> Option<Target> {
match namespace {
ModuleNS => return copy self.module_target,
}
}
+fn ImportResolution(span: span) -> ImportResolution {
+ ImportResolution {
+ span: span,
+ outstanding_references: 0u,
+ module_target: None,
+ value_target: None,
+ type_target: None,
+ used: false
+ }
+}
+
/// The link from a module up to its nearest parent node.
enum ParentLink {
NoParentLink,
// The index of the import we're resolving.
let mut resolved_import_count: uint;
- new(parent_link: ParentLink, def_id: Option<def_id>) {
- self.parent_link = parent_link;
- self.def_id = def_id;
-
- self.children = atom_hashmap();
- self.imports = DVec();
-
- self.anonymous_children = int_hash();
-
- self.exported_names = atom_hashmap();
-
- self.import_resolutions = atom_hashmap();
- self.glob_count = 0u;
- self.resolved_import_count = 0u;
- }
-
fn all_imports_resolved() -> bool {
return self.imports.len() == self.resolved_import_count;
}
}
+fn Module(parent_link: ParentLink, def_id: Option<def_id>) -> Module {
+ Module {
+ parent_link: parent_link,
+ def_id: def_id,
+ children: atom_hashmap(),
+ imports: DVec(),
+ anonymous_children: int_hash(),
+ exported_names: atom_hashmap(),
+ import_resolutions: atom_hashmap(),
+ glob_count: 0u,
+ resolved_import_count: 0u
+ }
+}
+
// XXX: This is a workaround due to is_none in the standard library mistakenly
// requiring a T:copy.
let mut type_span: Option<span>;
let mut value_span: Option<span>;
- new() {
- self.module_def = NoModuleDef;
- self.type_def = None;
- self.value_def = None;
- self.module_span = None;
- self.type_span = None;
- self.value_span = None;
- }
-
/// Creates a new module in this set of name bindings.
fn define_module(parent_link: ParentLink, def_id: Option<def_id>,
sp: span) {
}
}
+fn NameBindings() -> NameBindings {
+ NameBindings {
+ module_def: NoModuleDef,
+ type_def: None,
+ value_def: None,
+ module_span: None,
+ type_span: None,
+ value_span: None
+ }
+}
+
+
/// Interns the names of the primitive types.
struct PrimitiveTypeTable {
let primitive_types: hashmap<Atom,prim_ty>;
- new(intr: ident_interner) {
- self.primitive_types = atom_hashmap();
-
- self.intern(intr, @~"bool", ty_bool);
- self.intern(intr, @~"char", ty_int(ty_char));
- self.intern(intr, @~"float", ty_float(ty_f));
- self.intern(intr, @~"f32", ty_float(ty_f32));
- self.intern(intr, @~"f64", ty_float(ty_f64));
- self.intern(intr, @~"int", ty_int(ty_i));
- self.intern(intr, @~"i8", ty_int(ty_i8));
- self.intern(intr, @~"i16", ty_int(ty_i16));
- self.intern(intr, @~"i32", ty_int(ty_i32));
- self.intern(intr, @~"i64", ty_int(ty_i64));
- self.intern(intr, @~"str", ty_str);
- self.intern(intr, @~"uint", ty_uint(ty_u));
- self.intern(intr, @~"u8", ty_uint(ty_u8));
- self.intern(intr, @~"u16", ty_uint(ty_u16));
- self.intern(intr, @~"u32", ty_uint(ty_u32));
- self.intern(intr, @~"u64", ty_uint(ty_u64));
- }
-
fn intern(intr: ident_interner, string: @~str,
primitive_type: prim_ty) {
let atom = intr.intern(string);
}
}
+fn PrimitiveTypeTable(intr: ident_interner) -> PrimitiveTypeTable {
+ let table = PrimitiveTypeTable {
+ primitive_types: atom_hashmap()
+ };
+
+ table.intern(intr, @~"bool", ty_bool);
+ table.intern(intr, @~"char", ty_int(ty_char));
+ table.intern(intr, @~"float", ty_float(ty_f));
+ table.intern(intr, @~"f32", ty_float(ty_f32));
+ table.intern(intr, @~"f64", ty_float(ty_f64));
+ table.intern(intr, @~"int", ty_int(ty_i));
+ table.intern(intr, @~"i8", ty_int(ty_i8));
+ table.intern(intr, @~"i16", ty_int(ty_i16));
+ table.intern(intr, @~"i32", ty_int(ty_i32));
+ table.intern(intr, @~"i64", ty_int(ty_i64));
+ table.intern(intr, @~"str", ty_str);
+ table.intern(intr, @~"uint", ty_uint(ty_u));
+ table.intern(intr, @~"u8", ty_uint(ty_u8));
+ table.intern(intr, @~"u16", ty_uint(ty_u16));
+ table.intern(intr, @~"u32", ty_uint(ty_u32));
+ table.intern(intr, @~"u64", ty_uint(ty_u64));
+
+ return table;
+}
+
+
fn namespace_to_str(ns: Namespace) -> ~str {
match ns {
TypeNS => ~"type",
}
}
+fn Resolver(session: session, lang_items: LanguageItems,
+ crate: @crate) -> Resolver {
+
+ let graph_root = @NameBindings();
+
+ (*graph_root).define_module(NoParentLink,
+ Some({ crate: 0, node: 0 }),
+ crate.span);
+
+ let current_module = (*graph_root).get_module();
+
+ let self = Resolver {
+ session: session,
+ lang_items: copy lang_items,
+ crate: crate,
+
+ // The outermost module has def ID 0; this is not reflected in the
+ // AST.
+
+ graph_root: graph_root,
+
+ unused_import_lint_level: unused_import_lint_level(session),
+
+ trait_info: new_def_hash(),
+ structs: new_def_hash(),
+
+ unresolved_imports: 0u,
+
+ current_module: current_module,
+ value_ribs: @DVec(),
+ type_ribs: @DVec(),
+ label_ribs: @DVec(),
+
+ xray_context: NoXray,
+ current_trait_refs: None,
+
+ self_atom: syntax::parse::token::special_idents::self_,
+ primitive_type_table: @PrimitiveTypeTable(session.
+ parse_sess.interner),
+
+ namespaces: ~[ ModuleNS, TypeNS, ValueNS ],
+
+ def_map: int_hash(),
+ export_map: int_hash(),
+ export_map2: int_hash(),
+ trait_map: @int_hash(),
+
+ intr: session.intr()
+ };
+
+ return self;
+}
+
/// The main resolver class.
struct Resolver {
let session: session;
let export_map2: ExportMap2;
let trait_map: TraitMap;
- new(session: session, lang_items: LanguageItems, crate: @crate) {
- self.session = session;
- self.lang_items = copy lang_items;
- self.crate = crate;
-
- // The outermost module has def ID 0; this is not reflected in the
- // AST.
-
- self.graph_root = @NameBindings();
- (*self.graph_root).define_module(NoParentLink,
- Some({ crate: 0, node: 0 }),
- crate.span);
-
- self.unused_import_lint_level = unused_import_lint_level(session);
-
- self.trait_info = new_def_hash();
- self.structs = new_def_hash();
-
- self.unresolved_imports = 0u;
-
- self.current_module = (*self.graph_root).get_module();
- self.value_ribs = @DVec();
- self.type_ribs = @DVec();
- self.label_ribs = @DVec();
-
- self.xray_context = NoXray;
- self.current_trait_refs = None;
-
- self.self_atom = syntax::parse::token::special_idents::self_;
- self.primitive_type_table = @PrimitiveTypeTable(self.session.
- parse_sess.interner);
-
- self.namespaces = ~[ ModuleNS, TypeNS, ValueNS ];
-
- self.def_map = int_hash();
- self.export_map = int_hash();
- self.export_map2 = int_hash();
- self.trait_map = @int_hash();
-
- self.intr = session.intr();
- }
-
/// The main name resolution procedure.
fn resolve(@self, this: @Resolver) {
self.build_reduced_graph(this);
struct icx_popper {
let ccx: @crate_ctxt;
- new(ccx: @crate_ctxt) { self.ccx = ccx; }
drop {
if self.ccx.sess.count_llvm_insns() {
vec::pop(*(self.ccx.stats.llvm_insn_ctxt));
}
}
+fn icx_popper(ccx: @crate_ctxt) -> icx_popper {
+ icx_popper {
+ ccx: ccx
+ }
+}
+
trait get_insn_ctxt {
fn insn_ctxt(s: &str) -> icx_popper;
}
struct BuilderRef_res {
let B: BuilderRef;
- new(B: BuilderRef) { self.B = B; }
drop { llvm::LLVMDisposeBuilder(self.B); }
}
+fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
+ BuilderRef_res {
+ B: B
+ }
+}
+
// Crate context. Every crate we compile has one of these.
type crate_ctxt = {
sess: session::session,
// The function context for the function to which this block is
// attached.
let fcx: fn_ctxt;
- new(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind,
- is_lpad: bool, node_info: Option<node_info>, fcx: fn_ctxt) {
- // sigh
- self.llbb = llbb; self.terminated = false; self.unreachable = false;
- self.parent = parent; self.kind = kind; self.is_lpad = is_lpad;
- self.node_info = node_info; self.fcx = fcx;
+}
+
+fn block_(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind,
+ is_lpad: bool, node_info: Option<node_info>, fcx: fn_ctxt)
+ -> block_ {
+
+ block_ {
+ llbb: llbb,
+ terminated: false,
+ unreachable: false,
+ parent: parent,
+ kind: kind,
+ is_lpad: is_lpad,
+ node_info: node_info,
+ fcx: fcx
}
}
}
}
+fn lookup(fcx: @fn_ctxt,
+
+ // In a call `a.b::<X, Y, ...>(...)`:
+ expr: @ast::expr, // The expression `a.b`.
+ self_expr: @ast::expr, // The expression `a`.
+ borrow_lb: ast::node_id, // Scope to borrow the expression `a` for.
+ node_id: ast::node_id, // The node_id in which to store the type of
+ // `a.b`.
+ m_name: ast::ident, // The ident `b`.
+ self_ty: ty::t, // The type of `a`.
+ supplied_tps: ~[ty::t], // The list of types X, Y, ... .
+ include_private: bool) -> lookup {
+
+ lookup {
+ fcx: fcx,
+ expr: expr,
+ self_expr: self_expr,
+ borrow_lb: borrow_lb,
+ node_id: node_id,
+ m_name: m_name,
+ self_ty: self_ty,
+ derefs: 0u,
+ candidates: DVec(),
+ candidate_impls: new_def_hash(),
+ supplied_tps: supplied_tps,
+ include_private: include_private
+ }
+}
+
struct lookup {
let fcx: @fn_ctxt;
let expr: @ast::expr;
let supplied_tps: ~[ty::t];
let include_private: bool;
- new(fcx: @fn_ctxt,
-
- // In a call `a.b::<X, Y, ...>(...)`:
- expr: @ast::expr, // The expression `a.b`.
- self_expr: @ast::expr, // The expression `a`.
- borrow_lb: ast::node_id, // Scope to borrow the expression `a` for.
- node_id: ast::node_id, // The node_id in which to store the type of
- // `a.b`.
- m_name: ast::ident, // The ident `b`.
- self_ty: ty::t, // The type of `a`.
- supplied_tps: ~[ty::t], // The list of types X, Y, ... .
- include_private: bool) {
-
- self.fcx = fcx;
- self.expr = expr;
- self.self_expr = self_expr;
- self.borrow_lb = borrow_lb;
- self.node_id = node_id;
- self.m_name = m_name;
- self.self_ty = self_ty;
- self.derefs = 0u;
- self.candidates = DVec();
- self.candidate_impls = new_def_hash();
- self.supplied_tps = supplied_tps;
- self.include_private = include_private;
- }
-
// Entrypoint:
fn method() -> Option<method_map_entry> {
debug!("method lookup(m_name=%s, self_ty=%s, %?)",
// Contains implementations of methods associated with a trait. For these,
// the associated trait must be imported at the call site.
let extension_methods: hashmap<def_id,@DVec<@Impl>>;
+}
+
+fn CoherenceInfo() -> CoherenceInfo {
+ CoherenceInfo {
+ inherent_methods: new_def_hash(),
+ extension_methods: new_def_hash()
+ }
+}
- new() {
- self.inherent_methods = new_def_hash();
- self.extension_methods = new_def_hash();
+fn CoherenceChecker(crate_context: @crate_ctxt) -> CoherenceChecker {
+ CoherenceChecker {
+ crate_context: crate_context,
+ inference_context: new_infer_ctxt(crate_context.tcx),
+
+ base_type_def_ids: new_def_hash(),
+ privileged_implementations: int_hash()
}
}
let privileged_implementations: hashmap<node_id,()>;
- new(crate_context: @crate_ctxt) {
- self.crate_context = crate_context;
- self.inference_context = new_infer_ctxt(crate_context.tcx);
-
- self.base_type_def_ids = new_def_hash();
- self.privileged_implementations = int_hash();
- }
-
// Create a mapping containing a MethodInfo for every provided
// method in every trait.
fn build_provided_methods_map(crate: @crate) {
struct _indenter {
let _i: ();
- new(_i: ()) { self._i = (); }
drop { debug!("<<"); }
}
+fn _indenter(_i: ()) -> _indenter {
+ _indenter {
+ _i: ()
+ }
+}
+
fn indenter() -> _indenter {
debug!(">>");
_indenter(())
*/
struct bored {
let bored: bool;
- new(bored: bool) { self.bored = bored; }
drop { log(error, self.bored); }
}
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
}
+ fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
+ }
+
}
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
-
fn speak() {}
}
+ fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
+ }
+
}
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
-
fn speak() { self.meows += 1u; }
fn meow_count() -> uint { self.meows }
}
+ fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
+ }
+
+
}
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+ }
+
}
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
}
+ fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
+ }
+
}
\ No newline at end of file
let how_hungry : int;
- new(in_x : uint, in_y : int, -in_info: ~[U])
- { self.meows = in_x; self.how_hungry = in_y;
- self.info <- in_info; }
-
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 {
+ meows: in_x,
+ how_hungry: in_y,
+ info: in_info
+ }
+}
+
+
}
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
fn to_str() -> ~str { self.name }
}
+
+fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
}
+
+}
+
+
struct arc_destruct<T:const> {
let _data: int;
- new(data: int) { self._data = data; }
drop {}
}
+fn arc_destruct<T: const>(data: int) -> arc_destruct<T> {
+ arc_destruct {
+ _data: data
+ }
+}
+
fn arc<T: const>(_data: T) -> arc_destruct<T> {
arc_destruct(0)
}
struct context_res {
let ctx : int;
- new() { self.ctx = 0; }
-
drop { }
}
+fn context_res() -> context_res {
+ context_res {
+ ctx: 0
+ }
+}
+
type context = arc_destruct<context_res>;
impl context {
struct socket_handle {
let sockfd: libc::c_int;
- new(x: libc::c_int) {self.sockfd = x;}
drop { /* c::close(self.sockfd); */ }
}
+
+ fn socket_handle(x: libc::c_int) -> socket_handle {
+ socket_handle {
+ sockfd: x
+ }
+ }
+
}
struct rsrc {
let x: i32;
- new(x: i32) { self.x = x; }
drop { foo(self.x); }
+}
+
+fn rsrc(x: i32) -> rsrc {
+ rsrc {
+ x: x
+ }
}
\ No newline at end of file
struct port_ptr<T:send> {
let po: *rust_port;
- new(po: *rust_port) {
- debug!("in the port_ptr constructor");
- self.po = po; }
drop unsafe {
debug!("in the port_ptr destructor");
do task::unkillable {
}
}
+fn port_ptr<T: send>(po: *rust_port) -> port_ptr<T> {
+ debug!("in the port_ptr constructor");
+ port_ptr {
+ po: po
+ }
+}
/**
* Receive from a port. If no data is available on the port then the
struct r {
let _l: @nillist;
- new(l: @nillist) { self._l = l; }
drop {}
}
+fn r(l: @nillist) -> r {
+ r {
+ _l: l
+ }
+}
+
fn recurse_or_fail(depth: int, st: Option<st>) {
if depth == 0 {
debug!("unwinding %.4f", precise_time_s());
struct box<T> {
let mut contents: Option<T>;
- new(+x: T) { self.contents = Some(x); }
fn swap(f: fn(+T) -> T) {
let mut tmp = None;
}
}
+fn box<T>(+x: T) -> box<T> {
+ box {
+ contents: Some(x)
+ }
+}
+
mod map_reduce {
export putter;
export getter;
struct random_word_reader: word_reader {
let mut remaining: uint;
let rng: rand::Rng;
- new(count: uint) {
- self.remaining = count;
- self.rng = rand::Rng();
- }
fn read_word() -> Option<~str> {
if self.remaining > 0 {
else { None }
}
}
+
+fn random_word_reader(count: uint) -> random_word_reader {
+ random_word_reader {
+ remaining: count,
+ rng: rand::Rng()
+ }
+}
let how_hungry : int;
fn speak() { self.meows += 1u; }
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
// error-pattern:mismatched types: expected `()` but found `bool`
struct r {
- new() {}
drop { true }
}
struct defer {
x: &[&str];
- new(x: &[&str]) { self.x = x; }
drop { #error["%?", self.x]; }
}
+fn defer(x: &r/[&r/str]) -> defer/&r {
+ defer {
+ x: x
+ }
+}
+
fn main() {
let _x = defer(~["Goodbye", "world!"]); //~ ERROR illegal borrow
}
struct noncopyable {
- i: (); new() { self.i = (); } drop { #error["dropped"]; }
+ i: (); drop { #error["dropped"]; }
}
+
+fn noncopyable() -> noncopyable {
+ noncopyable {
+ i: ()
+ }
+}
+
enum wrapper = noncopyable;
fn main() {
// error-pattern: copying a noncopyable value
-struct foo { let x: int; new(x: int) { self.x = x; } drop { } }
+struct foo { let x: int; drop { } }
+
+fn foo(x: int) -> foo {
+ foo {
+ x: x
+ }
+}
fn to_lambda2(b: foo) -> fn@(uint) -> uint {
// test case where copy clause specifies a value that is not used
let mut how_hungry : int;
let name : str;
- new(in_x : uint, in_y : int, in_name: str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+fn cat(in_x : uint, in_y : int, in_name: str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
+
fn main() {
let nyan : noisy = cat(0u, 2, "nyan") as noisy;
nyan.eat();
struct cat : int { //~ ERROR trait
let meows: uint;
- new(in_x : uint) { self.meows = in_x; }
+}
+
+fn cat(in_x : uint) -> cat {
+ cat {
+ meows: in_x
+ }
}
fn main() {
struct cat : animal {
let meows: uint;
- new(in_x : uint) { self.meows = in_x; }
+}
+
+fn cat(in_x : uint) -> cat {
+ cat {
+ meows: in_x
+ }
}
fn main() {
}
}
- new(in_x : uint) { self.meows = in_x; }
}
+
fn main() { }
\ No newline at end of file
struct foo {
let i: int;
- new(i:int) { self.i = i; }
drop {}
}
+fn foo(i:int) -> foo {
+ foo {
+ i: i
+ }
+}
+
fn main() { let x <- foo(10); let y = x; log(error, x); }
struct t { //~ ERROR this type cannot be instantiated
let x: x;
let to_str: ();
- new(x: x) { self.x = x; self.to_str = (); }
}
+
enum x = @t; //~ ERROR this type cannot be instantiated
fn main() {
// error-pattern: type cat cannot be dereferenced
-struct cat { new() {} }
+struct cat {
+ x: ()
+}
fn main() {
- let kitty : cat = cat();
- log (error, *kitty);
+ let kitty : cat = cat { x: () };
+ log (error, *kitty);
}
\ No newline at end of file
// error-pattern: type cat cannot be dereferenced
-struct cat { new() {} }
+struct cat {
+ foo: ()
+}
fn main() {
- let nyan = cat();
- log (error, *nyan);
+ let nyan = cat { foo: () };
+ log (error, *nyan);
}
\ No newline at end of file
struct socket {
let sock: int;
- new() { self.sock = 1; }
-
drop { }
fn set_identity() {
struct c { //~ ERROR a struct must have at least one field
- new() { }
}
fn main() {
- let a = c();
- let x = ~[a];
- let _y = x[0];
}
struct send_packet<T: copy> {
let p: T;
- new(p: T) { self.p = p; }
}
struct example {
let x: int;
- new() {
- self.x = 1;
- }
drop {} //~ ERROR First destructor declared
drop {
debug!("Goodbye, cruel world");
}
}
+fn example() -> example {
+ example {
+ x: 1
+ }
+}
+
fn main(_args: ~[~str]) {
let e: example = example();
}
+++ /dev/null
-struct example {
- let x: int;
- new() { //~ ERROR First constructor declared here
- self.x = 1;
- }
- new(x_: int) {
- self.x = x_;
- }
-}
-
-fn main(_args: ~[~str]) {
- let e: example = example();
-}
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
//~^ ERROR unresolved name: k0
}
- new() { self.v0 = 0; }
}
}
#[forbid(non_camel_case_types)]
struct foo { //~ ERROR type, variant, or trait must be camel case
let bar: int;
-
- new() {
- self.bar = 0;
- }
}
fn main() {
+++ /dev/null
-struct cat {
- let how_hungry : int;
- fn meow() {}
- new() {
- self.meow();
- //~^ ERROR use of possibly uninitialized field: `self.how_hungry`
- }
-}
-
-fn main() {
-}
+++ /dev/null
-struct cat {
- let how_hungry : int;
- new() {} //~ ERROR field `self.how_hungry` is never initialized
-}
-
-fn main() {
-}
+++ /dev/null
-struct cat {
- let mut a: int;
- let mut b: int;
- let mut c: int;
-
- new() {
- self.a = 3;
- self.b = self.a;
- self.a += self.c; //~ ERROR use of possibly uninitialized field: `self.c`
- }
-}
-
-fn main() {
-}
+++ /dev/null
-struct cat {
- priv {
- let mut meows : uint;
- }
-
- let how_hungry : int;
-
- fn eat() {
- self.how_hungry -= 5;
- }
-
- new(in_x : uint, in_y : int) {
- let foo;
- self.meows = in_x + (in_y as uint);
- self.how_hungry = foo; //~ ERROR use of possibly uninitialized variable: `foo`
- }
-}
-
-fn main() {
- let nyan : cat = cat(52u, 99);
- nyan.eat();
-}
// leave this in here just to trigger compile-fail:
struct r {
let x: ();
- new() { self.x = (); }
drop {}
}
fn main() {
- let x = r();
+ let x = r { x: () };
fn@() { copy x; }; //~ ERROR copying a noncopyable value
}
self.how_hungry -= 5;
}
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
fn main() {
struct foo {
let _x: comm::Port<()>;
- new(x: comm::Port<()>) { self._x = x; }
drop {}
}
+
+ fn foo(x: comm::Port<()>) -> foo {
+ foo {
+ _x: x
+ }
+ }
let x = ~mut Some(foo(comm::Port()));
struct r {
let x:int;
- new(x:int) { self.x = x; }
drop {}
}
+fn r(x:int) -> r {
+ r {
+ x: x
+ }
+}
+
struct r2 {
let x:@mut int;
- new(x:@mut int) { self.x = x; }
drop {}
}
+fn r2(x:@mut int) -> r2 {
+ r2 {
+ x: x
+ }
+}
+
fn main() {
foo({f: 3});
foo({mut f: 3}); //~ ERROR missing `const`
// copied
struct bar {
let x: int;
- new(x:int) {self.x = x;}
drop {}
}
+fn bar(x:int) -> bar {
+ bar {
+ x: x
+ }
+}
+
struct foo {
let i: int;
let j: bar;
- new(i:int) { self.i = i; self.j = bar(5); }
+}
+
+fn foo(i:int) -> foo {
+ foo {
+ i: i,
+ j: bar(5)
+ }
}
fn main() { let x <- foo(10); let y = x; log(error, x); }
struct r {
let i: @mut int;
- new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
}
+fn r(i: @mut int) -> r {
+ r {
+ i: i
+ }
+}
+
fn main() {
let i = @mut 0;
{
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
struct my_resource {
let x: int;
- new(x: int) { self.x = x; }
drop { log(error, self.x); }
}
+fn my_resource(x: int) -> my_resource {
+ my_resource {
+ x: x
+ }
+}
+
fn main() {
{
let a = {x: 0, y: my_resource(20)};
struct dog {
let mut cats_chased: uint;
- new() {
- self.cats_chased = 0u;
- }
-
fn chase_cat() {
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow
*p += 1u;
}
}
+fn dog() -> dog {
+ dog {
+ cats_chased: 0u
+ }
+}
+
fn main() {
let d = dog();
d.chase_cat();
struct dog {
let mut food: uint;
- new() {
- self.food = 0u;
- }
-
fn chase_cat() {
for uint::range(0u, 10u) |_i| {
let p: &static/mut uint = &mut self.food; //~ ERROR illegal borrow
enum an_enum = ∫
trait a_trait { fn foo() -> &self/int; }
-struct a_class { let x:&self/int; new(x:&self/int) { self.x = x; } }
+struct a_class { let x:&self/int; }
fn a_fn1(e: an_enum/&a) -> an_enum/&b {
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
struct yes0 {
let x: &uint;
- new(x: &uint) { self.x = x; }
drop {}
}
struct yes1 {
let x: &self/uint;
- new(x: &self/uint) { self.x = x; }
drop {}
}
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 {}
}
struct box_impl<T> {
let mut f: T;
+}
- new(f: T) {
- self.f = f;
+fn box_impl<T>(f: T) -> box_impl<T> {
+ box_impl {
+ f: f
}
}
struct r {
let b:bool;
- new(b: bool) { self.b = b; }
drop {}
}
fn main() {
- let i <- ~r(true);
+ let i <- ~r { b: true };
let j = i;
log(debug, i);
}
\ No newline at end of file
struct r {
let i: @mut int;
- new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
}
fn main() {
let i1 = @mut 0;
let i2 = @mut 1;
- let r1 <- ~[~r(i1)];
- let r2 <- ~[~r(i2)];
+ let r1 <- ~[~r { i: i1 }];
+ let r2 <- ~[~r { i: i2 }];
f(r1, r2);
log(debug, (r2, *i1));
log(debug, (r1, *i2));
struct foo {
let i: int;
let j: @~str;
- new(i:int, j: @~str) { self.i = i; self.j = j; }
+}
+
+fn foo(i:int, j: @~str) -> foo {
+ foo {
+ i: i,
+ j: j
+ }
}
fn main() {
struct and_then_get_big_again {
let x:int;
- new(x:int) {self.x = x;}
drop {
fn getbig(i: int) {
if i != 0 {
}
}
+fn and_then_get_big_again(x:int) -> and_then_get_big_again {
+ and_then_get_big_again {
+ x: x
+ }
+}
+
fn main() {
do task::spawn {
let r = and_then_get_big_again(4);
struct and_then_get_big_again {
let x:int;
- new(x:int) {self.x = x;}
drop {
fn getbig(i: int) {
if i != 0 {
}
}
+fn and_then_get_big_again(x:int) -> and_then_get_big_again {
+ and_then_get_big_again {
+ x: x
+ }
+}
+
fn main() {
do task::spawn {
getbig_and_fail(400);
struct and_then_get_big_again {
let x:int;
- new(x:int) {self.x = x;}
drop {}
}
+fn and_then_get_big_again(x:int) -> and_then_get_big_again {
+ and_then_get_big_again {
+ x: x
+ }
+}
+
fn main() {
do task::spawn {
getbig_and_fail(1);
drop {
os::set_exit_status(50);
}
- new(x:int) {self.x = x;}
+}
+
+fn r(x:int) -> r {
+ r {
+ x: x
+ }
}
fn main() {
struct r {
let v: *int;
- new(v: *int) { self.v = v; }
drop unsafe {
let _v2: ~int = unsafe::reinterpret_cast(&self.v);
}
}
+fn r(v: *int) -> r {
+ r {
+ v: v
+ }
+}
+
fn main() unsafe {
let i1 = ~0;
let i1p = unsafe::reinterpret_cast(&i1);
struct p {
let mut x: int;
let mut y: int;
- new(x: int, y: int) { self.x = x; self.y = y; }
+}
+
+fn p(x: int, y: int) -> p {
+ p {
+ x: x,
+ y: y
+ }
}
impl p : cmp::Eq {
struct Box {
let tree: Tree<@Box>;
+}
- new() {
- self.tree = empty();
+fn Box() -> Box {
+ Box {
+ tree: empty()
}
}
// pp-exact - Make sure we actually print the attributes
struct cat {
- #[cat_maker]
- new(name: ~str) { self.name = name; }
#[cat_dropper]
drop { error!("%s landed on hir feet",self.name); }
name: ~str,
}
+#[cat_maker]
+fn cat(name: ~str) -> cat { cat{name: name,} }
+
fn main() { let _kitty = cat(~"Spotty"); }
struct cat {
let name: ~str;
- #[cat_maker]
- /**
- Maybe it should technically be a kitten_maker.
- */
- new(name: ~str) { self.name = name; }
#[cat_dropper]
/**
Actually, cats don't always land on their feet when you drop them.
drop { error!("%s landed on hir feet", self.name); }
}
+#[cat_maker]
+/**
+Maybe it should technically be a kitten_maker.
+*/
+fn cat(name: ~str) -> cat {
+ cat {
+ name: name
+ }
+}
+
fn main() {
let _kitty = cat(~"Spotty");
}
let volume : @mut int;
- new() { self.volume = @mut 0; self.barks = @mut 0u; }
-
fn speak() -> int { self.bark() }
}
+fn dog() -> dog {
+ dog {
+ volume: @mut 0,
+ barks: @mut 0u
+ }
+}
+
struct cat : noisy {
priv {
let meows : @mut uint;
let how_hungry : @mut int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = @mut in_x; self.how_hungry = @mut in_y;
- self.name = in_name; }
-
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 {
+ cat {
+ meows: @mut in_x,
+ how_hungry: @mut in_y,
+ name: in_name
+ }
+}
+
+
fn annoy_neighbors<T: noisy>(critter: T) {
for uint::range(0u, 10u) |i| { critter.speak(); }
}
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
+
+
fn main() {
let nyan : noisy = cat(0u, 2, ~"nyan") as noisy;
nyan.speak();
struct cat {
let done : extern fn(uint);
let meows : uint;
- new(done: extern fn(uint)) {
- self.meows = 0u;
- self.done = done;
- }
drop { self.done(self.meows); }
}
+fn cat(done: extern fn(uint)) -> cat {
+ cat {
+ meows: 0u,
+ done: done
+ }
+}
+
fn main() {}
let name: ~str;
fn get_name() -> ~str { self.name }
- new(in_name: ~str) { self.name = in_name; self.meows = 0u; }
}
+
+ fn cat(in_name: ~str) -> cat {
+ cat {
+ name: in_name,
+ meows: 0u
+ }
+ }
+
}
fn main() {
let mut how_hungry : int;
let name : T;
- new(in_x : int, in_y : int, in_name: T)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
fn clear() { }
}
+fn cat<T: copy>(in_x : int, in_y : int, in_name: T) -> cat<T> {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
fn main() {
let nyan : cat<~str> = cat(0, 2, ~"nyan");
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
+
+
fn main() {
let nyan = cat(0u, 2, ~"nyan");
nyan.eat();
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
+
+
fn make_speak<C: noisy>(c: C) {
c.speak();
}
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
-
fn speak() { self.meows += 1u; }
fn meow_count() -> uint { self.meows }
}
+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 kitty = cat(1000u, 2);
let how_hungry : int;
- new(in_x : uint, in_y : int, -in_info: ~[U])
- { self.meows = in_x; self.how_hungry = in_y;
- self.info <- in_info; }
-
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 {
+ meows: in_x,
+ how_hungry: in_y,
+ info: move in_info
+ }
+}
+
fn main() {
let nyan : cat<int> = cat::<int>(52u, 99, ~[9]);
let kitty = cat(1000u, 2, ~[~"tabby"]);
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
+
impl cat: ToStr {
fn to_str() -> ~str { self.name }
}
let name : ~str;
- new(in_name: ~str)
- { self.name = in_name; }
+}
+
+fn cat(in_name: ~str) -> cat {
+ cat {
+ name: in_name
+ }
}
fn main() {
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
-
fn speak() {
self.meows += 1u;
}
fn meow_count() -> uint { self.meows }
}
+fn cat<U>(in_x : uint, in_y : int) -> cat<U> {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
+}
+
+
fn main() {
let _nyan : cat<int> = cat::<int>(52u, 99);
// let kitty = cat(1000u, 2);
struct kitten {
let cat: Option<cat>;
- new(cat: Option<cat>) {
- self.cat = cat;
+}
+
+fn kitten(cat: Option<cat>) -> kitten {
+ kitten {
+ cat: cat
}
}
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
-
fn speak() {}
}
+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 kitty = cat(1000u, 2);
let how_hungry : int;
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
let mut how_hungry : int;
let name : ~str;
- new(in_x : uint, in_y : int, in_name: ~str)
- { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
fn speak() { self.meow(); }
fn eat() -> bool {
}
}
+fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y,
+ name: in_name
+ }
+}
+
fn main() {
let nyan = cat(0u, 2, ~"nyan");
nyan.eat();
#[cfg(bogus)]
struct r {
let i: int;
- new(i:int) { self.i = i; }
+}
+
+#[cfg(bogus)]
+fn r(i:int) -> r {
+ r {
+ i: i
+ }
}
struct r {
let i: int;
- new(i:int) { self.i = i; }
+}
+
+fn r(i:int) -> r {
+ r {
+ i: i
+ }
}
#[cfg(bogus)]
struct thing {
x: {mut a: @int};
- new (x: {mut a: @int}) { self.x = copy x; }
}
+fn thing(x: {mut a: @int}) -> thing {
+ thing {
+ x: copy x
+ }
+}
impl thing {
fn foo(@self) -> int { *self.x.a }
struct r {
let i: @mut int;
- new(i: @mut int) {
- self.i = i;
- }
drop { *(self.i) = *(self.i) + 1; }
}
+fn r(i: @mut int) -> r {
+ r {
+ i: i
+ }
+}
+
fn test_box() {
let i = @mut 0;
{
}
struct foo<A: copy> : clam<A> {
let x: A;
- new(b: A) { self.x = b; }
fn chowder(y: A) {
}
}
+fn foo<A: copy>(b: A) -> foo<A> {
+ foo {
+ x: b
+ }
+}
+
fn f<A: copy>(x: clam<A>, a: A) {
x.chowder(a);
}
trait clam<A: copy> { }
struct foo<A: copy> {
let x: A;
- new(b: A) { self.x = b; }
fn bar<B,C:clam<A>>(c: C) -> B {
fail;
}
}
+fn foo<A: copy>(b: A) -> foo<A> {
+ foo {
+ x: b
+ }
+}
+
fn main() { }
struct c1<T: copy> {
let x: T;
- new(x: T) {self.x = x;}
-
fn f1(x: int) {
}
}
+fn c1<T: copy>(x: T) -> c1<T> {
+ c1 {
+ x: x
+ }
+}
+
impl<T: copy> c1<T> {
fn f2(x: int) {
}
struct c1<T: copy> {
let x: T;
- new(x: T) {self.x = x;}
-
fn f1(x: T) {}
}
+fn c1<T: copy>(x: T) -> c1<T> {
+ c1 {
+ x: x
+ }
+}
+
impl<T: copy> c1<T> {
fn f2(x: T) {}
}
struct socket {
let sock: int;
- new() { self.sock = 1; }
-
drop { }
fn set_identity() {
}
}
+fn socket() -> socket {
+ socket {
+ sock: 1
+ }
+}
+
fn closure(f: fn()) { f() }
fn setsockopt_bytes(_sock: int) { }
struct font {
let fontbuf: &self/~[u8];
- new(fontbuf: &self/~[u8]) {
- self.fontbuf = fontbuf;
- }
-
fn buf() -> &self/~[u8] {
self.fontbuf
}
}
+fn font(fontbuf: &r/~[u8]) -> font/&r {
+ font {
+ fontbuf: fontbuf
+ }
+}
+
fn main() { }
struct C {
let x: uint;
- new(x: uint) {
- self.x = x;
+}
+
+fn C(x: uint) -> C {
+ C {
+ x: x
}
}
struct cat {
let mut meow: fn@();
- new() { self.meow = fn@() { error!("meow"); };}
+}
+
+fn cat() -> cat {
+ cat {
+ meow: fn@() { error!("meow"); }
+ }
}
type kitty_info = {kitty: cat};
let cairo_font: uint;
let font_dtor: uint;
- new() {
- self.fontbuf = 0;
- self.cairo_font = 0;
- self.font_dtor = 0;
- }
-
drop { }
}
+fn Font() -> Font {
+ Font {
+ fontbuf: 0,
+ cairo_font: 0,
+ font_dtor: 0
+ }
+}
+
fn main() {
let _f = @Font();
}
struct send_packet<T: send> {
let mut p: Option<*packet<T>>;
- new(p: *packet<T>) { self.p = Some(p); }
drop {
if self.p != None {
let mut p = None;
}
}
+ fn send_packet<T: send>(p: *packet<T>) -> send_packet<T> {
+ send_packet {
+ p: Some(p)
+ }
+ }
+
struct recv_packet<T: send> {
let mut p: Option<*packet<T>>;
- new(p: *packet<T>) { self.p = Some(p); }
drop {
if self.p != None {
let mut p = None;
}
}
+ fn recv_packet<T: send>(p: *packet<T>) -> recv_packet<T> {
+ recv_packet {
+ p: Some(p)
+ }
+ }
+
fn entangle<T: send>() -> (send_packet<T>, recv_packet<T>) {
let p = packet();
(send_packet(p), recv_packet(p))
// This test should behave exactly like issue-2735-3
struct defer {
let b: &mut bool;
- new(b: &mut bool) {
- self.b = b;
- }
drop { *(self.b) = true; }
}
+fn defer(b: &r/mut bool) -> defer/&r {
+ defer {
+ b: b
+ }
+}
+
fn main() {
let mut dtor_ran = false;
let _ = defer(&mut dtor_ran);
// This test should behave exactly like issue-2735-2
struct defer {
let b: &mut bool;
- new(b: &mut bool) {
- self.b = b;
- }
drop { *(self.b) = true; }
}
+fn defer(b: &r/mut bool) -> defer/&r {
+ defer {
+ b: b
+ }
+}
+
fn main() {
let mut dtor_ran = false;
defer(&mut dtor_ran);
struct CMap {
let buf: &[u8];
- new(buf: &self/[u8]) {
- self.buf = buf;
+}
+
+fn CMap(buf: &r/[u8]) -> CMap/&r {
+ CMap {
+ buf: buf
}
}
struct cbar : bar<int> {
x: int;
- new(x: int) { self.x = x; }
fn get_bar() -> int {
self.x
}
}
+fn cbar(x: int) -> cbar {
+ cbar {
+ x: x
+ }
+}
+
fn main() {
let x: int = foo::<int, cbar>(cbar(5));
assert x == 5;
-struct thing { x: int; new () { self.x = 0; } drop { } }
+struct thing { x: int; drop { } }
+fn thing() -> thing {
+ thing {
+ x: 0
+ }
+}
impl thing { fn f(self) {} }
fn main() {
struct r {
let b: @mut int;
- new(b: @mut int) {
- self.b = b;
- }
drop { *(self.b) += 1; }
}
+fn r(b: @mut int) -> r {
+ r {
+ b: b
+ }
+}
+
fn main() {
let b = @mut 0;
{
struct b {
let i: int;
fn do_stuff() -> int { return 37; }
- new(i:int) { self.i = i; }
}
+ fn b(i:int) -> b {
+ b {
+ i: i
+ }
+ }
+
// fn b(x:int) -> int { fail; }
let z = b(42);
let how_hungry : int;
fn meow_count() -> uint { self.meows }
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
self.meows += 1u;
self.nap();
}
- new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
+}
+
+fn cat(in_x : uint, in_y : int) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
}
fn main() {
struct r {
let i: @mut int;
- new(i: @mut int) {
- self.i = i;
- }
drop { *(self.i) += 1; }
}
+fn r(i: @mut int) -> r {
+ r {
+ i: i
+ }
+}
+
fn main() {
let i = @mut 0;
// Even though these look like copies, they are guaranteed not to be
struct r {
let v: *int;
- new(v: *int) unsafe {
- self.v = v;
- debug!("r's ctor: v = %x, self = %x, self.v = %x",
- unsafe::reinterpret_cast::<*int, uint>(&v),
- unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)),
- unsafe::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)));
- }
drop unsafe {
debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x",
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)),
let v2: ~int = unsafe::reinterpret_cast(&self.v); }
}
+fn r(v: *int) -> r unsafe {
+ r {
+ v: v
+ }
+}
+
enum t = {
mut next: Option<@t>,
r: r
struct r {
let v: u;
- new(v: u) { self.v = v; }
drop unsafe {
let v2: ~int = unsafe::reinterpret_cast(&self.v.c);
}
}
+fn r(v: u) -> r {
+ r {
+ v: v
+ }
+}
+
enum t = {
mut next: Option<@t>,
r: r
let v: u;
let w: int;
let x: *int;
- new(v: u, w: int, _x: *int) unsafe { self.v = v; self.w = w;
- self.x = unsafe::reinterpret_cast(&0);
- /* self.x = x; */ }
drop unsafe {
let _v2: ~int = unsafe::reinterpret_cast(&self.v.c);
// let _v3: ~int = unsafe::reinterpret_cast(self.x);
}
}
+fn r(v: u, w: int, _x: *int) -> r unsafe {
+ r {
+ v: v,
+ w: w,
+ x: unsafe::reinterpret_cast(&0)
+ }
+}
+
enum t = {
mut next: Option<@t>,
r: r
struct shrinky_pointer {
let i: @@mut int;
fn look_at() -> int { return **(self.i); }
- new(i: @@mut int) { self.i = i; }
drop { log(error, ~"Hello!"); **(self.i) -= 1; }
}
+fn shrinky_pointer(i: @@mut int) -> shrinky_pointer {
+ shrinky_pointer {
+ i: i
+ }
+}
+
fn main() {
let my_total = @@mut 10;
{ let pt <- shrinky_pointer(my_total); assert (pt.look_at() == 10); }
struct finish<T: copy> {
let arg: {val: T, fin: extern fn(T)};
- new(arg: {val: T, fin: extern fn(T)}) {
- self.arg = arg;
- }
drop { self.arg.fin(self.arg.val); }
}
+fn finish<T: copy>(arg: {val: T, fin: extern fn(T)}) -> finish<T> {
+ finish {
+ arg: arg
+ }
+}
+
fn main() {
let box = @mut 10;
fn dec_box(&&i: @mut int) { *i -= 1; }
struct close_res {
let i: closable;
- new(i: closable) { self.i = i; }
drop { *(self.i) = false; }
}
+fn close_res(i: closable) -> close_res {
+ close_res {
+ i: i
+ }
+}
+
enum option<T> { none, some(T), }
fn sink(res: option<close_res>) { }
struct test {
let f: int;
- new(f: int) { self.f = f; }
drop {}
}
+fn test(f: int) -> test {
+ test {
+ f: f
+ }
+}
+
fn main() {
let p = Port();
let c = Chan(p);
struct foo {
let i: int;
let j: char;
- new(i:int, j: char) { self.i = i; self.j = j; }
+}
+
+fn foo(i:int, j: char) -> foo {
+ foo {
+ i: i,
+ j: j
+ }
}
fn main() {
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 {
error!("notify: task=%? v=%x unwinding=%b b=%b",
task::get_task(),
}
}
+fn notify(ch: comm::Chan<bool>, v: @mut bool) -> notify {
+ notify {
+ ch: ch,
+ v: v
+ }
+}
+
fn joinable(+f: fn~()) -> comm::Port<bool> {
fn wrapper(+c: comm::Chan<bool>, +f: fn()) {
let b = @mut false;
struct r {
let i: int;
- new(i:int) { self.i = i; }
drop {}
}
+fn r(i:int) -> r {
+ r {
+ i: i
+ }
+}
+
fn main() {
p_foo(r(10));
p_foo(@r(10));
struct r {
let i: @mut int;
- new(i: @mut int) { self.i = i; }
drop { *(self.i) = *(self.i) + 1; }
}
+fn r(i: @mut int) -> r {
+ r {
+ i: i
+ }
+}
+
fn main() {
let i = @mut 0;
{
struct complainer {
let c: comm::Chan<bool>;
- new(c: comm::Chan<bool>) {
- error!("Hello!");
- self.c = c; }
drop { error!("About to send!");
comm::send(self.c, true);
error!("Sent!"); }
}
+fn complainer(c: comm::Chan<bool>) -> complainer {
+ error!("Hello!");
+ complainer {
+ c: c
+ }
+}
+
fn f(c: comm::Chan<bool>) {
let _c <- complainer(c);
fail;
struct complainer {
let c: @int;
- new(c: @int) { self.c = c; }
drop {}
}
+fn complainer(c: @int) -> complainer {
+ complainer {
+ c: c
+ }
+}
+
fn f() {
let c <- complainer(@0);
fail;
// Make sure that destructors get run on slice literals
struct foo {
let x: @mut int;
- new(x: @mut int) { self.x = x; }
drop { *self.x += 1; }
}
+fn foo(x: @mut int) -> foo {
+ foo {
+ x: x
+ }
+}
+
fn main() {
let x = @mut 0;
{