Remove struct ctors
This commit is contained in:
parent
5e36a99794
commit
b4e547d71a
130 changed files with 1017 additions and 557 deletions
|
@ -118,6 +118,15 @@ fn protocol(name: ~str, +span: span) -> protocol {
|
||||||
@protocol_(name, span)
|
@protocol_(name, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn protocol_(name: ~str, span: span) -> protocol_ {
|
||||||
|
protocol_ {
|
||||||
|
name: name,
|
||||||
|
span: span,
|
||||||
|
states: DVec(),
|
||||||
|
bounded: None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct protocol_ {
|
struct protocol_ {
|
||||||
let name: ~str;
|
let name: ~str;
|
||||||
let span: span;
|
let span: span;
|
||||||
|
@ -125,13 +134,6 @@ struct protocol_ {
|
||||||
|
|
||||||
let mut bounded: Option<bool>;
|
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.
|
/// Get a state.
|
||||||
fn get_state(name: ~str) -> state {
|
fn get_state(name: ~str) -> state {
|
||||||
self.states.find(|i| i.name == name).get()
|
self.states.find(|i| i.name == name).get()
|
||||||
|
|
|
@ -181,6 +181,37 @@ pure fn maybe_append(+lhs: ~[attribute], rhs: Option<~[attribute]>)
|
||||||
|
|
||||||
/* ident is handled by common.rs */
|
/* 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 {
|
struct parser {
|
||||||
let sess: parse_sess;
|
let sess: parse_sess;
|
||||||
let cfg: crate_cfg;
|
let cfg: crate_cfg;
|
||||||
|
@ -198,32 +229,6 @@ struct parser {
|
||||||
let keywords: hashmap<~str, ()>;
|
let keywords: hashmap<~str, ()>;
|
||||||
let restricted_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 */
|
drop {} /* do not copy the parser; its state is tied to outside state */
|
||||||
|
|
||||||
fn bump() {
|
fn bump() {
|
||||||
|
@ -2594,7 +2599,6 @@ struct parser {
|
||||||
let class_name = self.parse_value_ident();
|
let class_name = self.parse_value_ident();
|
||||||
self.parse_region_param();
|
self.parse_region_param();
|
||||||
let ty_params = self.parse_ty_params();
|
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)
|
let traits : ~[@trait_ref] = if self.eat(token::COLON)
|
||||||
{ self.parse_trait_ref_list(token::LBRACE) }
|
{ self.parse_trait_ref_list(token::LBRACE) }
|
||||||
else { ~[] };
|
else { ~[] };
|
||||||
|
@ -2610,7 +2614,7 @@ struct parser {
|
||||||
// It's a record-like struct.
|
// It's a record-like struct.
|
||||||
fields = ~[];
|
fields = ~[];
|
||||||
while self.token != token::RBRACE {
|
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) => {
|
ctor_decl(a_fn_decl, attrs, blk, s) => {
|
||||||
match the_ctor {
|
match the_ctor {
|
||||||
Some((_, _, _, s_first)) => {
|
Some((_, _, _, s_first)) => {
|
||||||
|
@ -2747,24 +2751,13 @@ struct parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn parse_dtor(attrs: ~[attribute]) -> class_contents {
|
||||||
let lo = self.last_span.lo;
|
let lo = self.last_span.lo;
|
||||||
let body = self.parse_block();
|
let body = self.parse_block();
|
||||||
dtor_decl(body, attrs, mk_sp(lo, self.last_span.hi))
|
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") {
|
if self.eat_keyword(~"priv") {
|
||||||
// XXX: Remove after snapshot.
|
// XXX: Remove after snapshot.
|
||||||
match self.token {
|
match self.token {
|
||||||
|
@ -2789,12 +2782,7 @@ struct parser {
|
||||||
|
|
||||||
let attrs = self.parse_outer_attributes();
|
let attrs = self.parse_outer_attributes();
|
||||||
|
|
||||||
if self.eat_keyword(~"new") {
|
if self.eat_keyword(~"drop") {
|
||||||
// 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") {
|
|
||||||
return self.parse_dtor(attrs);
|
return self.parse_dtor(attrs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3019,12 +3007,12 @@ struct parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
|
||||||
let mut fields: ~[@struct_field] = ~[];
|
let mut fields: ~[@struct_field] = ~[];
|
||||||
let mut methods: ~[@method] = ~[];
|
let mut methods: ~[@method] = ~[];
|
||||||
while self.token != token::RBRACE {
|
while self.token != token::RBRACE {
|
||||||
match self.parse_class_item(path) {
|
match self.parse_class_item() {
|
||||||
ctor_decl(*) => {
|
ctor_decl(*) => {
|
||||||
self.span_fatal(copy self.span,
|
self.span_fatal(copy self.span,
|
||||||
~"deprecated explicit \
|
~"deprecated explicit \
|
||||||
|
@ -3076,7 +3064,7 @@ struct parser {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_enum_def(ident: ast::ident, ty_params: ~[ast::ty_param])
|
fn parse_enum_def(ty_params: ~[ast::ty_param])
|
||||||
-> enum_def {
|
-> enum_def {
|
||||||
let mut variants: ~[variant] = ~[];
|
let mut variants: ~[variant] = ~[];
|
||||||
let mut all_nullary = true, have_disr = false;
|
let mut all_nullary = true, have_disr = false;
|
||||||
|
@ -3092,8 +3080,7 @@ struct parser {
|
||||||
self.fatal(~"duplicate declaration of shared fields");
|
self.fatal(~"duplicate declaration of shared fields");
|
||||||
}
|
}
|
||||||
self.expect(token::LBRACE);
|
self.expect(token::LBRACE);
|
||||||
let path = self.ident_to_path_tys(ident, ty_params);
|
common_fields = Some(self.parse_struct_def());
|
||||||
common_fields = Some(self.parse_struct_def(path));
|
|
||||||
again;
|
again;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3105,7 +3092,7 @@ struct parser {
|
||||||
if self.eat_keyword(~"enum") {
|
if self.eat_keyword(~"enum") {
|
||||||
ident = self.parse_ident();
|
ident = self.parse_ident();
|
||||||
self.expect(token::LBRACE);
|
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);
|
kind = enum_variant_kind(move nested_enum_def);
|
||||||
needs_comma = false;
|
needs_comma = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3113,8 +3100,7 @@ struct parser {
|
||||||
if self.eat(token::LBRACE) {
|
if self.eat(token::LBRACE) {
|
||||||
// Parse a struct variant.
|
// Parse a struct variant.
|
||||||
all_nullary = false;
|
all_nullary = false;
|
||||||
let path = self.ident_to_path_tys(ident, ty_params);
|
kind = struct_variant_kind(self.parse_struct_def());
|
||||||
kind = struct_variant_kind(self.parse_struct_def(path));
|
|
||||||
} else if self.token == token::LPAREN {
|
} else if self.token == token::LPAREN {
|
||||||
all_nullary = false;
|
all_nullary = false;
|
||||||
let arg_tys = self.parse_unspanned_seq(
|
let arg_tys = self.parse_unspanned_seq(
|
||||||
|
@ -3176,7 +3162,7 @@ struct parser {
|
||||||
}
|
}
|
||||||
self.expect(token::LBRACE);
|
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)
|
(id, item_enum(enum_definition, ty_params), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,6 @@ fn restricted_keyword_table() -> hashmap<~str, ()> {
|
||||||
~"if", ~"impl", ~"import",
|
~"if", ~"impl", ~"import",
|
||||||
~"let", ~"log", ~"loop",
|
~"let", ~"log", ~"loop",
|
||||||
~"match", ~"mod", ~"module", ~"move", ~"mut",
|
~"match", ~"mod", ~"module", ~"move", ~"mut",
|
||||||
~"new",
|
|
||||||
~"owned",
|
~"owned",
|
||||||
~"pure",
|
~"pure",
|
||||||
~"ref", ~"return",
|
~"ref", ~"return",
|
||||||
|
|
|
@ -241,11 +241,10 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
|
||||||
|
|
||||||
struct finally {
|
struct finally {
|
||||||
let ch: comm::Chan<monitor_msg>;
|
let ch: comm::Chan<monitor_msg>;
|
||||||
new(ch: comm::Chan<monitor_msg>) { self.ch = ch; }
|
|
||||||
drop { comm::send(self.ch, done); }
|
drop { comm::send(self.ch, done); }
|
||||||
}
|
}
|
||||||
|
|
||||||
let _finally = finally(ch);
|
let _finally = finally { ch: ch };
|
||||||
|
|
||||||
f(demitter)
|
f(demitter)
|
||||||
} {
|
} {
|
||||||
|
|
|
@ -1175,10 +1175,15 @@ fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] unsafe {
|
||||||
|
|
||||||
struct target_data_res {
|
struct target_data_res {
|
||||||
let TD: TargetDataRef;
|
let TD: TargetDataRef;
|
||||||
new(TD: TargetDataRef) { self.TD = TD; }
|
|
||||||
drop { llvm::LLVMDisposeTargetData(self.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};
|
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
|
||||||
|
|
||||||
fn mk_target_data(string_rep: ~str) -> target_data {
|
fn mk_target_data(string_rep: ~str) -> target_data {
|
||||||
|
@ -1191,10 +1196,15 @@ fn mk_target_data(string_rep: ~str) -> target_data {
|
||||||
|
|
||||||
struct pass_manager_res {
|
struct pass_manager_res {
|
||||||
let PM: PassManagerRef;
|
let PM: PassManagerRef;
|
||||||
new(PM: PassManagerRef) { self.PM = PM; }
|
|
||||||
drop { llvm::LLVMDisposePassManager(self.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};
|
type pass_manager = {llpm: PassManagerRef, dtor: @pass_manager_res};
|
||||||
|
|
||||||
fn mk_pass_manager() -> pass_manager {
|
fn mk_pass_manager() -> pass_manager {
|
||||||
|
@ -1206,10 +1216,15 @@ fn mk_pass_manager() -> pass_manager {
|
||||||
|
|
||||||
struct object_file_res {
|
struct object_file_res {
|
||||||
let ObjectFile: ObjectFileRef;
|
let ObjectFile: ObjectFileRef;
|
||||||
new(ObjectFile: ObjectFileRef) { self.ObjectFile = ObjectFile; }
|
|
||||||
drop { llvm::LLVMDisposeObjectFile(self.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};
|
type object_file = {llof: ObjectFileRef, dtor: @object_file_res};
|
||||||
|
|
||||||
fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
|
fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
|
||||||
|
@ -1222,10 +1237,15 @@ fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
|
||||||
|
|
||||||
struct section_iter_res {
|
struct section_iter_res {
|
||||||
let SI: SectionIteratorRef;
|
let SI: SectionIteratorRef;
|
||||||
new(SI: SectionIteratorRef) { self.SI = SI; }
|
|
||||||
drop { llvm::LLVMDisposeSectionIterator(self.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};
|
type section_iter = {llsi: SectionIteratorRef, dtor: @section_iter_res};
|
||||||
|
|
||||||
fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
|
fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
|
||||||
|
|
|
@ -442,10 +442,12 @@ struct path_entry {
|
||||||
let path_string: ~str;
|
let path_string: ~str;
|
||||||
// The definition, implementation, or field that this path corresponds to.
|
// The definition, implementation, or field that this path corresponds to.
|
||||||
let def_like: def_like;
|
let def_like: def_like;
|
||||||
|
}
|
||||||
|
|
||||||
new(path_string: ~str, def_like: def_like) {
|
fn path_entry(path_string: ~str, def_like: def_like) -> path_entry {
|
||||||
self.path_string = path_string;
|
path_entry {
|
||||||
self.def_like = def_like;
|
path_string: path_string,
|
||||||
|
def_like: def_like
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,41 @@ mod LanguageItems {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
struct LanguageItemCollector {
|
||||||
let items: &LanguageItems;
|
let items: &LanguageItems;
|
||||||
|
|
||||||
|
@ -80,34 +115,6 @@ struct LanguageItemCollector {
|
||||||
|
|
||||||
let item_refs: hashmap<~str,&mut Option<def_id>>;
|
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,
|
fn match_and_collect_meta_item(item_def_id: def_id,
|
||||||
meta_item: meta_item) {
|
meta_item: meta_item) {
|
||||||
|
|
||||||
|
|
|
@ -311,26 +311,30 @@ fn atom_hashmap<V:copy>() -> hashmap<Atom,V> {
|
||||||
struct Rib {
|
struct Rib {
|
||||||
let bindings: hashmap<Atom,def_like>;
|
let bindings: hashmap<Atom,def_like>;
|
||||||
let kind: RibKind;
|
let kind: RibKind;
|
||||||
|
}
|
||||||
|
|
||||||
new(kind: RibKind) {
|
fn Rib(kind: RibKind) -> Rib {
|
||||||
self.bindings = atom_hashmap();
|
Rib {
|
||||||
self.kind = kind;
|
bindings: atom_hashmap(),
|
||||||
|
kind: kind
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// One import directive.
|
/// One import directive.
|
||||||
struct ImportDirective {
|
struct ImportDirective {
|
||||||
let module_path: @DVec<Atom>;
|
let module_path: @DVec<Atom>;
|
||||||
let subclass: @ImportDirectiveSubclass;
|
let subclass: @ImportDirectiveSubclass;
|
||||||
let span: span;
|
let span: span;
|
||||||
|
}
|
||||||
|
|
||||||
new(module_path: @DVec<Atom>,
|
fn ImportDirective(module_path: @DVec<Atom>,
|
||||||
subclass: @ImportDirectiveSubclass,
|
subclass: @ImportDirectiveSubclass,
|
||||||
span: span) {
|
span: span) -> ImportDirective {
|
||||||
|
ImportDirective {
|
||||||
self.module_path = module_path;
|
module_path: module_path,
|
||||||
self.subclass = subclass;
|
subclass: subclass,
|
||||||
self.span = span;
|
span: span
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,10 +342,12 @@ struct ImportDirective {
|
||||||
struct Target {
|
struct Target {
|
||||||
let target_module: @Module;
|
let target_module: @Module;
|
||||||
let bindings: @NameBindings;
|
let bindings: @NameBindings;
|
||||||
|
}
|
||||||
|
|
||||||
new(target_module: @Module, bindings: @NameBindings) {
|
fn Target(target_module: @Module, bindings: @NameBindings) -> Target {
|
||||||
self.target_module = target_module;
|
Target {
|
||||||
self.bindings = bindings;
|
target_module: target_module,
|
||||||
|
bindings: bindings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,18 +366,6 @@ struct ImportResolution {
|
||||||
|
|
||||||
let mut used: bool;
|
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> {
|
fn target_for_namespace(namespace: Namespace) -> Option<Target> {
|
||||||
match namespace {
|
match namespace {
|
||||||
ModuleNS => return copy self.module_target,
|
ModuleNS => return copy self.module_target,
|
||||||
|
@ -381,6 +375,17 @@ struct ImportResolution {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
/// The link from a module up to its nearest parent node.
|
||||||
enum ParentLink {
|
enum ParentLink {
|
||||||
NoParentLink,
|
NoParentLink,
|
||||||
|
@ -430,27 +435,25 @@ struct Module {
|
||||||
// The index of the import we're resolving.
|
// The index of the import we're resolving.
|
||||||
let mut resolved_import_count: uint;
|
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 {
|
fn all_imports_resolved() -> bool {
|
||||||
return self.imports.len() == self.resolved_import_count;
|
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
|
// XXX: This is a workaround due to is_none in the standard library mistakenly
|
||||||
// requiring a T:copy.
|
// requiring a T:copy.
|
||||||
|
|
||||||
|
@ -501,15 +504,6 @@ struct NameBindings {
|
||||||
let mut type_span: Option<span>;
|
let mut type_span: Option<span>;
|
||||||
let mut value_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.
|
/// Creates a new module in this set of name bindings.
|
||||||
fn define_module(parent_link: ParentLink, def_id: Option<def_id>,
|
fn define_module(parent_link: ParentLink, def_id: Option<def_id>,
|
||||||
sp: span) {
|
sp: span) {
|
||||||
|
@ -598,31 +592,22 @@ struct NameBindings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
/// Interns the names of the primitive types.
|
||||||
struct PrimitiveTypeTable {
|
struct PrimitiveTypeTable {
|
||||||
let primitive_types: hashmap<Atom,prim_ty>;
|
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,
|
fn intern(intr: ident_interner, string: @~str,
|
||||||
primitive_type: prim_ty) {
|
primitive_type: prim_ty) {
|
||||||
let atom = intr.intern(string);
|
let atom = intr.intern(string);
|
||||||
|
@ -630,6 +615,32 @@ struct PrimitiveTypeTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
fn namespace_to_str(ns: Namespace) -> ~str {
|
||||||
match ns {
|
match ns {
|
||||||
TypeNS => ~"type",
|
TypeNS => ~"type",
|
||||||
|
@ -638,6 +649,59 @@ fn namespace_to_str(ns: Namespace) -> ~str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
/// The main resolver class.
|
||||||
struct Resolver {
|
struct Resolver {
|
||||||
let session: session;
|
let session: session;
|
||||||
|
@ -690,48 +754,6 @@ struct Resolver {
|
||||||
let export_map2: ExportMap2;
|
let export_map2: ExportMap2;
|
||||||
let trait_map: TraitMap;
|
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.
|
/// The main name resolution procedure.
|
||||||
fn resolve(@self, this: @Resolver) {
|
fn resolve(@self, this: @Resolver) {
|
||||||
self.build_reduced_graph(this);
|
self.build_reduced_graph(this);
|
||||||
|
|
|
@ -56,7 +56,6 @@ use option::{is_none, is_some};
|
||||||
|
|
||||||
struct icx_popper {
|
struct icx_popper {
|
||||||
let ccx: @crate_ctxt;
|
let ccx: @crate_ctxt;
|
||||||
new(ccx: @crate_ctxt) { self.ccx = ccx; }
|
|
||||||
drop {
|
drop {
|
||||||
if self.ccx.sess.count_llvm_insns() {
|
if self.ccx.sess.count_llvm_insns() {
|
||||||
vec::pop(*(self.ccx.stats.llvm_insn_ctxt));
|
vec::pop(*(self.ccx.stats.llvm_insn_ctxt));
|
||||||
|
@ -64,6 +63,12 @@ struct icx_popper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn icx_popper(ccx: @crate_ctxt) -> icx_popper {
|
||||||
|
icx_popper {
|
||||||
|
ccx: ccx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trait get_insn_ctxt {
|
trait get_insn_ctxt {
|
||||||
fn insn_ctxt(s: &str) -> icx_popper;
|
fn insn_ctxt(s: &str) -> icx_popper;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,10 +95,15 @@ type stats =
|
||||||
|
|
||||||
struct BuilderRef_res {
|
struct BuilderRef_res {
|
||||||
let B: BuilderRef;
|
let B: BuilderRef;
|
||||||
new(B: BuilderRef) { self.B = B; }
|
|
||||||
drop { llvm::LLVMDisposeBuilder(self.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.
|
// Crate context. Every crate we compile has one of these.
|
||||||
type crate_ctxt = {
|
type crate_ctxt = {
|
||||||
sess: session::session,
|
sess: session::session,
|
||||||
|
@ -485,12 +490,21 @@ struct block_ {
|
||||||
// The function context for the function to which this block is
|
// The function context for the function to which this block is
|
||||||
// attached.
|
// attached.
|
||||||
let fcx: fn_ctxt;
|
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
|
fn block_(llbb: BasicBlockRef, parent: Option<block>, -kind: block_kind,
|
||||||
self.llbb = llbb; self.terminated = false; self.unreachable = false;
|
is_lpad: bool, node_info: Option<node_info>, fcx: fn_ctxt)
|
||||||
self.parent = parent; self.kind = kind; self.is_lpad = is_lpad;
|
-> block_ {
|
||||||
self.node_info = node_info; self.fcx = fcx;
|
|
||||||
|
block_ {
|
||||||
|
llbb: llbb,
|
||||||
|
terminated: false,
|
||||||
|
unreachable: false,
|
||||||
|
parent: parent,
|
||||||
|
kind: kind,
|
||||||
|
is_lpad: is_lpad,
|
||||||
|
node_info: node_info,
|
||||||
|
fcx: fcx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,35 @@ fn get_mode_from_self_type(self_type: ast::self_ty_) -> ast::rmode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
struct lookup {
|
||||||
let fcx: @fn_ctxt;
|
let fcx: @fn_ctxt;
|
||||||
let expr: @ast::expr;
|
let expr: @ast::expr;
|
||||||
|
@ -77,33 +106,6 @@ struct lookup {
|
||||||
let supplied_tps: ~[ty::t];
|
let supplied_tps: ~[ty::t];
|
||||||
let include_private: bool;
|
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:
|
// Entrypoint:
|
||||||
fn method() -> Option<method_map_entry> {
|
fn method() -> Option<method_map_entry> {
|
||||||
debug!("method lookup(m_name=%s, self_ty=%s, %?)",
|
debug!("method lookup(m_name=%s, self_ty=%s, %?)",
|
||||||
|
|
|
@ -126,10 +126,22 @@ struct CoherenceInfo {
|
||||||
// Contains implementations of methods associated with a trait. For these,
|
// Contains implementations of methods associated with a trait. For these,
|
||||||
// the associated trait must be imported at the call site.
|
// the associated trait must be imported at the call site.
|
||||||
let extension_methods: hashmap<def_id,@DVec<@Impl>>;
|
let extension_methods: hashmap<def_id,@DVec<@Impl>>;
|
||||||
|
}
|
||||||
|
|
||||||
new() {
|
fn CoherenceInfo() -> CoherenceInfo {
|
||||||
self.inherent_methods = new_def_hash();
|
CoherenceInfo {
|
||||||
self.extension_methods = new_def_hash();
|
inherent_methods: new_def_hash(),
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,14 +159,6 @@ struct CoherenceChecker {
|
||||||
|
|
||||||
let privileged_implementations: hashmap<node_id,()>;
|
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
|
// Create a mapping containing a MethodInfo for every provided
|
||||||
// method in every trait.
|
// method in every trait.
|
||||||
fn build_provided_methods_map(crate: @crate) {
|
fn build_provided_methods_map(crate: @crate) {
|
||||||
|
|
|
@ -16,10 +16,15 @@ fn indent<R>(op: fn() -> R) -> R {
|
||||||
|
|
||||||
struct _indenter {
|
struct _indenter {
|
||||||
let _i: ();
|
let _i: ();
|
||||||
new(_i: ()) { self._i = (); }
|
|
||||||
drop { debug!("<<"); }
|
drop { debug!("<<"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn _indenter(_i: ()) -> _indenter {
|
||||||
|
_indenter {
|
||||||
|
_i: ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn indenter() -> _indenter {
|
fn indenter() -> _indenter {
|
||||||
debug!(">>");
|
debug!(">>");
|
||||||
_indenter(())
|
_indenter(())
|
||||||
|
|
|
@ -113,7 +113,6 @@ mod blade_runner {
|
||||||
*/
|
*/
|
||||||
struct bored {
|
struct bored {
|
||||||
let bored: bool;
|
let bored: bool;
|
||||||
new(bored: bool) { self.bored = bored; }
|
|
||||||
drop { log(error, self.bored); }
|
drop { log(error, self.bored); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,13 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,14 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
let how_hungry : int;
|
||||||
|
|
||||||
new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
|
|
||||||
|
|
||||||
fn speak() {}
|
fn speak() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cat(in_x : uint, in_y : int) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: in_x,
|
||||||
|
how_hungry: in_y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,17 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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 speak() { self.meows += 1u; }
|
||||||
fn meow_count() -> uint { self.meows }
|
fn meow_count() -> uint { self.meows }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cat(in_x : uint, in_y : int) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: in_x,
|
||||||
|
how_hungry: in_y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,6 @@ struct cat {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -33,4 +30,12 @@ struct cat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: in_x,
|
||||||
|
how_hungry: in_y,
|
||||||
|
name: in_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,13 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -8,14 +8,20 @@ struct cat<U> {
|
||||||
|
|
||||||
let how_hungry : int;
|
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]) {
|
fn speak<T>(stuff: ~[T]) {
|
||||||
self.meows += stuff.len();
|
self.meows += stuff.len();
|
||||||
}
|
}
|
||||||
fn meow_count() -> uint { self.meows }
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@ struct cat : ToStr {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -37,4 +34,15 @@ struct cat : ToStr {
|
||||||
|
|
||||||
fn to_str() -> ~str { self.name }
|
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
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,15 @@ export context;
|
||||||
|
|
||||||
struct arc_destruct<T:const> {
|
struct arc_destruct<T:const> {
|
||||||
let _data: int;
|
let _data: int;
|
||||||
new(data: int) { self._data = data; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn arc_destruct<T: const>(data: int) -> arc_destruct<T> {
|
||||||
|
arc_destruct {
|
||||||
|
_data: data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn arc<T: const>(_data: T) -> arc_destruct<T> {
|
fn arc<T: const>(_data: T) -> arc_destruct<T> {
|
||||||
arc_destruct(0)
|
arc_destruct(0)
|
||||||
}
|
}
|
||||||
|
@ -24,11 +29,15 @@ fn init() -> arc_destruct<context_res> unsafe {
|
||||||
struct context_res {
|
struct context_res {
|
||||||
let ctx : int;
|
let ctx : int;
|
||||||
|
|
||||||
new() { self.ctx = 0; }
|
|
||||||
|
|
||||||
drop { }
|
drop { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn context_res() -> context_res {
|
||||||
|
context_res {
|
||||||
|
ctx: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type context = arc_destruct<context_res>;
|
type context = arc_destruct<context_res>;
|
||||||
|
|
||||||
impl context {
|
impl context {
|
||||||
|
|
|
@ -7,7 +7,13 @@ export socket_handle;
|
||||||
|
|
||||||
struct socket_handle {
|
struct socket_handle {
|
||||||
let sockfd: libc::c_int;
|
let sockfd: libc::c_int;
|
||||||
new(x: libc::c_int) {self.sockfd = x;}
|
|
||||||
drop { /* c::close(self.sockfd); */ }
|
drop { /* c::close(self.sockfd); */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn socket_handle(x: libc::c_int) -> socket_handle {
|
||||||
|
socket_handle {
|
||||||
|
sockfd: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,11 @@ fn foo(_x: i32) {
|
||||||
|
|
||||||
struct rsrc {
|
struct rsrc {
|
||||||
let x: i32;
|
let x: i32;
|
||||||
new(x: i32) { self.x = x; }
|
|
||||||
drop { foo(self.x); }
|
drop { foo(self.x); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rsrc(x: i32) -> rsrc {
|
||||||
|
rsrc {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,9 +29,6 @@ fn port<T: send>() -> port<T> {
|
||||||
|
|
||||||
struct port_ptr<T:send> {
|
struct port_ptr<T:send> {
|
||||||
let po: *rust_port;
|
let po: *rust_port;
|
||||||
new(po: *rust_port) {
|
|
||||||
debug!("in the port_ptr constructor");
|
|
||||||
self.po = po; }
|
|
||||||
drop unsafe {
|
drop unsafe {
|
||||||
debug!("in the port_ptr destructor");
|
debug!("in the port_ptr destructor");
|
||||||
do task::unkillable {
|
do task::unkillable {
|
||||||
|
@ -51,6 +48,12 @@ struct port_ptr<T:send> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
* Receive from a port. If no data is available on the port then the
|
||||||
|
|
|
@ -42,10 +42,15 @@ enum st {
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let _l: @nillist;
|
let _l: @nillist;
|
||||||
new(l: @nillist) { self._l = l; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn r(l: @nillist) -> r {
|
||||||
|
r {
|
||||||
|
_l: l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn recurse_or_fail(depth: int, st: Option<st>) {
|
fn recurse_or_fail(depth: int, st: Option<st>) {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
debug!("unwinding %.4f", precise_time_s());
|
debug!("unwinding %.4f", precise_time_s());
|
||||||
|
|
|
@ -98,7 +98,6 @@ fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
|
||||||
|
|
||||||
struct box<T> {
|
struct box<T> {
|
||||||
let mut contents: Option<T>;
|
let mut contents: Option<T>;
|
||||||
new(+x: T) { self.contents = Some(x); }
|
|
||||||
|
|
||||||
fn swap(f: fn(+T) -> T) {
|
fn swap(f: fn(+T) -> T) {
|
||||||
let mut tmp = None;
|
let mut tmp = None;
|
||||||
|
@ -113,6 +112,12 @@ struct box<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn box<T>(+x: T) -> box<T> {
|
||||||
|
box {
|
||||||
|
contents: Some(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mod map_reduce {
|
mod map_reduce {
|
||||||
export putter;
|
export putter;
|
||||||
export getter;
|
export getter;
|
||||||
|
@ -345,10 +350,6 @@ fn is_word_char(c: char) -> bool {
|
||||||
struct random_word_reader: word_reader {
|
struct random_word_reader: word_reader {
|
||||||
let mut remaining: uint;
|
let mut remaining: uint;
|
||||||
let rng: rand::Rng;
|
let rng: rand::Rng;
|
||||||
new(count: uint) {
|
|
||||||
self.remaining = count;
|
|
||||||
self.rng = rand::Rng();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_word() -> Option<~str> {
|
fn read_word() -> Option<~str> {
|
||||||
if self.remaining > 0 {
|
if self.remaining > 0 {
|
||||||
|
@ -359,3 +360,10 @@ struct random_word_reader: word_reader {
|
||||||
else { None }
|
else { None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn random_word_reader(count: uint) -> random_word_reader {
|
||||||
|
random_word_reader {
|
||||||
|
remaining: count,
|
||||||
|
rng: rand::Rng()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,13 @@ struct cat {
|
||||||
let how_hungry : int;
|
let how_hungry : int;
|
||||||
|
|
||||||
fn speak() { self.meows += 1u; }
|
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() {
|
fn main() {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// error-pattern:mismatched types: expected `()` but found `bool`
|
// error-pattern:mismatched types: expected `()` but found `bool`
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
new() {}
|
|
||||||
drop { true }
|
drop { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
struct defer {
|
struct defer {
|
||||||
x: &[&str];
|
x: &[&str];
|
||||||
new(x: &[&str]) { self.x = x; }
|
|
||||||
drop { #error["%?", self.x]; }
|
drop { #error["%?", self.x]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn defer(x: &r/[&r/str]) -> defer/&r {
|
||||||
|
defer {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _x = defer(~["Goodbye", "world!"]); //~ ERROR illegal borrow
|
let _x = defer(~["Goodbye", "world!"]); //~ ERROR illegal borrow
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
struct noncopyable {
|
struct noncopyable {
|
||||||
i: (); new() { self.i = (); } drop { #error["dropped"]; }
|
i: (); drop { #error["dropped"]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn noncopyable() -> noncopyable {
|
||||||
|
noncopyable {
|
||||||
|
i: ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum wrapper = noncopyable;
|
enum wrapper = noncopyable;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
// error-pattern: copying a noncopyable value
|
// 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 {
|
fn to_lambda2(b: foo) -> fn@(uint) -> uint {
|
||||||
// test case where copy clause specifies a value that is not used
|
// test case where copy clause specifies a value that is not used
|
||||||
|
|
|
@ -18,9 +18,6 @@ struct cat : noisy {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -36,6 +33,14 @@ struct cat : noisy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
fn main() {
|
||||||
let nyan : noisy = cat(0u, 2, "nyan") as noisy;
|
let nyan : noisy = cat(0u, 2, "nyan") as noisy;
|
||||||
nyan.eat();
|
nyan.eat();
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
struct cat : int { //~ ERROR trait
|
struct cat : int { //~ ERROR trait
|
||||||
let meows: uint;
|
let meows: uint;
|
||||||
new(in_x : uint) { self.meows = in_x; }
|
}
|
||||||
|
|
||||||
|
fn cat(in_x : uint) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: in_x
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -5,7 +5,12 @@ trait animal {
|
||||||
|
|
||||||
struct cat : animal {
|
struct cat : animal {
|
||||||
let meows: uint;
|
let meows: uint;
|
||||||
new(in_x : uint) { self.meows = in_x; }
|
}
|
||||||
|
|
||||||
|
fn cat(in_x : uint) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: in_x
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ struct cat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new(in_x : uint) { self.meows = in_x; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
struct foo {
|
struct foo {
|
||||||
let i: int;
|
let i: int;
|
||||||
new(i:int) { self.i = i; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo(i:int) -> foo {
|
||||||
|
foo {
|
||||||
|
i: i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() { let x <- foo(10); let y = x; log(error, x); }
|
fn main() { let x <- foo(10); let y = x; log(error, x); }
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
struct t { //~ ERROR this type cannot be instantiated
|
struct t { //~ ERROR this type cannot be instantiated
|
||||||
let x: x;
|
let x: x;
|
||||||
let to_str: ();
|
let to_str: ();
|
||||||
new(x: x) { self.x = x; self.to_str = (); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum x = @t; //~ ERROR this type cannot be instantiated
|
enum x = @t; //~ ERROR this type cannot be instantiated
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
// error-pattern: type cat cannot be dereferenced
|
// error-pattern: type cat cannot be dereferenced
|
||||||
struct cat { new() {} }
|
struct cat {
|
||||||
|
x: ()
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let kitty : cat = cat();
|
let kitty : cat = cat { x: () };
|
||||||
log (error, *kitty);
|
log (error, *kitty);
|
||||||
}
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
// error-pattern: type cat cannot be dereferenced
|
// error-pattern: type cat cannot be dereferenced
|
||||||
struct cat { new() {} }
|
struct cat {
|
||||||
|
foo: ()
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let nyan = cat();
|
let nyan = cat { foo: () };
|
||||||
log (error, *nyan);
|
log (error, *nyan);
|
||||||
}
|
}
|
|
@ -1,8 +1,6 @@
|
||||||
struct socket {
|
struct socket {
|
||||||
let sock: int;
|
let sock: int;
|
||||||
|
|
||||||
new() { self.sock = 1; }
|
|
||||||
|
|
||||||
drop { }
|
drop { }
|
||||||
|
|
||||||
fn set_identity() {
|
fn set_identity() {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
struct c { //~ ERROR a struct must have at least one field
|
struct c { //~ ERROR a struct must have at least one field
|
||||||
new() { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = c();
|
|
||||||
let x = ~[a];
|
|
||||||
let _y = x[0];
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
struct send_packet<T: copy> {
|
struct send_packet<T: copy> {
|
||||||
let p: T;
|
let p: T;
|
||||||
new(p: T) { self.p = p; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
struct example {
|
struct example {
|
||||||
let x: int;
|
let x: int;
|
||||||
new() {
|
|
||||||
self.x = 1;
|
|
||||||
}
|
|
||||||
drop {} //~ ERROR First destructor declared
|
drop {} //~ ERROR First destructor declared
|
||||||
drop {
|
drop {
|
||||||
debug!("Goodbye, cruel world");
|
debug!("Goodbye, cruel world");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn example() -> example {
|
||||||
|
example {
|
||||||
|
x: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main(_args: ~[~str]) {
|
fn main(_args: ~[~str]) {
|
||||||
let e: example = example();
|
let e: example = example();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
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();
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ fn siphash(k0 : u64) {
|
||||||
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
|
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
|
||||||
//~^ ERROR unresolved name: k0
|
//~^ ERROR unresolved name: k0
|
||||||
}
|
}
|
||||||
new() { self.v0 = 0; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#[forbid(non_camel_case_types)]
|
#[forbid(non_camel_case_types)]
|
||||||
struct foo { //~ ERROR type, variant, or trait must be camel case
|
struct foo { //~ ERROR type, variant, or trait must be camel case
|
||||||
let bar: int;
|
let bar: int;
|
||||||
|
|
||||||
new() {
|
|
||||||
self.bar = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
struct cat {
|
|
||||||
let how_hungry : int;
|
|
||||||
fn meow() {}
|
|
||||||
new() {
|
|
||||||
self.meow();
|
|
||||||
//~^ ERROR use of possibly uninitialized field: `self.how_hungry`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
struct cat {
|
|
||||||
let how_hungry : int;
|
|
||||||
new() {} //~ ERROR field `self.how_hungry` is never initialized
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
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() {
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
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();
|
|
||||||
}
|
|
|
@ -50,10 +50,9 @@ fn f4b() -> int {
|
||||||
// leave this in here just to trigger compile-fail:
|
// leave this in here just to trigger compile-fail:
|
||||||
struct r {
|
struct r {
|
||||||
let x: ();
|
let x: ();
|
||||||
new() { self.x = (); }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = r();
|
let x = r { x: () };
|
||||||
fn@() { copy x; }; //~ ERROR copying a noncopyable value
|
fn@() { copy x; }; //~ ERROR copying a noncopyable value
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,13 @@ struct cat {
|
||||||
self.how_hungry -= 5;
|
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() {
|
fn main() {
|
||||||
|
|
|
@ -6,7 +6,13 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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() {
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
struct foo {
|
struct foo {
|
||||||
let _x: comm::Port<()>;
|
let _x: comm::Port<()>;
|
||||||
new(x: comm::Port<()>) { self._x = x; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo(x: comm::Port<()>) -> foo {
|
||||||
|
foo {
|
||||||
|
_x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let x = ~mut Some(foo(comm::Port()));
|
let x = ~mut Some(foo(comm::Port()));
|
||||||
|
|
||||||
do task::spawn |move x| { //~ ERROR not a sendable value
|
do task::spawn |move x| { //~ ERROR not a sendable value
|
||||||
|
|
|
@ -4,16 +4,26 @@ fn foo<T: const>(_x: T) { }
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let x:int;
|
let x:int;
|
||||||
new(x:int) { self.x = x; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn r(x:int) -> r {
|
||||||
|
r {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct r2 {
|
struct r2 {
|
||||||
let x:@mut int;
|
let x:@mut int;
|
||||||
new(x:@mut int) { self.x = x; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn r2(x:@mut int) -> r2 {
|
||||||
|
r2 {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo({f: 3});
|
foo({f: 3});
|
||||||
foo({mut f: 3}); //~ ERROR missing `const`
|
foo({mut f: 3}); //~ ERROR missing `const`
|
||||||
|
|
|
@ -4,14 +4,25 @@
|
||||||
// copied
|
// copied
|
||||||
struct bar {
|
struct bar {
|
||||||
let x: int;
|
let x: int;
|
||||||
new(x:int) {self.x = x;}
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bar(x:int) -> bar {
|
||||||
|
bar {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct foo {
|
struct foo {
|
||||||
let i: int;
|
let i: int;
|
||||||
let j: bar;
|
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); }
|
fn main() { let x <- foo(10); let y = x; log(error, x); }
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let i: @mut int;
|
let i: @mut int;
|
||||||
new(i: @mut int) { self.i = i; }
|
|
||||||
drop { *(self.i) = *(self.i) + 1; }
|
drop { *(self.i) = *(self.i) + 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn r(i: @mut int) -> r {
|
||||||
|
r {
|
||||||
|
i: i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let i = @mut 0;
|
let i = @mut 0;
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,13 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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() {
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
struct my_resource {
|
struct my_resource {
|
||||||
let x: int;
|
let x: int;
|
||||||
new(x: int) { self.x = x; }
|
|
||||||
drop { log(error, self.x); }
|
drop { log(error, self.x); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn my_resource(x: int) -> my_resource {
|
||||||
|
my_resource {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
{
|
{
|
||||||
let a = {x: 0, y: my_resource(20)};
|
let a = {x: 0, y: my_resource(20)};
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
struct dog {
|
struct dog {
|
||||||
let mut cats_chased: uint;
|
let mut cats_chased: uint;
|
||||||
|
|
||||||
new() {
|
|
||||||
self.cats_chased = 0u;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn chase_cat() {
|
fn chase_cat() {
|
||||||
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow
|
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow
|
||||||
*p += 1u;
|
*p += 1u;
|
||||||
|
@ -16,6 +12,12 @@ struct dog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dog() -> dog {
|
||||||
|
dog {
|
||||||
|
cats_chased: 0u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let d = dog();
|
let d = dog();
|
||||||
d.chase_cat();
|
d.chase_cat();
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
struct dog {
|
struct dog {
|
||||||
let mut food: uint;
|
let mut food: uint;
|
||||||
|
|
||||||
new() {
|
|
||||||
self.food = 0u;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn chase_cat() {
|
fn chase_cat() {
|
||||||
for uint::range(0u, 10u) |_i| {
|
for uint::range(0u, 10u) |_i| {
|
||||||
let p: &static/mut uint = &mut self.food; //~ ERROR illegal borrow
|
let p: &static/mut uint = &mut self.food; //~ ERROR illegal borrow
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
enum an_enum = ∫
|
enum an_enum = ∫
|
||||||
trait a_trait { fn foo() -> &self/int; }
|
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 {
|
fn a_fn1(e: an_enum/&a) -> an_enum/&b {
|
||||||
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
|
return e; //~ ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
struct yes0 {
|
struct yes0 {
|
||||||
let x: &uint;
|
let x: &uint;
|
||||||
new(x: &uint) { self.x = x; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct yes1 {
|
struct yes1 {
|
||||||
let x: &self/uint;
|
let x: &self/uint;
|
||||||
new(x: &self/uint) { self.x = x; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct yes2 {
|
struct yes2 {
|
||||||
let x: &foo/uint; //~ ERROR named regions other than `self` are not allowed as part of a type declaration
|
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 {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
struct box_impl<T> {
|
struct box_impl<T> {
|
||||||
let mut f: T;
|
let mut f: T;
|
||||||
|
}
|
||||||
|
|
||||||
new(f: T) {
|
fn box_impl<T>(f: T) -> box_impl<T> {
|
||||||
self.f = f;
|
box_impl {
|
||||||
|
f: f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let b:bool;
|
let b:bool;
|
||||||
new(b: bool) { self.b = b; }
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let i <- ~r(true);
|
let i <- ~r { b: true };
|
||||||
let j = i;
|
let j = i;
|
||||||
log(debug, i);
|
log(debug, i);
|
||||||
}
|
}
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let i: @mut int;
|
let i: @mut int;
|
||||||
new(i: @mut int) { self.i = i; }
|
|
||||||
drop { *(self.i) = *(self.i) + 1; }
|
drop { *(self.i) = *(self.i) + 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +12,8 @@ fn f<T>(+i: ~[T], +j: ~[T]) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let i1 = @mut 0;
|
let i1 = @mut 0;
|
||||||
let i2 = @mut 1;
|
let i2 = @mut 1;
|
||||||
let r1 <- ~[~r(i1)];
|
let r1 <- ~[~r { i: i1 }];
|
||||||
let r2 <- ~[~r(i2)];
|
let r2 <- ~[~r { i: i2 }];
|
||||||
f(r1, r2);
|
f(r1, r2);
|
||||||
log(debug, (r2, *i1));
|
log(debug, (r2, *i1));
|
||||||
log(debug, (r1, *i2));
|
log(debug, (r1, *i2));
|
||||||
|
|
|
@ -4,7 +4,13 @@
|
||||||
struct foo {
|
struct foo {
|
||||||
let i: int;
|
let i: int;
|
||||||
let j: @~str;
|
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() {
|
fn main() {
|
||||||
|
|
|
@ -22,7 +22,6 @@ fn getbig_call_c_and_fail(i: int) {
|
||||||
|
|
||||||
struct and_then_get_big_again {
|
struct and_then_get_big_again {
|
||||||
let x:int;
|
let x:int;
|
||||||
new(x:int) {self.x = x;}
|
|
||||||
drop {
|
drop {
|
||||||
fn getbig(i: int) {
|
fn getbig(i: int) {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
|
@ -33,6 +32,12 @@ struct and_then_get_big_again {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn and_then_get_big_again(x:int) -> and_then_get_big_again {
|
||||||
|
and_then_get_big_again {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
let r = and_then_get_big_again(4);
|
let r = and_then_get_big_again(4);
|
||||||
|
|
|
@ -15,7 +15,6 @@ fn getbig_and_fail(&&i: int) {
|
||||||
|
|
||||||
struct and_then_get_big_again {
|
struct and_then_get_big_again {
|
||||||
let x:int;
|
let x:int;
|
||||||
new(x:int) {self.x = x;}
|
|
||||||
drop {
|
drop {
|
||||||
fn getbig(i: int) {
|
fn getbig(i: int) {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
|
@ -26,6 +25,12 @@ struct and_then_get_big_again {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn and_then_get_big_again(x:int) -> and_then_get_big_again {
|
||||||
|
and_then_get_big_again {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
getbig_and_fail(400);
|
getbig_and_fail(400);
|
||||||
|
|
|
@ -15,10 +15,15 @@ fn getbig_and_fail(&&i: int) {
|
||||||
|
|
||||||
struct and_then_get_big_again {
|
struct and_then_get_big_again {
|
||||||
let x:int;
|
let x:int;
|
||||||
new(x:int) {self.x = x;}
|
|
||||||
drop {}
|
drop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn and_then_get_big_again(x:int) -> and_then_get_big_again {
|
||||||
|
and_then_get_big_again {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
getbig_and_fail(1);
|
getbig_and_fail(1);
|
||||||
|
|
|
@ -8,7 +8,12 @@ struct r {
|
||||||
drop {
|
drop {
|
||||||
os::set_exit_status(50);
|
os::set_exit_status(50);
|
||||||
}
|
}
|
||||||
new(x:int) {self.x = x;}
|
}
|
||||||
|
|
||||||
|
fn r(x:int) -> r {
|
||||||
|
r {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -6,12 +6,17 @@ fn failfn() {
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let v: *int;
|
let v: *int;
|
||||||
new(v: *int) { self.v = v; }
|
|
||||||
drop unsafe {
|
drop unsafe {
|
||||||
let _v2: ~int = unsafe::reinterpret_cast(&self.v);
|
let _v2: ~int = unsafe::reinterpret_cast(&self.v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn r(v: *int) -> r {
|
||||||
|
r {
|
||||||
|
v: v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() unsafe {
|
fn main() unsafe {
|
||||||
let i1 = ~0;
|
let i1 = ~0;
|
||||||
let i1p = unsafe::reinterpret_cast(&i1);
|
let i1p = unsafe::reinterpret_cast(&i1);
|
||||||
|
|
|
@ -80,7 +80,13 @@ extern mod test {
|
||||||
struct p {
|
struct p {
|
||||||
let mut x: int;
|
let mut x: int;
|
||||||
let mut y: 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 {
|
impl p : cmp::Eq {
|
||||||
|
|
|
@ -9,9 +9,11 @@ fn empty<T>() -> Tree<T> { fail }
|
||||||
|
|
||||||
struct Box {
|
struct Box {
|
||||||
let tree: Tree<@Box>;
|
let tree: Tree<@Box>;
|
||||||
|
}
|
||||||
|
|
||||||
new() {
|
fn Box() -> Box {
|
||||||
self.tree = empty();
|
Box {
|
||||||
|
tree: empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
// pp-exact - Make sure we actually print the attributes
|
// pp-exact - Make sure we actually print the attributes
|
||||||
|
|
||||||
struct cat {
|
struct cat {
|
||||||
#[cat_maker]
|
|
||||||
new(name: ~str) { self.name = name; }
|
|
||||||
#[cat_dropper]
|
#[cat_dropper]
|
||||||
drop { error!("%s landed on hir feet",self.name); }
|
drop { error!("%s landed on hir feet",self.name); }
|
||||||
name: ~str,
|
name: ~str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cat_maker]
|
||||||
|
fn cat(name: ~str) -> cat { cat{name: name,} }
|
||||||
|
|
||||||
fn main() { let _kitty = cat(~"Spotty"); }
|
fn main() { let _kitty = cat(~"Spotty"); }
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
struct cat {
|
struct cat {
|
||||||
let name: ~str;
|
let name: ~str;
|
||||||
#[cat_maker]
|
|
||||||
/**
|
|
||||||
Maybe it should technically be a kitten_maker.
|
|
||||||
*/
|
|
||||||
new(name: ~str) { self.name = name; }
|
|
||||||
#[cat_dropper]
|
#[cat_dropper]
|
||||||
/**
|
/**
|
||||||
Actually, cats don't always land on their feet when you drop them.
|
Actually, cats don't always land on their feet when you drop them.
|
||||||
|
@ -12,6 +7,16 @@ struct cat {
|
||||||
drop { error!("%s landed on hir feet", self.name); }
|
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() {
|
fn main() {
|
||||||
let _kitty = cat(~"Spotty");
|
let _kitty = cat(~"Spotty");
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,16 @@ struct dog : noisy {
|
||||||
|
|
||||||
let volume : @mut int;
|
let volume : @mut int;
|
||||||
|
|
||||||
new() { self.volume = @mut 0; self.barks = @mut 0u; }
|
|
||||||
|
|
||||||
fn speak() -> int { self.bark() }
|
fn speak() -> int { self.bark() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dog() -> dog {
|
||||||
|
dog {
|
||||||
|
volume: @mut 0,
|
||||||
|
barks: @mut 0u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct cat : noisy {
|
struct cat : noisy {
|
||||||
priv {
|
priv {
|
||||||
let meows : @mut uint;
|
let meows : @mut uint;
|
||||||
|
@ -42,14 +47,19 @@ struct cat : noisy {
|
||||||
let how_hungry : @mut int;
|
let how_hungry : @mut int;
|
||||||
let name : ~str;
|
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 speak() -> int { self.meow() as int }
|
||||||
fn meow_count() -> uint { *self.meows }
|
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) {
|
fn annoy_neighbors<T: noisy>(critter: T) {
|
||||||
for uint::range(0u, 10u) |i| { critter.speak(); }
|
for uint::range(0u, 10u) |i| { critter.speak(); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,6 @@ struct cat : noisy {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -35,6 +32,15 @@ struct cat : noisy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
fn main() {
|
||||||
let nyan : noisy = cat(0u, 2, ~"nyan") as noisy;
|
let nyan : noisy = cat(0u, 2, ~"nyan") as noisy;
|
||||||
nyan.speak();
|
nyan.speak();
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
struct cat {
|
struct cat {
|
||||||
let done : extern fn(uint);
|
let done : extern fn(uint);
|
||||||
let meows : uint;
|
let meows : uint;
|
||||||
new(done: extern fn(uint)) {
|
|
||||||
self.meows = 0u;
|
|
||||||
self.done = done;
|
|
||||||
}
|
|
||||||
drop { self.done(self.meows); }
|
drop { self.done(self.meows); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cat(done: extern fn(uint)) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: 0u,
|
||||||
|
done: done
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -10,8 +10,15 @@ mod kitty {
|
||||||
let name: ~str;
|
let name: ~str;
|
||||||
|
|
||||||
fn get_name() -> ~str { self.name }
|
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() {
|
fn main() {
|
||||||
|
|
|
@ -29,9 +29,6 @@ struct cat<T: copy> : map<int, T> {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : T;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -96,6 +93,13 @@ struct cat<T: copy> : map<int, T> {
|
||||||
fn clear() { }
|
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() {
|
fn main() {
|
||||||
let nyan : cat<~str> = cat(0, 2, ~"nyan");
|
let nyan : cat<~str> = cat(0, 2, ~"nyan");
|
||||||
|
|
|
@ -18,9 +18,6 @@ struct cat : noisy {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -36,6 +33,15 @@ struct cat : noisy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
fn main() {
|
||||||
let nyan = cat(0u, 2, ~"nyan");
|
let nyan = cat(0u, 2, ~"nyan");
|
||||||
nyan.eat();
|
nyan.eat();
|
||||||
|
|
|
@ -17,9 +17,6 @@ struct cat : noisy {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -35,6 +32,15 @@ struct cat : noisy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
fn make_speak<C: noisy>(c: C) {
|
||||||
c.speak();
|
c.speak();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,17 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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 speak() { self.meows += 1u; }
|
||||||
fn meow_count() -> uint { self.meows }
|
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() {
|
fn main() {
|
||||||
let nyan : cat = cat(52u, 99);
|
let nyan : cat = cat(52u, 99);
|
||||||
let kitty = cat(1000u, 2);
|
let kitty = cat(1000u, 2);
|
||||||
|
|
|
@ -6,16 +6,20 @@ struct cat<U> {
|
||||||
|
|
||||||
let how_hungry : int;
|
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]) {
|
fn speak<T>(stuff: ~[T]) {
|
||||||
self.meows += stuff.len();
|
self.meows += stuff.len();
|
||||||
}
|
}
|
||||||
fn meow_count() -> uint { self.meows }
|
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() {
|
fn main() {
|
||||||
let nyan : cat<int> = cat::<int>(52u, 99, ~[9]);
|
let nyan : cat<int> = cat::<int>(52u, 99, ~[9]);
|
||||||
let kitty = cat(1000u, 2, ~[~"tabby"]);
|
let kitty = cat(1000u, 2, ~[~"tabby"]);
|
||||||
|
|
|
@ -17,9 +17,6 @@ struct cat {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -35,6 +32,14 @@ struct cat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
impl cat: ToStr {
|
||||||
fn to_str() -> ~str { self.name }
|
fn to_str() -> ~str { self.name }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,12 @@ struct cat {
|
||||||
|
|
||||||
let name : ~str;
|
let name : ~str;
|
||||||
|
|
||||||
new(in_name: ~str)
|
}
|
||||||
{ self.name = in_name; }
|
|
||||||
|
fn cat(in_name: ~str) -> cat {
|
||||||
|
cat {
|
||||||
|
name: in_name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -5,14 +5,20 @@ struct cat<U> {
|
||||||
|
|
||||||
let how_hungry : int;
|
let how_hungry : int;
|
||||||
|
|
||||||
new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
|
|
||||||
|
|
||||||
fn speak() {
|
fn speak() {
|
||||||
self.meows += 1u;
|
self.meows += 1u;
|
||||||
}
|
}
|
||||||
fn meow_count() -> uint { self.meows }
|
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() {
|
fn main() {
|
||||||
let _nyan : cat<int> = cat::<int>(52u, 99);
|
let _nyan : cat<int> = cat::<int>(52u, 99);
|
||||||
// let kitty = cat(1000u, 2);
|
// let kitty = cat(1000u, 2);
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
struct kitten {
|
struct kitten {
|
||||||
let cat: Option<cat>;
|
let cat: Option<cat>;
|
||||||
new(cat: Option<cat>) {
|
}
|
||||||
self.cat = cat;
|
|
||||||
|
fn kitten(cat: Option<cat>) -> kitten {
|
||||||
|
kitten {
|
||||||
|
cat: cat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,16 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
let how_hungry : int;
|
||||||
|
|
||||||
new(in_x : uint, in_y : int) { self.meows = in_x; self.how_hungry = in_y; }
|
|
||||||
|
|
||||||
fn speak() {}
|
fn speak() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cat(in_x : uint, in_y : int) -> cat {
|
||||||
|
cat {
|
||||||
|
meows: in_x,
|
||||||
|
how_hungry: in_y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let nyan : cat = cat(52u, 99);
|
let nyan : cat = cat(52u, 99);
|
||||||
let kitty = cat(1000u, 2);
|
let kitty = cat(1000u, 2);
|
||||||
|
|
|
@ -5,7 +5,13 @@ struct cat {
|
||||||
|
|
||||||
let how_hungry : int;
|
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() {
|
||||||
|
|
|
@ -13,9 +13,6 @@ struct cat {
|
||||||
let mut how_hungry : int;
|
let mut how_hungry : int;
|
||||||
let name : ~str;
|
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 speak() { self.meow(); }
|
||||||
|
|
||||||
fn eat() -> bool {
|
fn eat() -> bool {
|
||||||
|
@ -31,6 +28,14 @@ struct cat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
fn main() {
|
||||||
let nyan = cat(0u, 2, ~"nyan");
|
let nyan = cat(0u, 2, ~"nyan");
|
||||||
nyan.eat();
|
nyan.eat();
|
||||||
|
|
|
@ -27,12 +27,23 @@ enum tg { bar, }
|
||||||
#[cfg(bogus)]
|
#[cfg(bogus)]
|
||||||
struct r {
|
struct r {
|
||||||
let i: int;
|
let i: int;
|
||||||
new(i:int) { self.i = i; }
|
}
|
||||||
|
|
||||||
|
#[cfg(bogus)]
|
||||||
|
fn r(i:int) -> r {
|
||||||
|
r {
|
||||||
|
i: i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let i: int;
|
let i: int;
|
||||||
new(i:int) { self.i = i; }
|
}
|
||||||
|
|
||||||
|
fn r(i:int) -> r {
|
||||||
|
r {
|
||||||
|
i: i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(bogus)]
|
#[cfg(bogus)]
|
||||||
|
|
|
@ -34,9 +34,13 @@ fn select_based_on_unit_circle<T>(
|
||||||
|
|
||||||
struct thing {
|
struct thing {
|
||||||
x: {mut a: @int};
|
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 {
|
impl thing {
|
||||||
fn foo(@self) -> int { *self.x.a }
|
fn foo(@self) -> int { *self.x.a }
|
||||||
|
|
|
@ -3,12 +3,15 @@
|
||||||
|
|
||||||
struct r {
|
struct r {
|
||||||
let i: @mut int;
|
let i: @mut int;
|
||||||
new(i: @mut int) {
|
|
||||||
self.i = i;
|
|
||||||
}
|
|
||||||
drop { *(self.i) = *(self.i) + 1; }
|
drop { *(self.i) = *(self.i) + 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn r(i: @mut int) -> r {
|
||||||
|
r {
|
||||||
|
i: i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn test_box() {
|
fn test_box() {
|
||||||
let i = @mut 0;
|
let i = @mut 0;
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,11 +3,16 @@ trait clam<A: copy> {
|
||||||
}
|
}
|
||||||
struct foo<A: copy> : clam<A> {
|
struct foo<A: copy> : clam<A> {
|
||||||
let x: A;
|
let x: A;
|
||||||
new(b: A) { self.x = b; }
|
|
||||||
fn chowder(y: A) {
|
fn chowder(y: A) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo<A: copy>(b: A) -> foo<A> {
|
||||||
|
foo {
|
||||||
|
x: b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn f<A: copy>(x: clam<A>, a: A) {
|
fn f<A: copy>(x: clam<A>, a: A) {
|
||||||
x.chowder(a);
|
x.chowder(a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
trait clam<A: copy> { }
|
trait clam<A: copy> { }
|
||||||
struct foo<A: copy> {
|
struct foo<A: copy> {
|
||||||
let x: A;
|
let x: A;
|
||||||
new(b: A) { self.x = b; }
|
|
||||||
fn bar<B,C:clam<A>>(c: C) -> B {
|
fn bar<B,C:clam<A>>(c: C) -> B {
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo<A: copy>(b: A) -> foo<A> {
|
||||||
|
foo {
|
||||||
|
x: b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
struct c1<T: copy> {
|
struct c1<T: copy> {
|
||||||
let x: T;
|
let x: T;
|
||||||
new(x: T) {self.x = x;}
|
|
||||||
|
|
||||||
fn f1(x: int) {
|
fn f1(x: int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn c1<T: copy>(x: T) -> c1<T> {
|
||||||
|
c1 {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: copy> c1<T> {
|
impl<T: copy> c1<T> {
|
||||||
fn f2(x: int) {
|
fn f2(x: int) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,15 @@ use dvec::DVec;
|
||||||
|
|
||||||
struct c1<T: copy> {
|
struct c1<T: copy> {
|
||||||
let x: T;
|
let x: T;
|
||||||
new(x: T) {self.x = x;}
|
|
||||||
|
|
||||||
fn f1(x: T) {}
|
fn f1(x: T) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn c1<T: copy>(x: T) -> c1<T> {
|
||||||
|
c1 {
|
||||||
|
x: x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: copy> c1<T> {
|
impl<T: copy> c1<T> {
|
||||||
fn f2(x: T) {}
|
fn f2(x: T) {}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue