From 12a0401d84dc033fc4e03484b334de3cb20bab30 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 25 Sep 2012 15:15:42 -0700 Subject: Change method res to try autoref more often. Fixes #3585. --- .../autoref-intermediate-types-issue-3585.rs | 20 ++++++++++++++++++++ src/test/run-pass/autoref-vec-push.rs | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/test/run-pass/autoref-intermediate-types-issue-3585.rs create mode 100644 src/test/run-pass/autoref-vec-push.rs (limited to 'src/test') diff --git a/src/test/run-pass/autoref-intermediate-types-issue-3585.rs b/src/test/run-pass/autoref-intermediate-types-issue-3585.rs new file mode 100644 index 00000000000..68e172bacad --- /dev/null +++ b/src/test/run-pass/autoref-intermediate-types-issue-3585.rs @@ -0,0 +1,20 @@ +trait Foo { + fn foo(&self) -> ~str; +} + +impl @T: Foo { + fn foo(&self) -> ~str { + fmt!("@%s", (**self).foo()) + } +} + +impl uint: Foo { + fn foo(&self) -> ~str { + fmt!("%u", *self) + } +} + +fn main() { + let x = @3u; + assert x.foo() == ~"@3"; +} \ No newline at end of file diff --git a/src/test/run-pass/autoref-vec-push.rs b/src/test/run-pass/autoref-vec-push.rs new file mode 100644 index 00000000000..cb70a1810b7 --- /dev/null +++ b/src/test/run-pass/autoref-vec-push.rs @@ -0,0 +1,17 @@ +trait VecPush { + fn push(&mut self, +t: T); +} + +impl ~[T]: VecPush { + fn push(&mut self, +t: T) { + vec::push(*self, t); + } +} + +fn main() { + let mut x = ~[]; + x.push(1); + x.push(2); + x.push(3); + assert x == ~[1, 2, 3]; +} \ No newline at end of file -- cgit 1.4.1-3-g733a5 From fdd48dd903e07bdb107bcc82a97daf533285120c Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 25 Sep 2012 15:22:28 -0700 Subject: Respect privacy qualifiers on view items, add to import resolutions. --- src/rustc/middle/resolve.rs | 130 ++++++++++++++++++++--------------- src/rustc/rustc.rc | 1 + src/test/auxiliary/cci_class.rs | 1 + src/test/auxiliary/cci_class_2.rs | 2 + src/test/auxiliary/cci_class_3.rs | 2 + src/test/auxiliary/cci_class_4.rs | 1 + src/test/auxiliary/cci_class_6.rs | 2 + src/test/auxiliary/cci_class_cast.rs | 2 + src/test/auxiliary/crateresolve7x.rs | 1 + src/test/auxiliary/foreign_lib.rs | 1 + src/test/auxiliary/issue-3012-1.rs | 1 + 11 files changed, 90 insertions(+), 54 deletions(-) (limited to 'src/test') diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index f7c389e67ff..afb1cbc36f4 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -167,8 +167,8 @@ enum CaptureClause { type ResolveVisitor = vt<()>; enum ModuleDef { - NoModuleDef, // Does not define a module. - ModuleDef(@Module), // Defines a module. + NoModuleDef, // Does not define a module. + ModuleDef(Privacy, @Module), // Defines a module. } impl ModuleDef { @@ -333,15 +333,18 @@ fn Rib(kind: RibKind) -> Rib { /// One import directive. struct ImportDirective { + privacy: Privacy, module_path: @DVec, subclass: @ImportDirectiveSubclass, span: span, } -fn ImportDirective(module_path: @DVec, +fn ImportDirective(privacy: Privacy, + module_path: @DVec, subclass: @ImportDirectiveSubclass, span: span) -> ImportDirective { ImportDirective { + privacy: privacy, module_path: module_path, subclass: subclass, span: span @@ -362,6 +365,7 @@ fn Target(target_module: @Module, bindings: @NameBindings) -> Target { } struct ImportResolution { + privacy: Privacy, span: span, // The number of outstanding references to this name. When this reaches @@ -377,8 +381,10 @@ struct ImportResolution { mut used: bool, } -fn ImportResolution(span: span) -> ImportResolution { +fn ImportResolution(privacy: Privacy, + span: span) -> ImportResolution { ImportResolution { + privacy: privacy, span: span, outstanding_references: 0u, module_target: None, @@ -533,13 +539,14 @@ struct NameBindings { impl NameBindings { /// Creates a new module in this set of name bindings. - fn define_module(parent_link: ParentLink, + fn define_module(privacy: Privacy, + parent_link: ParentLink, def_id: Option, legacy_exports: bool, sp: span) { if self.module_def.is_none() { let module_ = @Module(parent_link, def_id, legacy_exports); - self.module_def = ModuleDef(module_); + self.module_def = ModuleDef(privacy, module_); self.module_span = Some(sp); } } @@ -560,7 +567,7 @@ impl NameBindings { fn get_module_if_available() -> Option<@Module> { match self.module_def { NoModuleDef => return None, - ModuleDef(module_) => return Some(module_) + ModuleDef(_privacy, module_) => return Some(module_) } } @@ -574,7 +581,7 @@ impl NameBindings { fail ~"get_module called on a node with no module definition!"; } - ModuleDef(module_) => { + ModuleDef(_, module_) => { return module_; } } @@ -599,12 +606,12 @@ impl NameBindings { ValueNS => return self.value_def, ModuleNS => match self.module_def { NoModuleDef => return None, - ModuleDef(module_) => + ModuleDef(privacy, module_) => match module_.def_id { None => return None, Some(def_id) => { return Some(Definition { - privacy: Public, + privacy: privacy, def: def_mod(def_id) }); } @@ -703,7 +710,8 @@ fn Resolver(session: session, lang_items: LanguageItems, let graph_root = @NameBindings(); - (*graph_root).define_module(NoParentLink, + (*graph_root).define_module(Public, + NoParentLink, Some({ crate: 0, node: 0 }), has_legacy_export_attr(crate.node.attrs), crate.span); @@ -991,6 +999,7 @@ impl Resolver { let legacy = match parent { ModuleReducedGraphParent(m) => m.legacy_exports }; + let privacy = self.visibility_to_privacy(item.vis, legacy); match item.node { item_mod(module_) => { @@ -1000,8 +1009,8 @@ impl Resolver { let parent_link = self.get_parent_link(new_parent, atom); let def_id = { crate: 0, node: item.id }; - (*name_bindings).define_module(parent_link, Some(def_id), - legacy, sp); + (*name_bindings).define_module(privacy, parent_link, + Some(def_id), legacy, sp); let new_parent = ModuleReducedGraphParent((*name_bindings).get_module()); @@ -1017,8 +1026,8 @@ impl Resolver { let parent_link = self.get_parent_link(new_parent, atom); let def_id = { crate: 0, node: item.id }; - (*name_bindings).define_module(parent_link, Some(def_id), - legacy, sp); + (*name_bindings).define_module(privacy, parent_link, + Some(def_id), legacy, sp); ModuleReducedGraphParent((*name_bindings).get_module()) } @@ -1036,17 +1045,14 @@ impl Resolver { ~[ValueNS], sp); (*name_bindings).define_value - (self.visibility_to_privacy(item.vis, legacy), - def_const(local_def(item.id)), - sp); + (privacy, def_const(local_def(item.id)), sp); } item_fn(_, purity, _, _) => { let (name_bindings, new_parent) = self.add_child(atom, parent, ~[ValueNS], sp); let def = def_fn(local_def(item.id), purity); - (*name_bindings).define_value - (self.visibility_to_privacy(item.vis, legacy), def, sp); + (*name_bindings).define_value(privacy, def, sp); visit_item(item, new_parent, visitor); } @@ -1056,9 +1062,7 @@ impl Resolver { ~[TypeNS], sp); (*name_bindings).define_type - (self.visibility_to_privacy(item.vis, legacy), - def_ty(local_def(item.id)), - sp); + (privacy, def_ty(local_def(item.id)), sp); } item_enum(enum_definition, _) => { @@ -1067,9 +1071,7 @@ impl Resolver { ~[TypeNS], sp); (*name_bindings).define_type - (self.visibility_to_privacy(item.vis, legacy), - def_ty(local_def(item.id)), - sp); + (privacy, def_ty(local_def(item.id)), sp); for enum_definition.variants.each |variant| { self.build_reduced_graph_for_variant(*variant, @@ -1088,9 +1090,7 @@ impl Resolver { self.add_child(atom, parent, ~[TypeNS], sp); (*name_bindings).define_type - (self.visibility_to_privacy(item.vis, legacy), - def_ty(local_def(item.id)), - sp); + (privacy, def_ty(local_def(item.id)), sp); new_parent } Some(ctor) => { @@ -1098,9 +1098,6 @@ impl Resolver { self.add_child(atom, parent, ~[ValueNS, TypeNS], sp); - let privacy = self.visibility_to_privacy(item.vis, - legacy); - (*name_bindings).define_type (privacy, def_ty(local_def(item.id)), sp); @@ -1156,7 +1153,7 @@ impl Resolver { self.trait_info.insert(def_id, method_names); (*name_bindings).define_type - (self.visibility_to_privacy(item.vis, legacy), + (privacy, def_ty(def_id), sp); visit_item(item, new_parent, visitor); @@ -1218,6 +1215,10 @@ impl Resolver { parent: ReducedGraphParent, &&_visitor: vt) { + let legacy = match parent { + ModuleReducedGraphParent(m) => m.legacy_exports + }; + let privacy = self.visibility_to_privacy(view_item.vis, legacy); match view_item.node { view_item_import(view_paths) => { for view_paths.each |view_path| { @@ -1259,7 +1260,8 @@ impl Resolver { let subclass = @SingleImport(binding, source_ident, ns); - self.build_import_directive(module_, + self.build_import_directive(privacy, + module_, module_path, subclass, view_path.span); @@ -1270,14 +1272,16 @@ impl Resolver { let subclass = @SingleImport(name, name, AnyNS); - self.build_import_directive(module_, + self.build_import_directive(privacy, + module_, module_path, subclass, view_path.span); } } view_path_glob(_, _) => { - self.build_import_directive(module_, + self.build_import_directive(privacy, + module_, module_path, @GlobImport, view_path.span); @@ -1356,7 +1360,8 @@ impl Resolver { let parent_link = ModuleParentLink (self.get_module_from_parent(new_parent), name); - (*child_name_bindings).define_module(parent_link, + (*child_name_bindings).define_module(privacy, + parent_link, Some(def_id), false, view_item.span); @@ -1440,7 +1445,8 @@ impl Resolver { match modules.find(def_id) { None => { - child_name_bindings.define_module(parent_link, + child_name_bindings.define_module(Public, + parent_link, Some(def_id), false, dummy_sp()); @@ -1452,7 +1458,7 @@ impl Resolver { // avoid creating cycles in the // module graph. - let resolution = @ImportResolution(dummy_sp()); + let resolution = @ImportResolution(Public, dummy_sp()); resolution.outstanding_references = 0; match existing_module.parent_link { @@ -1476,7 +1482,7 @@ impl Resolver { } } } - ModuleDef(module_) => { + ModuleDef(_priv, module_) => { debug!("(building reduced graph for \ external crate) already created \ module"); @@ -1585,11 +1591,12 @@ impl Resolver { autovivifying %s", *ident_str); let parent_link = self.get_parent_link(new_parent, ident); - (*child_name_bindings).define_module(parent_link, - None, false, + (*child_name_bindings).define_module(Public, + parent_link, + None, false, dummy_sp()); } - ModuleDef(_) => { /* Fall through. */ } + ModuleDef(*) => { /* Fall through. */ } } current_module = (*child_name_bindings).get_module(); @@ -1625,12 +1632,14 @@ impl Resolver { } /// Creates and adds an import directive to the given module. - fn build_import_directive(module_: @Module, + fn build_import_directive(privacy: Privacy, + module_: @Module, module_path: @DVec, subclass: @ImportDirectiveSubclass, span: span) { - let directive = @ImportDirective(module_path, subclass, span); + let directive = @ImportDirective(privacy, module_path, + subclass, span); module_.imports.push(directive); // Bump the reference count on the name. Or, if this is a glob, set @@ -1643,7 +1652,7 @@ impl Resolver { resolution.outstanding_references += 1u; } None => { - let resolution = @ImportResolution(span); + let resolution = @ImportResolution(privacy, span); resolution.outstanding_references = 1u; module_.import_resolutions.insert(target, resolution); } @@ -1829,8 +1838,9 @@ impl Resolver { } GlobImport => { let span = import_directive.span; + let p = import_directive.privacy; resolution_result = - self.resolve_glob_import(module_, + self.resolve_glob_import(p, module_, containing_module, span); } @@ -2196,7 +2206,8 @@ impl Resolver { * succeeds or bails out (as importing * from an empty module or a module * that exports nothing is valid). */ - fn resolve_glob_import(module_: @Module, + fn resolve_glob_import(privacy: Privacy, + module_: @Module, containing_module: @Module, span: span) -> ResolveResult<()> { @@ -2236,7 +2247,8 @@ impl Resolver { None => { // Simple: just copy the old import resolution. let new_import_resolution = - @ImportResolution(target_import_resolution.span); + @ImportResolution(privacy, + target_import_resolution.span); new_import_resolution.module_target = copy target_import_resolution.module_target; new_import_resolution.value_target = @@ -2294,7 +2306,8 @@ impl Resolver { match module_.import_resolutions.find(atom) { None => { // Create a new import resolution from this child. - dest_import_resolution = @ImportResolution(span); + dest_import_resolution = @ImportResolution(privacy, + span); module_.import_resolutions.insert (atom, dest_import_resolution); } @@ -2372,7 +2385,7 @@ impl Resolver { str_of(name))); return Failed; } - ModuleDef(copy module_) => { + ModuleDef(_, copy module_) => { search_module = module_; } } @@ -2528,7 +2541,7 @@ impl Resolver { wasn't actually a module!"); return Failed; } - ModuleDef(module_) => { + ModuleDef(_, module_) => { return Success(module_); } } @@ -2892,6 +2905,11 @@ impl Resolver { for [ModuleNS, TypeNS, ValueNS].each |ns| { match namebindings.def_for_namespace(*ns) { Some(d) if d.privacy == Public => { + debug!("(computing exports) YES: %s '%s' \ + => %?", + if reexport { ~"reexport" } else { ~"export"}, + self.session.str_of(atom), + def_id_of_def(d.def)); vec::push(*exports2, Export2 { reexport: reexport, name: self.session.str_of(atom), @@ -2906,6 +2924,8 @@ impl Resolver { fn add_exports_for_module(exports2: &mut ~[Export2], module_: @Module) { for module_.children.each_ref |atom, namebindings| { + debug!("(computing exports) maybe export '%s'", + self.session.str_of(*atom)); self.add_exports_of_namebindings(exports2, *atom, *namebindings, false) } @@ -2914,6 +2934,8 @@ impl Resolver { for [ModuleNS, TypeNS, ValueNS].each |ns| { match importresolution.target_for_namespace(*ns) { Some(target) => { + debug!("(computing exports) maybe reexport '%s'", + self.session.str_of(*atom)); self.add_exports_of_namebindings(exports2, *atom, target.bindings, true) @@ -2936,7 +2958,7 @@ impl Resolver { // Nothing to do. } ChildNameDefinition(target_def) => { - debug!("(computing exports) found child export '%s' \ + debug!("(computing exports) legacy export '%s' \ for %?", self.session.str_of(name), module_.def_id); @@ -2947,7 +2969,7 @@ impl Resolver { }); } ImportNameDefinition(target_def) => { - debug!("(computing exports) found reexport '%s' for \ + debug!("(computing exports) legacy reexport '%s' for \ %?", self.session.str_of(name), module_.def_id); diff --git a/src/rustc/rustc.rc b/src/rustc/rustc.rc index ca5491245e0..c021a4e2854 100644 --- a/src/rustc/rustc.rc +++ b/src/rustc/rustc.rc @@ -12,6 +12,7 @@ #[no_core]; #[legacy_modes]; +#[legacy_exports]; #[allow(vecs_implicitly_copyable)]; #[allow(non_camel_case_types)]; diff --git a/src/test/auxiliary/cci_class.rs b/src/test/auxiliary/cci_class.rs index 8f4055cd415..bb286f956bc 100644 --- a/src/test/auxiliary/cci_class.rs +++ b/src/test/auxiliary/cci_class.rs @@ -1,3 +1,4 @@ +#[legacy_exports]; mod kitties { #[legacy_exports]; diff --git a/src/test/auxiliary/cci_class_2.rs b/src/test/auxiliary/cci_class_2.rs index e572f41322c..186f021a81f 100644 --- a/src/test/auxiliary/cci_class_2.rs +++ b/src/test/auxiliary/cci_class_2.rs @@ -1,3 +1,5 @@ +#[legacy_exports]; + mod kitties { #[legacy_exports]; diff --git a/src/test/auxiliary/cci_class_3.rs b/src/test/auxiliary/cci_class_3.rs index 79583a6134c..dbae452a8f9 100644 --- a/src/test/auxiliary/cci_class_3.rs +++ b/src/test/auxiliary/cci_class_3.rs @@ -1,3 +1,5 @@ +#[legacy_exports]; + mod kitties { #[legacy_exports]; diff --git a/src/test/auxiliary/cci_class_4.rs b/src/test/auxiliary/cci_class_4.rs index 57c6f2f4b52..436f92e5e78 100644 --- a/src/test/auxiliary/cci_class_4.rs +++ b/src/test/auxiliary/cci_class_4.rs @@ -1,3 +1,4 @@ +#[legacy_exports]; mod kitties { #[legacy_exports]; diff --git a/src/test/auxiliary/cci_class_6.rs b/src/test/auxiliary/cci_class_6.rs index 72262781222..6cf86aff055 100644 --- a/src/test/auxiliary/cci_class_6.rs +++ b/src/test/auxiliary/cci_class_6.rs @@ -1,3 +1,5 @@ +#[legacy_exports]; + mod kitties { #[legacy_exports]; diff --git a/src/test/auxiliary/cci_class_cast.rs b/src/test/auxiliary/cci_class_cast.rs index 550dfb6886a..288fe66dd20 100644 --- a/src/test/auxiliary/cci_class_cast.rs +++ b/src/test/auxiliary/cci_class_cast.rs @@ -1,3 +1,5 @@ +#[legacy_exports]; + use to_str::*; use to_str::ToStr; diff --git a/src/test/auxiliary/crateresolve7x.rs b/src/test/auxiliary/crateresolve7x.rs index 520a207345f..e7bf211d3f0 100644 --- a/src/test/auxiliary/crateresolve7x.rs +++ b/src/test/auxiliary/crateresolve7x.rs @@ -3,6 +3,7 @@ // aux-build:crateresolve_calories-2.rs // These both have the same version but differ in other metadata +#[legacy_exports]; mod a { #[legacy_exports]; extern mod cr_1 (name = "crateresolve_calories", vers = "0.1", calories="100"); diff --git a/src/test/auxiliary/foreign_lib.rs b/src/test/auxiliary/foreign_lib.rs index 6ea28255421..bb6d425de34 100644 --- a/src/test/auxiliary/foreign_lib.rs +++ b/src/test/auxiliary/foreign_lib.rs @@ -1,4 +1,5 @@ #[link(name="foreign_lib", vers="0.0")]; +#[legacy_exports]; extern mod rustrt { #[legacy_exports]; diff --git a/src/test/auxiliary/issue-3012-1.rs b/src/test/auxiliary/issue-3012-1.rs index a9d371321f8..d774669cd13 100644 --- a/src/test/auxiliary/issue-3012-1.rs +++ b/src/test/auxiliary/issue-3012-1.rs @@ -1,5 +1,6 @@ #[link(name="socketlib", vers="0.0")]; #[crate_type = "lib"]; +#[legacy_exports]; mod socket { #[legacy_exports]; -- cgit 1.4.1-3-g733a5 From e85a3d82470e2e45db370b62e4fd54175c4b144d Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 25 Sep 2012 15:15:49 -0700 Subject: Demode Num trait and impls --- src/libcore/f32.rs | 10 +++---- src/libcore/f64.rs | 10 +++---- src/libcore/float.rs | 36 +++++++++++++------------- src/libcore/int-template.rs | 20 +++++++------- src/libcore/num.rs | 10 +++---- src/libcore/str.rs | 2 +- src/libcore/uint-template.rs | 10 +++---- src/test/run-pass/numeric-method-autoexport.rs | 20 +++++++------- 8 files changed, 59 insertions(+), 59 deletions(-) (limited to 'src/test') diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs index a8ca15f6afc..f5e4d629726 100644 --- a/src/libcore/f32.rs +++ b/src/libcore/f32.rs @@ -158,11 +158,11 @@ pure fn logarithm(n: f32, b: f32) -> f32 { } impl f32: num::Num { - pure fn add(&&other: f32) -> f32 { return self + other; } - pure fn sub(&&other: f32) -> f32 { return self - other; } - pure fn mul(&&other: f32) -> f32 { return self * other; } - pure fn div(&&other: f32) -> f32 { return self / other; } - pure fn modulo(&&other: f32) -> f32 { return self % other; } + pure fn add(other: &f32) -> f32 { return self + *other; } + pure fn sub(other: &f32) -> f32 { return self - *other; } + pure fn mul(other: &f32) -> f32 { return self * *other; } + pure fn div(other: &f32) -> f32 { return self / *other; } + pure fn modulo(other: &f32) -> f32 { return self % *other; } pure fn neg() -> f32 { return -self; } pure fn to_int() -> int { return self as int; } diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs index 0be0a059132..56f9cd85db9 100644 --- a/src/libcore/f64.rs +++ b/src/libcore/f64.rs @@ -185,11 +185,11 @@ pure fn logarithm(n: f64, b: f64) -> f64 { } impl f64: num::Num { - pure fn add(&&other: f64) -> f64 { return self + other; } - pure fn sub(&&other: f64) -> f64 { return self - other; } - pure fn mul(&&other: f64) -> f64 { return self * other; } - pure fn div(&&other: f64) -> f64 { return self / other; } - pure fn modulo(&&other: f64) -> f64 { return self % other; } + pure fn add(other: &f64) -> f64 { return self + *other; } + pure fn sub(other: &f64) -> f64 { return self - *other; } + pure fn mul(other: &f64) -> f64 { return self * *other; } + pure fn div(other: &f64) -> f64 { return self / *other; } + pure fn modulo(other: &f64) -> f64 { return self % *other; } pure fn neg() -> f64 { return -self; } pure fn to_int() -> int { return self as int; } diff --git a/src/libcore/float.rs b/src/libcore/float.rs index 2cd95269aaf..eaa51814056 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -139,7 +139,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { // while we still need digits // build stack of digits - while ii > 0u && (frac >= epsilon_prime || exact) { + while ii > 0 && (frac >= epsilon_prime || exact) { // store the next digit frac *= 10.0; let digit = frac as uint; @@ -153,25 +153,25 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { let mut acc; let mut racc = ~""; - let mut carry = if frac * 10.0 as uint >= 5u { 1u } else { 0u }; + let mut carry = if frac * 10.0 as uint >= 5 { 1 } else { 0 }; // turn digits into string // using stack of digits - while vec::len(fractionalParts) > 0u { + while fractionalParts.is_not_empty() { let mut adjusted_digit = carry + vec::pop(fractionalParts); - if adjusted_digit == 10u { - carry = 1u; - adjusted_digit %= 10u + if adjusted_digit == 10 { + carry = 1; + adjusted_digit %= 10 } else { - carry = 0u + carry = 0; }; racc = uint::str(adjusted_digit) + racc; } // pad decimals with trailing zeroes - while str::len(racc) < digits && exact { + while racc.len() < digits && exact { racc += ~"0" } @@ -428,11 +428,11 @@ impl float : Ord { } impl float: num::Num { - pure fn add(&&other: float) -> float { return self + other; } - pure fn sub(&&other: float) -> float { return self - other; } - pure fn mul(&&other: float) -> float { return self * other; } - pure fn div(&&other: float) -> float { return self / other; } - pure fn modulo(&&other: float) -> float { return self % other; } + pure fn add(other: &float) -> float { return self + *other; } + pure fn sub(other: &float) -> float { return self - *other; } + pure fn mul(other: &float) -> float { return self * *other; } + pure fn div(other: &float) -> float { return self / *other; } + pure fn modulo(other: &float) -> float { return self % *other; } pure fn neg() -> float { return -self; } pure fn to_int() -> int { return self as int; } @@ -540,11 +540,11 @@ fn test_traits() { let two: U = from_int(2); assert (two.to_int() == 2); - assert (ten.add(two) == from_int(12)); - assert (ten.sub(two) == from_int(8)); - assert (ten.mul(two) == from_int(20)); - assert (ten.div(two) == from_int(5)); - assert (ten.modulo(two) == from_int(0)); + assert (ten.add(&two) == from_int(12)); + assert (ten.sub(&two) == from_int(8)); + assert (ten.mul(&two) == from_int(20)); + assert (ten.div(&two) == from_int(5)); + assert (ten.modulo(&two) == from_int(0)); } test(&10.0); diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index e1137e6d269..649400e2360 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -81,11 +81,11 @@ impl T : Eq { } impl T: num::Num { - pure fn add(&&other: T) -> T { return self + other; } - pure fn sub(&&other: T) -> T { return self - other; } - pure fn mul(&&other: T) -> T { return self * other; } - pure fn div(&&other: T) -> T { return self / other; } - pure fn modulo(&&other: T) -> T { return self % other; } + pure fn add(other: &T) -> T { return self + *other; } + pure fn sub(other: &T) -> T { return self - *other; } + pure fn mul(other: &T) -> T { return self * *other; } + pure fn div(other: &T) -> T { return self / *other; } + pure fn modulo(other: &T) -> T { return self % *other; } pure fn neg() -> T { return -self; } pure fn to_int() -> int { return self as int; } @@ -250,11 +250,11 @@ fn test_interfaces() { let two: U = from_int(2); assert (two.to_int() == 2); - assert (ten.add(two) == from_int(12)); - assert (ten.sub(two) == from_int(8)); - assert (ten.mul(two) == from_int(20)); - assert (ten.div(two) == from_int(5)); - assert (ten.modulo(two) == from_int(0)); + assert (ten.add(&two) == from_int(12)); + assert (ten.sub(&two) == from_int(8)); + assert (ten.mul(&two) == from_int(20)); + assert (ten.div(&two) == from_int(5)); + assert (ten.modulo(&two) == from_int(0)); assert (ten.neg() == from_int(-10)); } diff --git a/src/libcore/num.rs b/src/libcore/num.rs index d5872933953..585a72d70ae 100644 --- a/src/libcore/num.rs +++ b/src/libcore/num.rs @@ -2,11 +2,11 @@ trait Num { // FIXME: Trait composition. (#2616) - pure fn add(&&other: self) -> self; - pure fn sub(&&other: self) -> self; - pure fn mul(&&other: self) -> self; - pure fn div(&&other: self) -> self; - pure fn modulo(&&other: self) -> self; + pure fn add(other: &self) -> self; + pure fn sub(other: &self) -> self; + pure fn mul(other: &self) -> self; + pure fn div(other: &self) -> self; + pure fn modulo(other: &self) -> self; pure fn neg() -> self; pure fn to_int() -> int; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 737cd4d9d50..eaaf11dab5d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -464,7 +464,7 @@ pure fn byte_slice(s: &str, f: fn(v: &[u8]) -> T) -> T { /// Convert a string to a vector of characters pure fn chars(s: &str) -> ~[char] { - let mut buf = ~[], i = 0u; + let mut buf = ~[], i = 0; let len = len(s); while i < len { let {ch, next} = char_range_at(s, i); diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index dba28ec06e6..f5d2229513d 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -74,11 +74,11 @@ impl T : Eq { } impl T: num::Num { - pure fn add(&&other: T) -> T { return self + other; } - pure fn sub(&&other: T) -> T { return self - other; } - pure fn mul(&&other: T) -> T { return self * other; } - pure fn div(&&other: T) -> T { return self / other; } - pure fn modulo(&&other: T) -> T { return self % other; } + pure fn add(other: &T) -> T { return self + *other; } + pure fn sub(other: &T) -> T { return self - *other; } + pure fn mul(other: &T) -> T { return self * *other; } + pure fn div(other: &T) -> T { return self / *other; } + pure fn modulo(other: &T) -> T { return self % *other; } pure fn neg() -> T { return -self; } pure fn to_int() -> int { return self as int; } diff --git a/src/test/run-pass/numeric-method-autoexport.rs b/src/test/run-pass/numeric-method-autoexport.rs index 6a3676227cc..f2882b91983 100644 --- a/src/test/run-pass/numeric-method-autoexport.rs +++ b/src/test/run-pass/numeric-method-autoexport.rs @@ -5,11 +5,11 @@ fn main() { // ints // num - assert 15.add(6) == 21; - assert 15i8.add(6i8) == 21i8; - assert 15i16.add(6i16) == 21i16; - assert 15i32.add(6i32) == 21i32; - assert 15i64.add(6i64) == 21i64; + assert 15.add(&6) == 21; + assert 15i8.add(&6i8) == 21i8; + assert 15i16.add(&6i16) == 21i16; + assert 15i32.add(&6i32) == 21i32; + assert 15i64.add(&6i64) == 21i64; // times 15.times(|| false); 15i8.times(|| false); @@ -19,11 +19,11 @@ fn main() { // uints // num - assert 15u.add(6u) == 21u; - assert 15u8.add(6u8) == 21u8; - assert 15u16.add(6u16) == 21u16; - assert 15u32.add(6u32) == 21u32; - assert 15u64.add(6u64) == 21u64; + assert 15u.add(&6u) == 21u; + assert 15u8.add(&6u8) == 21u8; + assert 15u16.add(&6u16) == 21u16; + assert 15u32.add(&6u32) == 21u32; + assert 15u64.add(&6u64) == 21u64; // times 15u.times(|| false); 15u8.times(|| false); -- cgit 1.4.1-3-g733a5 From 954eee53109e081f09cbccf2104752ed7eaa4119 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 25 Sep 2012 17:06:01 -0700 Subject: test: Remove various box annihilator tests --- src/test/run-pass/box-annihilator-shared.rs | 12 ------------ src/test/run-pass/box-annihilator-unique-vec.rs | 12 ------------ src/test/run-pass/box-annihilator-unique.rs | 12 ------------ 3 files changed, 36 deletions(-) delete mode 100644 src/test/run-pass/box-annihilator-shared.rs delete mode 100644 src/test/run-pass/box-annihilator-unique-vec.rs delete mode 100644 src/test/run-pass/box-annihilator-unique.rs (limited to 'src/test') diff --git a/src/test/run-pass/box-annihilator-shared.rs b/src/test/run-pass/box-annihilator-shared.rs deleted file mode 100644 index 5786b334af7..00000000000 --- a/src/test/run-pass/box-annihilator-shared.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern mod rustrt { - #[legacy_exports]; - fn rust_annihilate_box(ptr: *uint); -} - -fn main() { - unsafe { - let x = @3; - let p: *uint = cast::transmute(x); - rustrt::rust_annihilate_box(p); - } -} diff --git a/src/test/run-pass/box-annihilator-unique-vec.rs b/src/test/run-pass/box-annihilator-unique-vec.rs deleted file mode 100644 index 45449cc6382..00000000000 --- a/src/test/run-pass/box-annihilator-unique-vec.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern mod rustrt { - #[legacy_exports]; - fn rust_annihilate_box(ptr: *uint); -} - -fn main() { - unsafe { - let x = ~[~"a", ~"b", ~"c"]; - let p: *uint = cast::transmute(x); - rustrt::rust_annihilate_box(p); - } -} diff --git a/src/test/run-pass/box-annihilator-unique.rs b/src/test/run-pass/box-annihilator-unique.rs deleted file mode 100644 index a2d11654f9a..00000000000 --- a/src/test/run-pass/box-annihilator-unique.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern mod rustrt { - #[legacy_exports]; - fn rust_annihilate_box(ptr: *uint); -} - -fn main() { - unsafe { - let x = ~3; - let p: *uint = cast::transmute(x); - rustrt::rust_annihilate_box(p); - } -} -- cgit 1.4.1-3-g733a5 From 62649f0412630f8bfe284996c82b6a723d2ffea9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 25 Sep 2012 17:02:22 -0700 Subject: Check more things with deprecated_modes --- src/libcore/option.rs | 2 +- src/libstd/fun_treemap.rs | 2 +- src/libstd/list.rs | 2 +- src/libstd/test.rs | 2 +- src/libstd/treemap.rs | 2 +- src/rustc/middle/lint.rs | 127 ++++++++++++++++++------ src/test/compile-fail/deprecated-mode-fn-arg.rs | 9 ++ 7 files changed, 110 insertions(+), 36 deletions(-) create mode 100644 src/test/compile-fail/deprecated-mode-fn-arg.rs (limited to 'src/test') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 6ab9a86d8f3..518775ec751 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -9,7 +9,7 @@ */ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +#[warn(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cmp::Eq; diff --git a/src/libstd/fun_treemap.rs b/src/libstd/fun_treemap.rs index d3cc11d2a31..714d6c93ffa 100644 --- a/src/libstd/fun_treemap.rs +++ b/src/libstd/fun_treemap.rs @@ -1,4 +1,4 @@ -#[forbid(deprecated_mode)]; +#[warn(deprecated_mode)]; #[forbid(deprecated_pattern)]; /*! diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 45eafb3d018..b4e8678f6ae 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -1,5 +1,5 @@ //! A standard linked list -#[forbid(deprecated_mode)]; +#[warn(deprecated_mode)]; #[forbid(deprecated_pattern)]; use core::cmp::Eq; diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 51c0ad385ce..e872cba5dc9 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -5,7 +5,7 @@ // simplest interface possible for representing and running tests // while providing a base that other test frameworks may build off of. -#[forbid(deprecated_mode)]; +#[warn(deprecated_mode)]; #[forbid(deprecated_pattern)]; use core::cmp::Eq; diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 598a680f706..d6946590d80 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -5,7 +5,7 @@ * very naive algorithm, but it will probably be updated to be a * red-black tree or something else. */ -#[forbid(deprecated_mode)]; +#[warn(deprecated_mode)]; #[forbid(deprecated_pattern)]; use core::cmp::{Eq, Ord}; diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs index a6778d83b99..473931d8179 100644 --- a/src/rustc/middle/lint.rs +++ b/src/rustc/middle/lint.rs @@ -396,6 +396,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_non_camel_case_types(cx, i); check_item_heap(cx, i); check_item_structural_records(cx, i); + check_item_deprecated_modes(cx, i); } // Take a visitor, and modify it so that it will not proceed past subitems. @@ -666,43 +667,107 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl, } let fn_ty = ty::node_id_to_type(tcx, id); + check_fn_deprecated_modes(tcx, fn_ty, decl, span, id); +} + +fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, + span: span, id: ast::node_id) { match ty::get(fn_ty).sty { - ty::ty_fn(fn_ty) => { - let mut counter = 0; - do vec::iter2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| { - counter += 1; - debug!("arg %d, ty=%s, mode=%s", - counter, - ty_to_str(tcx, arg_ty.ty), - mode_to_str(arg_ast.mode)); - match arg_ast.mode { - ast::expl(ast::by_copy) => { - /* always allow by-copy */ - } + ty::ty_fn(fn_ty) => { + let mut counter = 0; + do vec::iter2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| { + counter += 1; + debug!("arg %d, ty=%s, mode=%s", + counter, + ty_to_str(tcx, arg_ty.ty), + mode_to_str(arg_ast.mode)); + match arg_ast.mode { + ast::expl(ast::by_copy) => { + /* always allow by-copy */ + } - ast::expl(_) => { - tcx.sess.span_lint( - deprecated_mode, id, id, - span, - fmt!("argument %d uses an explicit mode", counter)); - } + ast::expl(_) => { + tcx.sess.span_lint( + deprecated_mode, id, id, + span, + fmt!("argument %d uses an explicit mode", counter)); + } - ast::infer(_) => { - let kind = ty::type_kind(tcx, arg_ty.ty); - if !ty::kind_is_safe_for_default_mode(kind) { - tcx.sess.span_lint( - deprecated_mode, id, id, - span, - fmt!("argument %d uses the default mode \ - but shouldn't", - counter)); + ast::infer(_) => { + let kind = ty::type_kind(tcx, arg_ty.ty); + if !ty::kind_is_safe_for_default_mode(kind) { + tcx.sess.span_lint( + deprecated_mode, id, id, + span, + fmt!("argument %d uses the default mode \ + but shouldn't", + counter)); + } + } + } + + match ty::get(arg_ty.ty).sty { + ty::ty_fn(*) => { + let span = arg_ast.ty.span; + // Recurse to check fn-type argument + match arg_ast.ty.node { + ast::ty_fn(_, _, _, decl) => { + check_fn_deprecated_modes(tcx, arg_ty.ty, + decl, span, id); + } + ast::ty_path(*) => { + // This is probably a typedef, so we can't + // see the actual fn decl + // e.g. fn foo(f: InitOp) + } + ast::ty_rptr(_, mt) + | ast::ty_box(mt) + | ast::ty_uniq(mt) => { + // Functions with preceding sigil are parsed + // as pointers of functions + match mt.ty.node { + ast::ty_fn(_, _, _, decl) => { + check_fn_deprecated_modes( + tcx, arg_ty.ty, + decl, span, id); + } + _ => fail + } + } + _ => { + tcx.sess.span_warn(span, ~"what"); + error!("arg %d, ty=%s, mode=%s", + counter, + ty_to_str(tcx, arg_ty.ty), + mode_to_str(arg_ast.mode)); + error!("%?",arg_ast.ty.node); + fail + } + }; + } + _ => () } - } } } - } - _ => tcx.sess.impossible_case(span, ~"check_fn: function has \ - non-fn type") + + _ => tcx.sess.impossible_case(span, ~"check_fn: function has \ + non-fn type") + } +} + +fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) { + match it.node { + ast::item_ty(ty, _) => { + match ty.node { + ast::ty_fn(_, _, _, decl) => { + let fn_ty = ty::node_id_to_type(tcx, it.id); + check_fn_deprecated_modes( + tcx, fn_ty, decl, ty.span, it.id) + } + _ => () + } + } + _ => () } } diff --git a/src/test/compile-fail/deprecated-mode-fn-arg.rs b/src/test/compile-fail/deprecated-mode-fn-arg.rs new file mode 100644 index 00000000000..5afffb59dfc --- /dev/null +++ b/src/test/compile-fail/deprecated-mode-fn-arg.rs @@ -0,0 +1,9 @@ +#[forbid(deprecated_mode)]; + +fn foo(_f: fn(&i: int)) { //~ ERROR explicit mode +} + +type Bar = fn(&i: int); //~ ERROR explicit mode + +fn main() { +} \ No newline at end of file -- cgit 1.4.1-3-g733a5 From d05e2ad66c7bb2418b7c746f87486d4f74180193 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 25 Sep 2012 16:23:04 -0700 Subject: Demode core::result --- src/cargo/cargo.rs | 10 +-- src/compiletest/errors.rs | 2 +- src/compiletest/header.rs | 2 +- src/compiletest/runtest.rs | 8 +- src/fuzzer/fuzzer.rs | 6 +- src/libcore/comm.rs | 2 +- src/libcore/io.rs | 6 +- src/libcore/private.rs | 2 +- src/libcore/result.rs | 116 ++++++++++++++------------ src/libstd/json.rs | 14 ++-- src/libstd/net_ip.rs | 16 ++-- src/libstd/net_tcp.rs | 28 +++---- src/libstd/net_url.rs | 32 +++---- src/rustc/middle/typeck/astconv.rs | 4 +- src/rustc/middle/typeck/infer/combine.rs | 8 +- src/rustdoc/config.rs | 28 +++---- src/test/bench/core-std.rs | 2 +- src/test/bench/shootout-fasta.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/run-fail/result-get-fail.rs | 2 +- src/test/run-pass/cleanup-copy-mode.rs | 2 +- 23 files changed, 153 insertions(+), 145 deletions(-) (limited to 'src/test') diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 4dcfc608e0e..6f356a6e943 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -460,7 +460,7 @@ fn parse_source(name: ~str, j: json::Json) -> source { fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, source>) { if !os::path_exists(filename) { return; } let c = io::read_whole_file_str(filename); - match json::from_str(result::get(c)) { + match json::from_str(c.get()) { Ok(json::Dict(j)) => { for j.each |k, v| { sources.insert(k, parse_source(k, v)); @@ -579,7 +579,7 @@ fn load_source_info(c: &cargo, src: source) { let srcfile = dir.push("source.json"); if !os::path_exists(&srcfile) { return; } let srcstr = io::read_whole_file_str(&srcfile); - match json::from_str(result::get(srcstr)) { + match json::from_str(srcstr.get()) { Ok(json::Dict(s)) => { let o = parse_source(src.name, json::Dict(s)); @@ -601,7 +601,7 @@ fn load_source_packages(c: &cargo, src: source) { let pkgfile = dir.push("packages.json"); if !os::path_exists(&pkgfile) { return; } let pkgstr = io::read_whole_file_str(&pkgfile); - match json::from_str(result::get(pkgstr)) { + match json::from_str(pkgstr.get()) { Ok(json::List(js)) => { for (*js).each |j| { match *j { @@ -659,7 +659,7 @@ fn build_cargo_options(argv: ~[~str]) -> options { fn configure(opts: options) -> cargo { let home = match get_cargo_root() { Ok(home) => home, - Err(_err) => result::get(get_cargo_sysroot()) + Err(_err) => get_cargo_sysroot().get() }; let get_cargo_dir = match opts.mode { @@ -668,7 +668,7 @@ fn configure(opts: options) -> cargo { local_mode => get_cargo_root_nearest }; - let p = result::get(get_cargo_dir()); + let p = get_cargo_dir().get(); let sources = map::HashMap(); try_parse_sources(&home.push("sources.json"), sources); diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index e7d6593061d..a8b69201a22 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -9,7 +9,7 @@ type expected_error = { line: uint, kind: ~str, msg: ~str }; // Load any test directives embedded in the file fn load_errors(testfile: &Path) -> ~[expected_error] { let mut error_patterns = ~[]; - let rdr = result::get(io::file_reader(testfile)); + let rdr = io::file_reader(testfile).get(); let mut line_num = 1u; while !rdr.eof() { let ln = rdr.read_line(); diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 4ff1b8e9c78..5cd54a115ff 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -73,7 +73,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> bool { } fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool { - let rdr = result::get(io::file_reader(testfile)); + let rdr = io::file_reader(testfile).get(); while !rdr.eof() { let ln = rdr.read_line(); diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 1c69e511137..fcb007eca8b 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) { let rounds = match props.pp_exact { option::Some(_) => 1, option::None => 2 }; - let mut srcs = ~[result::get(io::read_whole_file_str(testfile))]; + let mut srcs = ~[io::read_whole_file_str(testfile).get()]; let mut round = 0; while round < rounds { @@ -129,7 +129,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) { match props.pp_exact { option::Some(file) => { let filepath = testfile.dir_path().push_rel(&file); - result::get(io::read_whole_file_str(&filepath)) + io::read_whole_file_str(&filepath).get() } option::None => { srcs[vec::len(srcs) - 2u] } }; @@ -561,8 +561,8 @@ fn dump_output(config: config, testfile: &Path, out: ~str, err: ~str) { fn dump_output_file(config: config, testfile: &Path, out: ~str, extension: ~str) { let outfile = make_out_name(config, testfile, extension); - let writer = result::get( - io::file_writer(&outfile, ~[io::Create, io::Truncate])); + let writer = + io::file_writer(&outfile, ~[io::Create, io::Truncate]).get(); writer.write_str(out); } diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 5e2cf689b7c..65adbb9e09e 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -19,7 +19,7 @@ impl test_mode : cmp::Eq { fn write_file(filename: &Path, content: ~str) { result::get( - io::file_writer(filename, ~[io::Create, io::Truncate])) + &io::file_writer(filename, ~[io::Create, io::Truncate])) .write_str(content); } @@ -543,7 +543,7 @@ fn check_convergence(files: &[Path]) { error!("pp convergence tests: %u files", vec::len(files)); for files.each |file| { if !file_might_not_converge(file) { - let s = @result::get(io::read_whole_file_str(file)); + let s = @result::get(&io::read_whole_file_str(file)); if !content_might_not_converge(*s) { error!("pp converge: %s", file.to_str()); // Change from 7u to 2u once @@ -563,7 +563,7 @@ fn check_variants(files: &[Path], cx: context) { loop; } - let s = @result::get(io::read_whole_file_str(file)); + let s = @result::get(&io::read_whole_file_str(file)); if contains(*s, ~"#") { loop; // Macros are confusing } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index b99eec8bb5b..a32d7af2ac6 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -459,7 +459,7 @@ fn test_recv_chan_wrong_task() { let po = Port(); let ch = Chan(po); send(ch, ~"flower"); - assert result::is_err(task::try(|| + assert result::is_err(&task::try(|| recv_chan(ch) )) } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 7c08e508d51..9a2a177c196 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -645,7 +645,7 @@ impl T : WriterUtil { #[allow(non_implicitly_copyable_typarams)] fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result { - result::chain(mk_file_writer(path, flags), |w| result::Ok(w)) + mk_file_writer(path, flags).chain(|w| result::Ok(w)) } @@ -864,10 +864,10 @@ mod tests { { let out: io::Writer = result::get( - io::file_writer(tmpfile, ~[io::Create, io::Truncate])); + &io::file_writer(tmpfile, ~[io::Create, io::Truncate])); out.write_str(frood); } - let inp: io::Reader = result::get(io::file_reader(tmpfile)); + let inp: io::Reader = result::get(&io::file_reader(tmpfile)); let frood2: ~str = inp.read_c_str(); log(debug, frood2); assert frood == frood2; diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 777aea7320c..9fe05723d35 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -283,7 +283,7 @@ fn test_weaken_task_fail() { } } }; - assert result::is_err(res); + assert result::is_err(&res); } /**************************************************************************** diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 205d375e9db..3735d555e2d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1,5 +1,9 @@ //! A type representing either success or failure +// NB: transitionary, de-mode-ing. +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use cmp::Eq; use either::Either; @@ -18,8 +22,8 @@ enum Result { * * If the result is an error */ -pure fn get(res: Result) -> T { - match res { +pure fn get(res: &Result) -> T { + match *res { Ok(t) => t, Err(the_err) => unsafe { fail fmt!("get called on error result: %?", the_err) @@ -50,23 +54,23 @@ pure fn get_ref(res: &a/Result) -> &a/T { * * If the result is not an error */ -pure fn get_err(res: Result) -> U { - match res { +pure fn get_err(res: &Result) -> U { + match *res { Err(u) => u, Ok(_) => fail ~"get_err called on ok result" } } /// Returns true if the result is `ok` -pure fn is_ok(res: Result) -> bool { - match res { +pure fn is_ok(res: &Result) -> bool { + match *res { Ok(_) => true, Err(_) => false } } /// Returns true if the result is `err` -pure fn is_err(res: Result) -> bool { +pure fn is_err(res: &Result) -> bool { !is_ok(res) } @@ -76,8 +80,8 @@ pure fn is_err(res: Result) -> bool { * `ok` result variants are converted to `either::right` variants, `err` * result variants are converted to `either::left`. */ -pure fn to_either(res: Result) -> Either { - match res { +pure fn to_either(res: &Result) -> Either { + match *res { Ok(res) => either::Right(res), Err(fail_) => either::Left(fail_) } @@ -97,11 +101,13 @@ pure fn to_either(res: Result) -> Either { * ok(parse_bytes(buf)) * } */ -fn chain(res: Result, op: fn(T) -> Result) +fn chain(+res: Result, op: fn(+t: T) -> Result) -> Result { - match res { - Ok(t) => op(t), - Err(e) => Err(e) + // XXX: Should be writable with move + match + if res.is_ok() { + op(unwrap(res)) + } else { + Err(unwrap_err(res)) } } @@ -114,10 +120,10 @@ fn chain(res: Result, op: fn(T) -> Result) * successful result while handling an error. */ fn chain_err( - res: Result, - op: fn(V) -> Result) + +res: Result, + op: fn(+t: V) -> Result) -> Result { - match res { + move match res { Ok(t) => Ok(t), Err(v) => op(v) } @@ -137,9 +143,9 @@ fn chain_err( * print_buf(buf) * } */ -fn iter(res: Result, f: fn(T)) { - match res { - Ok(t) => f(t), +fn iter(res: &Result, f: fn((&T))) { + match *res { + Ok(t) => f(&t), Err(_) => () } } @@ -152,10 +158,10 @@ fn iter(res: Result, f: fn(T)) { * This function can be used to pass through a successful result while * handling an error. */ -fn iter_err(res: Result, f: fn(E)) { - match res { +fn iter_err(res: &Result, f: fn((&E))) { + match *res { Ok(_) => (), - Err(e) => f(e) + Err(e) => f(&e) } } @@ -173,10 +179,10 @@ fn iter_err(res: Result, f: fn(E)) { * parse_bytes(buf) * } */ -fn map(res: Result, op: fn(T) -> U) +fn map(res: &Result, op: fn((&T)) -> U) -> Result { - match res { - Ok(t) => Ok(op(t)), + match *res { + Ok(t) => Ok(op(&t)), Err(e) => Err(e) } } @@ -189,63 +195,65 @@ fn map(res: Result, op: fn(T) -> U) * is immediately returned. This function can be used to pass through a * successful result while handling an error. */ -fn map_err(res: Result, op: fn(E) -> F) +fn map_err(res: &Result, op: fn((&E)) -> F) -> Result { - match res { + match *res { Ok(t) => Ok(t), - Err(e) => Err(op(e)) + Err(e) => Err(op(&e)) } } impl Result { - fn is_ok() -> bool { is_ok(self) } + fn is_ok() -> bool { is_ok(&self) } - fn is_err() -> bool { is_err(self) } + fn is_err() -> bool { is_err(&self) } - fn iter(f: fn(T)) { + fn iter(f: fn((&T))) { match self { - Ok(t) => f(t), + Ok(t) => f(&t), Err(_) => () } } - fn iter_err(f: fn(E)) { + fn iter_err(f: fn((&E))) { match self { Ok(_) => (), - Err(e) => f(e) + Err(e) => f(&e) } } } impl Result { - fn get() -> T { get(self) } + fn get() -> T { get(&self) } - fn map_err(op: fn(E) -> F) -> Result { + fn map_err(op: fn((&E)) -> F) -> Result { match self { Ok(t) => Ok(t), - Err(e) => Err(op(e)) + Err(e) => Err(op(&e)) } } } impl Result { - fn get_err() -> E { get_err(self) } + fn get_err() -> E { get_err(&self) } - fn map(op: fn(T) -> U) -> Result { + fn map(op: fn((&T)) -> U) -> Result { match self { - Ok(t) => Ok(op(t)), + Ok(t) => Ok(op(&t)), Err(e) => Err(e) } } } impl Result { - fn chain(op: fn(T) -> Result) -> Result { - chain(self, op) + fn chain(op: fn(+t: T) -> Result) -> Result { + // XXX: Bad copy + chain(copy self, op) } - fn chain_err(op: fn(E) -> Result) -> Result { - chain_err(self, op) + fn chain_err(op: fn(+t: E) -> Result) -> Result { + // XXX: Bad copy + chain_err(copy self, op) } } @@ -280,11 +288,11 @@ fn map_vec( } fn map_opt( - o_t: Option, op: fn(T) -> Result) -> Result,U> { + o_t: &Option, op: fn((&T)) -> Result) -> Result,U> { - match o_t { + match *o_t { None => Ok(None), - Some(t) => match op(t) { + Some(t) => match op(&t) { Ok(v) => Ok(Some(v)), Err(e) => Err(e) } @@ -301,14 +309,14 @@ fn map_opt( * to accommodate an error like the vectors being of different lengths. */ fn map_vec2(ss: &[S], ts: &[T], - op: fn(S,T) -> Result) -> Result<~[V],U> { + op: fn((&S),(&T)) -> Result) -> Result<~[V],U> { assert vec::same_length(ss, ts); let n = vec::len(ts); let mut vs = vec::with_capacity(n); let mut i = 0u; while i < n { - match op(ss[i],ts[i]) { + match op(&ss[i],&ts[i]) { Ok(v) => vec::push(vs, v), Err(u) => return Err(u) } @@ -323,13 +331,13 @@ fn map_vec2(ss: &[S], ts: &[T], * on its own as no result vector is built. */ fn iter_vec2(ss: &[S], ts: &[T], - op: fn(S,T) -> Result<(),U>) -> Result<(),U> { + op: fn((&S),(&T)) -> Result<(),U>) -> Result<(),U> { assert vec::same_length(ss, ts); let n = vec::len(ts); let mut i = 0u; while i < n { - match op(ss[i],ts[i]) { + match op(&ss[i],&ts[i]) { Ok(()) => (), Err(u) => return Err(u) } @@ -380,7 +388,7 @@ mod tests { #[legacy_exports]; fn op1() -> result::Result { result::Ok(666) } - fn op2(&&i: int) -> result::Result { + fn op2(+i: int) -> result::Result { result::Ok(i as uint + 1u) } @@ -388,12 +396,12 @@ mod tests { #[test] fn chain_success() { - assert get(chain(op1(), op2)) == 667u; + assert get(&chain(op1(), op2)) == 667u; } #[test] fn chain_failure() { - assert get_err(chain(op3(), op2)) == ~"sadface"; + assert get_err(&chain(op3(), op2)) == ~"sadface"; } #[test] diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 0f7bec6344a..2002e143ffa 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -892,7 +892,7 @@ mod tests { ])) ]); let astr = to_str(a); - let b = result::get(from_str(astr)); + let b = result::get(&from_str(astr)); let bstr = to_str(b); assert astr == bstr; assert a == b; @@ -1040,24 +1040,24 @@ mod tests { assert from_str(~"{\"a\":1,") == Err({line: 1u, col: 8u, msg: @~"EOF while parsing object"}); - assert eq(result::get(from_str(~"{}")), mk_dict(~[])); - assert eq(result::get(from_str(~"{\"a\": 3}")), + assert eq(result::get(&from_str(~"{}")), mk_dict(~[])); + assert eq(result::get(&from_str(~"{\"a\": 3}")), mk_dict(~[(~"a", Num(3.0f))])); - assert eq(result::get(from_str(~"{ \"a\": null, \"b\" : true }")), + assert eq(result::get(&from_str(~"{ \"a\": null, \"b\" : true }")), mk_dict(~[ (~"a", Null), (~"b", Boolean(true))])); - assert eq(result::get(from_str(~"\n{ \"a\": null, \"b\" : true }\n")), + assert eq(result::get(&from_str(~"\n{ \"a\": null, \"b\" : true }\n")), mk_dict(~[ (~"a", Null), (~"b", Boolean(true))])); - assert eq(result::get(from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), + assert eq(result::get(&from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), mk_dict(~[ (~"a", Num(1.0)), (~"b", List(@~[Boolean(true)])) ])); - assert eq(result::get(from_str( + assert eq(result::get(&from_str( ~"{" + ~"\"a\": 1.0, " + ~"\"b\": [" + diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 3e104e259b8..445bc62e4c9 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -176,24 +176,24 @@ mod v4 { unsafe { let INADDR_NONE = ll::get_INADDR_NONE(); let ip_rep_result = parse_to_ipv4_rep(ip); - if result::is_err(ip_rep_result) { - let err_str = result::get_err(ip_rep_result); + if result::is_err(&ip_rep_result) { + let err_str = result::get_err(&ip_rep_result); return result::Err({err_msg: err_str}) } // ipv4_rep.as_u32 is unsafe :/ let input_is_inaddr_none = - result::get(ip_rep_result).as_u32() == INADDR_NONE; + result::get(&ip_rep_result).as_u32() == INADDR_NONE; let new_addr = uv_ip4_addr(str::from_slice(ip), 22); let reformatted_name = uv_ip4_name(&new_addr); log(debug, fmt!("try_parse_addr: input ip: %s reparsed ip: %s", ip, reformatted_name)); let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name); - if result::is_err(ref_ip_rep_result) { - let err_str = result::get_err(ref_ip_rep_result); + if result::is_err(&ref_ip_rep_result) { + let err_str = result::get_err(&ref_ip_rep_result); return result::Err({err_msg: err_str}) } - if result::get(ref_ip_rep_result).as_u32() == INADDR_NONE && + if result::get(&ref_ip_rep_result).as_u32() == INADDR_NONE && !input_is_inaddr_none { return result::Err( {err_msg: ~"uv_ip4_name produced invalid result."}) @@ -358,7 +358,7 @@ mod test { let localhost_name = ~"localhost"; let iotask = uv::global_loop::get(); let ga_result = get_addr(localhost_name, iotask); - if result::is_err(ga_result) { + if result::is_err(&ga_result) { fail ~"got err result from net::ip::get_addr();" } // note really sure how to realiably test/assert @@ -384,6 +384,6 @@ mod test { let localhost_name = ~"sjkl234m,./sdf"; let iotask = uv::global_loop::get(); let ga_result = get_addr(localhost_name, iotask); - assert result::is_err(ga_result); + assert result::is_err(&ga_result); } } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index a0a209eae52..a1c7637dee6 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -871,17 +871,17 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint) log(debug, ~"starting tcp::read"); let iotask = (*socket_data).iotask; let rs_result = read_start_common_impl(socket_data); - if result::is_err(rs_result) { - let err_data = result::get_err(rs_result); + if result::is_err(&rs_result) { + let err_data = result::get_err(&rs_result); result::Err(err_data) } else { log(debug, ~"tcp::read before recv_timeout"); let read_result = if timeout_msecs > 0u { timer::recv_timeout( - iotask, timeout_msecs, result::get(rs_result)) + iotask, timeout_msecs, result::get(&rs_result)) } else { - Some(core::comm::recv(result::get(rs_result))) + Some(core::comm::recv(result::get(&rs_result))) }; log(debug, ~"tcp::read after recv_timeout"); match read_result { @@ -1514,9 +1514,9 @@ mod test { let accept_result = accept(new_conn); log(debug, ~"SERVER: after accept()"); - if result::is_err(accept_result) { + if result::is_err(&accept_result) { log(debug, ~"SERVER: error accept connection"); - let err_data = result::get_err(accept_result); + let err_data = result::get_err(&accept_result); core::comm::send(kill_ch, Some(err_data)); log(debug, ~"SERVER/WORKER: send on err cont ch"); @@ -1558,8 +1558,8 @@ mod test { log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb"); }); // err check on listen_result - if result::is_err(listen_result) { - match result::get_err(listen_result) { + if result::is_err(&listen_result) { + match result::get_err(&listen_result) { GenericListenErr(name, msg) => { fail fmt!("SERVER: exited abnormally name %s msg %s", name, msg); @@ -1592,8 +1592,8 @@ mod test { new_conn, kill_ch); }); // err check on listen_result - if result::is_err(listen_result) { - result::get_err(listen_result) + if result::is_err(&listen_result) { + result::get_err(&listen_result) } else { fail ~"SERVER: did not fail as expected" @@ -1609,9 +1609,9 @@ mod test { log(debug, ~"CLIENT: starting.."); let connect_result = connect(move server_ip_addr, server_port, iotask); - if result::is_err(connect_result) { + if result::is_err(&connect_result) { log(debug, ~"CLIENT: failed to connect"); - let err_data = result::get_err(connect_result); + let err_data = result::get_err(&connect_result); Err(err_data) } else { @@ -1636,9 +1636,9 @@ mod test { fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) { let write_result_future = sock.write_future(val); let write_result = write_result_future.get(); - if result::is_err(write_result) { + if result::is_err(&write_result) { log(debug, ~"tcp_write_single: write failed!"); - let err_data = result::get_err(write_result); + let err_data = result::get_err(&write_result); log(debug, fmt!("tcp_write_single err name: %s msg: %s", err_data.err_name, err_data.err_msg)); // meh. torn on what to do here. diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 74c603e29e9..2a27aed773d 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -627,30 +627,30 @@ fn get_query_fragment(rawurl: &str) -> fn from_str(rawurl: &str) -> result::Result { // scheme let mut schm = get_scheme(rawurl); - if result::is_err(schm) { - return result::Err(copy *result::get_err(schm)); + if result::is_err(&schm) { + return result::Err(copy *result::get_err(&schm)); } let (scheme, rest) = result::unwrap(schm); // authority let mut auth = get_authority(rest); - if result::is_err(auth) { - return result::Err(copy *result::get_err(auth)); + if result::is_err(&auth) { + return result::Err(copy *result::get_err(&auth)); } let (userinfo, host, port, rest) = result::unwrap(auth); // path let has_authority = if host == ~"" { false } else { true }; let mut pth = get_path(rest, has_authority); - if result::is_err(pth) { - return result::Err(copy *result::get_err(pth)); + if result::is_err(&pth) { + return result::Err(copy *result::get_err(&pth)); } let (path, rest) = result::unwrap(pth); // query and fragment let mut qry = get_query_fragment(rest); - if result::is_err(qry) { - return result::Err(copy *result::get_err(qry)); + if result::is_err(&qry) { + return result::Err(copy *result::get_err(&qry)); } let (query, fragment) = result::unwrap(qry); @@ -796,13 +796,13 @@ mod tests { assert p == option::Some(~"8000"); // invalid authorities; - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//user:pass@rust-lang:something")); - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//user@rust-lang:something:/path")); - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a")); - assert result::is_err(get_authority( + assert result::is_err(&get_authority( ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00")); // these parse as empty, because they don't start with '//' @@ -830,7 +830,7 @@ mod tests { assert r == ~"?q=v"; //failure cases - assert result::is_err(get_path(~"something?q", true)); + assert result::is_err(&get_path(~"something?q", true)); } @@ -877,13 +877,13 @@ mod tests { #[test] fn test_no_scheme() { - assert result::is_err(get_scheme(~"noschemehere.html")); + assert result::is_err(&get_scheme(~"noschemehere.html")); } #[test] fn test_invalid_scheme_errors() { - assert result::is_err(from_str(~"99://something")); - assert result::is_err(from_str(~"://something")); + assert result::is_err(&from_str(~"99://something")); + assert result::is_err(&from_str(~"://something")); } #[test] diff --git a/src/rustc/middle/typeck/astconv.rs b/src/rustc/middle/typeck/astconv.rs index 0c474994553..5434677b6fc 100644 --- a/src/rustc/middle/typeck/astconv.rs +++ b/src/rustc/middle/typeck/astconv.rs @@ -415,7 +415,7 @@ fn ty_of_arg( let mode = { match a.mode { ast::infer(_) if expected_ty.is_some() => { - result::get(ty::unify_mode( + result::get(&ty::unify_mode( self.tcx(), ty::expected_found {expected: expected_ty.get().mode, found: a.mode})) @@ -434,7 +434,7 @@ fn ty_of_arg( _ => { let m1 = ast::expl(ty::default_arg_mode_for_ty(self.tcx(), ty)); - result::get(ty::unify_mode( + result::get(&ty::unify_mode( self.tcx(), ty::expected_found {expected: m1, found: a.mode})) diff --git a/src/rustc/middle/typeck/infer/combine.rs b/src/rustc/middle/typeck/infer/combine.rs index 84791b59b32..db65bff9bfe 100644 --- a/src/rustc/middle/typeck/infer/combine.rs +++ b/src/rustc/middle/typeck/infer/combine.rs @@ -221,7 +221,7 @@ fn super_tps( if vec::same_length(as_, bs) { iter_vec2(as_, bs, |a, b| { - eq_tys(self, a, b) + eq_tys(self, *a, *b) }).then(|| Ok(as_.to_vec()) ) } else { Err(ty::terr_ty_param_size( @@ -327,7 +327,7 @@ fn super_fn_sigs( b_args: ~[ty::arg]) -> cres<~[ty::arg]> { if vec::same_length(a_args, b_args) { - map_vec2(a_args, b_args, |a, b| self.args(a, b)) + map_vec2(a_args, b_args, |a, b| self.args(*a, *b)) } else { Err(ty::terr_arg_count) } @@ -474,7 +474,7 @@ fn super_tys( (ty::ty_rec(as_), ty::ty_rec(bs)) => { if vec::same_length(as_, bs) { map_vec2(as_, bs, |a,b| { - self.flds(a, b) + self.flds(*a, *b) }).chain(|flds| Ok(ty::mk_rec(tcx, flds)) ) } else { Err(ty::terr_record_size(expected_found(self, as_.len(), @@ -484,7 +484,7 @@ fn super_tys( (ty::ty_tup(as_), ty::ty_tup(bs)) => { if vec::same_length(as_, bs) { - map_vec2(as_, bs, |a, b| self.tys(a, b) ) + map_vec2(as_, bs, |a, b| self.tys(*a, *b) ) .chain(|ts| Ok(ty::mk_tup(tcx, ts)) ) } else { Err(ty::terr_tuple_size( diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index b95e1657043..d8e79182506 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -285,20 +285,20 @@ mod test { #[test] fn should_error_with_no_crates() { let config = test::parse_config(~[~"rustdoc"]); - assert result::get_err(config) == ~"no crates specified"; + assert config.get_err() == ~"no crates specified"; } #[test] fn should_error_with_multiple_crates() { let config = test::parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]); - assert result::get_err(config) == ~"multiple crates specified"; + assert config.get_err() == ~"multiple crates specified"; } #[test] fn should_set_output_dir_to_cwd_if_not_provided() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).output_dir == Path("."); + assert config.get().output_dir == Path("."); } #[test] @@ -306,13 +306,13 @@ fn should_set_output_dir_if_provided() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles" ]); - assert result::get(config).output_dir == Path("snuggles"); + assert config.get().output_dir == Path("snuggles"); } #[test] fn should_set_output_format_to_pandoc_html_if_not_provided() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).output_format == PandocHtml; + assert config.get().output_format == PandocHtml; } #[test] @@ -320,7 +320,7 @@ fn should_set_output_format_to_markdown_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown" ]); - assert result::get(config).output_format == Markdown; + assert config.get().output_format == Markdown; } #[test] @@ -328,7 +328,7 @@ fn should_set_output_format_to_pandoc_html_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"html" ]); - assert result::get(config).output_format == PandocHtml; + assert config.get().output_format == PandocHtml; } #[test] @@ -336,13 +336,13 @@ fn should_error_on_bogus_format() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus" ]); - assert result::get_err(config) == ~"unknown output format 'bogus'"; + assert config.get_err() == ~"unknown output format 'bogus'"; } #[test] fn should_set_output_style_to_doc_per_mod_by_default() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).output_style == DocPerMod; + assert config.get().output_style == DocPerMod; } #[test] @@ -350,7 +350,7 @@ fn should_set_output_style_to_one_doc_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate" ]); - assert result::get(config).output_style == DocPerCrate; + assert config.get().output_style == DocPerCrate; } #[test] @@ -358,7 +358,7 @@ fn should_set_output_style_to_doc_per_mod_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod" ]); - assert result::get(config).output_style == DocPerMod; + assert config.get().output_style == DocPerMod; } #[test] @@ -366,7 +366,7 @@ fn should_error_on_bogus_output_style() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus" ]); - assert result::get_err(config) == ~"unknown output style 'bogus'"; + assert config.get_err() == ~"unknown output style 'bogus'"; } #[test] @@ -374,11 +374,11 @@ fn should_set_pandoc_command_if_requested() { let config = test::parse_config(~[ ~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc" ]); - assert result::get(config).pandoc_cmd == Some(~"panda-bear-doc"); + assert config.get().pandoc_cmd == Some(~"panda-bear-doc"); } #[test] fn should_set_pandoc_command_when_using_pandoc() { let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert result::get(config).pandoc_cmd == Some(~"pandoc"); + assert config.get().pandoc_cmd == Some(~"pandoc"); } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index a88793705a6..535b76bc94b 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -56,7 +56,7 @@ fn read_line() { .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); for int::range(0, 3) |_i| { - let reader = result::get(io::file_reader(&path)); + let reader = result::get(&io::file_reader(&path)); while !reader.eof() { reader.read_line(); } diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index a07b29f3dc6..0c742e16bfa 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -81,7 +81,7 @@ fn main(++args: ~[~str]) { }; let writer = if os::getenv(~"RUST_BENCH").is_some() { - result::get(io::file_writer(&Path("./shootout-fasta.data"), + result::get(&io::file_writer(&Path("./shootout-fasta.data"), ~[io::Truncate, io::Create])) } else { io::stdout() diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index dbdcf15db8a..b5dcacd76d3 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -134,7 +134,7 @@ fn main(++args: ~[~str]) { // get to this massive data set, but #include_bin chokes on it (#2598) let path = Path(env!("CFG_SRC_DIR")) .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); - result::get(io::file_reader(&path)) + result::get(&io::file_reader(&path)) } else { io::stdin() }; diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index d9d5827c56d..5f7036ed82a 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -131,7 +131,7 @@ fn main(++args: ~[~str]) { // get to this massive data set, but #include_bin chokes on it (#2598) let path = Path(env!("CFG_SRC_DIR")) .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); - result::get(io::file_reader(&path)) + result::get(&io::file_reader(&path)) } else { io::stdin() }; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index f6386a207b1..0cf0f0da5e5 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -114,7 +114,7 @@ fn writer(path: ~str, writech: comm::Chan>, size: uint) } _ => { result::get( - io::file_writer(&Path(path), + &io::file_writer(&Path(path), ~[io::Create, io::Truncate])) } }; diff --git a/src/test/run-fail/result-get-fail.rs b/src/test/run-fail/result-get-fail.rs index fbc8378643b..2b8712f3d59 100644 --- a/src/test/run-fail/result-get-fail.rs +++ b/src/test/run-fail/result-get-fail.rs @@ -1,4 +1,4 @@ // error-pattern:get called on error result: ~"kitty" fn main() { - log(error, result::get(result::Err::(~"kitty"))); + log(error, result::get(&result::Err::(~"kitty"))); } diff --git a/src/test/run-pass/cleanup-copy-mode.rs b/src/test/run-pass/cleanup-copy-mode.rs index 2cf1276887e..e4bfa54c410 100644 --- a/src/test/run-pass/cleanup-copy-mode.rs +++ b/src/test/run-pass/cleanup-copy-mode.rs @@ -2,7 +2,7 @@ fn adder(+x: @int, +y: @int) -> int { return *x + *y; } fn failer() -> @int { fail; } fn main() { - assert(result::is_err(task::try(|| { + assert(result::is_err(&task::try(|| { adder(@2, failer()); () }))); } -- cgit 1.4.1-3-g733a5 From 3023bd872949ce4ba45e13dbcd30d6b98963d0ed Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 25 Sep 2012 18:27:45 -0700 Subject: Demode dvec --- src/libcore/dlist.rs | 2 +- src/libcore/dvec.rs | 18 +++++++++--------- src/libcore/ops.rs | 2 +- src/libstd/bitv.rs | 2 +- src/libstd/ebml.rs | 2 +- src/libstd/map.rs | 2 +- src/libstd/smallintmap.rs | 2 +- src/test/run-pass/operator-overloading.rs | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/test') diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index e997d1f13ed..08ce967e025 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -118,7 +118,7 @@ fn concat(lists: DList>) -> DList { } priv impl DList { - pure fn new_link(-data: T) -> DListLink { + pure fn new_link(+data: T) -> DListLink { Some(DListNode(@{data: move data, mut linked: true, mut prev: None, mut next: None})) } diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 82767112b39..008d7841bec 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -93,7 +93,7 @@ priv impl DVec { } #[inline(always)] - fn check_out(f: fn(-v: ~[A]) -> B) -> B { + fn check_out(f: &fn(+v: ~[A]) -> B) -> B { unsafe { let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; @@ -126,7 +126,7 @@ impl DVec { * and return a new vector to replace it with. */ #[inline(always)] - fn swap(f: fn(-v: ~[A]) -> ~[A]) { + fn swap(f: &fn(+v: ~[A]) -> ~[A]) { self.check_out(|v| self.give_back(f(move v))) } @@ -136,7 +136,7 @@ impl DVec { * and return a new vector to replace it with. */ #[inline(always)] - fn swap_mut(f: fn(-v: ~[mut A]) -> ~[mut A]) { + fn swap_mut(f: &fn(-v: ~[mut A]) -> ~[mut A]) { do self.swap |v| { vec::from_mut(f(vec::to_mut(move v))) } @@ -170,7 +170,7 @@ impl DVec { } /// Insert a single item at the front of the list - fn unshift(-t: A) { + fn unshift(+t: A) { unsafe { let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; @@ -301,7 +301,7 @@ impl DVec { } /// Overwrites the contents of the element at `idx` with `a` - fn set_elt(idx: uint, a: A) { + fn set_elt(idx: uint, +a: A) { self.check_not_borrowed(); self.data[idx] = a; } @@ -311,7 +311,7 @@ impl DVec { * growing the vector if necessary. New elements will be initialized * with `initval` */ - fn grow_set_elt(idx: uint, initval: A, val: A) { + fn grow_set_elt(idx: uint, initval: A, +val: A) { do self.swap |v| { let mut v = move v; vec::grow_set(v, idx, initval, val); @@ -325,11 +325,11 @@ impl DVec { self.check_not_borrowed(); let length = self.len(); - if length == 0u { + if length == 0 { fail ~"attempt to retrieve the last element of an empty vector"; } - return self.data[length - 1u]; + return self.data[length - 1]; } /// Iterates over the elements in reverse order @@ -360,7 +360,7 @@ impl DVec { } impl DVec: Index { - pure fn index(&&idx: uint) -> A { + pure fn index(+idx: uint) -> A { self.get_elt(idx) } } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 28f7d21f574..70005020762 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -77,6 +77,6 @@ trait Shr { #[lang="index"] trait Index { - pure fn index(index: Index) -> Result; + pure fn index(+index: Index) -> Result; } diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 2c0a3716411..0ff0c0b6457 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -556,7 +556,7 @@ pure fn land(w0: uint, w1: uint) -> uint { return w0 & w1; } pure fn right(_w0: uint, w1: uint) -> uint { return w1; } impl Bitv: ops::Index { - pure fn index(&&i: uint) -> bool { + pure fn index(+i: uint) -> bool { self.get(i) } } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index db41c428cbe..9b7f7a79f22 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -42,7 +42,7 @@ type Doc = {data: @~[u8], start: uint, end: uint}; type TaggedDoc = {tag: uint, doc: Doc}; impl Doc: ops::Index { - pure fn index(&&tag: uint) -> Doc { + pure fn index(+tag: uint) -> Doc { unsafe { get_doc(self, tag) } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 9bdf6e15ee5..06df5a9e8ae 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -356,7 +356,7 @@ mod chained { } impl T: ops::Index { - pure fn index(&&k: K) -> V { + pure fn index(+k: K) -> V { unsafe { self.get(k) } diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 8ce1ebde127..5fc8ead59fd 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -132,7 +132,7 @@ impl SmallIntMap: map::Map { } impl SmallIntMap: ops::Index { - pure fn index(&&key: uint) -> V { + pure fn index(+key: uint) -> V { unsafe { get(self, key) } diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index d5af5a54377..2215b49937f 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -25,7 +25,7 @@ impl Point : ops::Neg { } impl Point : ops::Index { - pure fn index(&&x: bool) -> int { + pure fn index(+x: bool) -> int { if x { self.x } else { self.y } } } -- cgit 1.4.1-3-g733a5 From e19e628b19af2921fc29818009496bc430640f76 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 25 Sep 2012 17:39:22 -0700 Subject: Demode iter-trait --- src/libcore/iter-trait.rs | 12 +++++++----- src/libcore/iter-trait/dlist.rs | 4 ++-- src/libcore/iter-trait/dvec.rs | 4 ++-- src/libcore/iter-trait/option.rs | 12 ++++++------ src/libcore/iter.rs | 22 +++++++++++----------- src/libcore/str.rs | 4 ++-- src/libcore/vec.rs | 6 +++--- src/libstd/net_url.rs | 2 +- src/rustc/driver/rustc.rs | 4 ++-- src/rustc/middle/borrowck/check_loans.rs | 4 ++-- src/rustc/middle/check_alt.rs | 2 +- src/rustc/middle/check_const.rs | 2 +- src/rustc/middle/kind.rs | 6 +++--- src/rustc/middle/privacy.rs | 14 +++++++------- src/rustc/middle/region.rs | 2 +- src/rustc/middle/trans/expr.rs | 2 +- src/rustc/middle/typeck/check/method.rs | 2 +- src/rustdoc/rustdoc.rs | 2 +- src/test/run-pass/early-vtbl-resolution.rs | 2 +- src/test/run-pass/iter-contains.rs | 16 ++++++++-------- src/test/run-pass/iter-count.rs | 14 +++++++------- 21 files changed, 70 insertions(+), 68 deletions(-) (limited to 'src/test') diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index b2bb53d395f..fe42fe9e36c 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -2,17 +2,19 @@ // workaround our lack of traits and lack of macros. See core.{rc,rs} for // how this file is used. +#[warn(deprecated_mode)]; + use cmp::{Eq, Ord}; use inst::{IMPL_T, EACH, SIZE_HINT}; export extensions; impl IMPL_T: iter::BaseIter { - pure fn each(blk: fn(v: &A) -> bool) { EACH(self, blk) } - pure fn size_hint() -> Option { SIZE_HINT(self) } + pure fn each(blk: fn(v: &A) -> bool) { EACH(&self, blk) } + pure fn size_hint() -> Option { SIZE_HINT(&self) } } impl IMPL_T: iter::ExtendedIter { - pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } + pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { @@ -24,8 +26,8 @@ impl IMPL_T: iter::ExtendedIter { } impl IMPL_T: iter::EqIter { - pure fn contains(x: A) -> bool { iter::contains(self, x) } - pure fn count(x: A) -> uint { iter::count(self, x) } + pure fn contains(x: &A) -> bool { iter::contains(self, x) } + pure fn count(x: &A) -> uint { iter::count(self, x) } } impl IMPL_T: iter::CopyableIter { diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs index b6bbc1f70c0..1cf28f81dcc 100644 --- a/src/libcore/iter-trait/dlist.rs +++ b/src/libcore/iter-trait/dlist.rs @@ -8,7 +8,7 @@ type IMPL_T = dlist::DList; * e.g. breadth-first search with in-place enqueues), but removing the current * node is forbidden. */ -pure fn EACH(self: IMPL_T, f: fn(v: &A) -> bool) { +pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { let mut link = self.peek_n(); while option::is_some(&link) { let nobe = option::get(&link); @@ -29,6 +29,6 @@ pure fn EACH(self: IMPL_T, f: fn(v: &A) -> bool) { } } -pure fn SIZE_HINT(self: IMPL_T) -> Option { +pure fn SIZE_HINT(self: &IMPL_T) -> Option { Some(self.len()) } diff --git a/src/libcore/iter-trait/dvec.rs b/src/libcore/iter-trait/dvec.rs index 0f51df7b545..049b13da265 100644 --- a/src/libcore/iter-trait/dvec.rs +++ b/src/libcore/iter-trait/dvec.rs @@ -6,7 +6,7 @@ type IMPL_T = dvec::DVec; * * Attempts to access this dvec during iteration will fail. */ -pure fn EACH(self: IMPL_T, f: fn(v: &A) -> bool) { +pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { unsafe { do self.swap |v| { v.each(f); @@ -15,6 +15,6 @@ pure fn EACH(self: IMPL_T, f: fn(v: &A) -> bool) { } } -pure fn SIZE_HINT(self: IMPL_T) -> Option { +pure fn SIZE_HINT(self: &IMPL_T) -> Option { Some(self.len()) } diff --git a/src/libcore/iter-trait/option.rs b/src/libcore/iter-trait/option.rs index e1ffec0a7d7..2f7f7a4be7b 100644 --- a/src/libcore/iter-trait/option.rs +++ b/src/libcore/iter-trait/option.rs @@ -1,16 +1,16 @@ #[allow(non_camel_case_types)] type IMPL_T = Option; -pure fn EACH(self: IMPL_T, f: fn(v: &A) -> bool) { - match self { +pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { + match *self { None => (), Some(ref a) => { f(a); } } } -pure fn SIZE_HINT(self: IMPL_T) -> Option { - match self { - None => Some(0u), - Some(_) => Some(1u) +pure fn SIZE_HINT(self: &IMPL_T) -> Option { + match *self { + None => Some(0), + Some(_) => Some(1) } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 8af4ce3d0b1..dade851473b 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -23,8 +23,8 @@ trait ExtendedIter { } trait EqIter { - pure fn contains(x: A) -> bool; - pure fn count(x: A) -> uint; + pure fn contains(x: &A) -> bool; + pure fn count(x: &A) -> uint; } trait Times { @@ -66,11 +66,11 @@ trait Buildable { builder: fn(push: pure fn(+v: A))) -> self; } -pure fn eachi>(self: IA, blk: fn(uint, v: &A) -> bool) { - let mut i = 0u; +pure fn eachi>(self: &IA, blk: fn(uint, v: &A) -> bool) { + let mut i = 0; for self.each |a| { if !blk(i, a) { break; } - i += 1u; + i += 1; } } @@ -130,17 +130,17 @@ pure fn to_vec>(self: IA) -> ~[A] { foldl::(self, ~[], |r, a| vec::append(copy r, ~[a])) } -pure fn contains>(self: IA, x: A) -> bool { +pure fn contains>(self: IA, x: &A) -> bool { for self.each |a| { - if *a == x { return true; } + if *a == *x { return true; } } return false; } -pure fn count>(self: IA, x: A) -> uint { - do foldl(self, 0u) |count, value| { - if value == x { - count + 1u +pure fn count>(self: IA, x: &A) -> uint { + do foldl(self, 0) |count, value| { + if value == *x { + count + 1 } else { count } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index eaaf11dab5d..13fb2260045 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -377,7 +377,7 @@ fn unshift_char(s: &mut ~str, ch: char) { pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str { if chars_to_trim.is_empty() { return from_slice(s); } - match find(s, |c| !chars_to_trim.contains(c)) { + match find(s, |c| !chars_to_trim.contains(&c)) { None => ~"", Some(first) => unsafe { raw::slice_bytes(s, first, s.len()) } } @@ -395,7 +395,7 @@ pure fn trim_left_chars(s: &str, chars_to_trim: &[char]) -> ~str { pure fn trim_right_chars(s: &str, chars_to_trim: &[char]) -> ~str { if chars_to_trim.is_empty() { return str::from_slice(s); } - match rfind(s, |c| !chars_to_trim.contains(c)) { + match rfind(s, |c| !chars_to_trim.contains(&c)) { None => ~"", Some(last) => { let {next, _} = char_range_at(s, last); diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index e3df52b3cd6..7c5f242e8ba 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1873,7 +1873,7 @@ impl &[A]: iter::BaseIter { } impl &[A]: iter::ExtendedIter { - pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } + pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { @@ -1885,8 +1885,8 @@ impl &[A]: iter::ExtendedIter { } impl &[A]: iter::EqIter { - pure fn contains(x: A) -> bool { iter::contains(self, x) } - pure fn count(x: A) -> uint { iter::count(self, x) } + pure fn contains(x: &A) -> bool { iter::contains(self, x) } + pure fn count(x: &A) -> uint { iter::count(self, x) } } impl &[A]: iter::CopyableIter { diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 2a27aed773d..8116bd4fb30 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -524,7 +524,7 @@ fn get_authority(rawurl: &str) -> let host_is_end_plus_one: &fn() -> bool = || { end+1 == len - && !['?', '#', '/'].contains(rawurl[end] as char) + && !['?', '#', '/'].contains(&(rawurl[end] as char)) }; // finish up diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs index 1b4b47f1014..0306d0dbb18 100644 --- a/src/rustc/driver/rustc.rs +++ b/src/rustc/driver/rustc.rs @@ -140,12 +140,12 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { let lint_flags = vec::append(getopts::opt_strs(matches, ~"W"), getopts::opt_strs(matches, ~"warn")); - if lint_flags.contains(~"help") { + if lint_flags.contains(&~"help") { describe_warnings(); return; } - if getopts::opt_strs(matches, ~"Z").contains(~"help") { + if getopts::opt_strs(matches, ~"Z").contains(&~"help") { describe_debug_flags(); return; } diff --git a/src/rustc/middle/borrowck/check_loans.rs b/src/rustc/middle/borrowck/check_loans.rs index c0aaa041d18..cedab91b04e 100644 --- a/src/rustc/middle/borrowck/check_loans.rs +++ b/src/rustc/middle/borrowck/check_loans.rs @@ -204,7 +204,7 @@ impl check_loan_ctxt { let did = ast_util::def_id_of_def(def); let is_fn_arg = did.crate == ast::local_crate && - (*self.fn_args).contains(did.node); + (*self.fn_args).contains(&(did.node)); if is_fn_arg { return; } // case (a) above } ast::expr_fn_block(*) | ast::expr_fn(*) | @@ -251,7 +251,7 @@ impl check_loan_ctxt { let def = self.tcx().def_map.get(expr.id); let did = ast_util::def_id_of_def(def); did.crate == ast::local_crate && - (*self.fn_args).contains(did.node) + (*self.fn_args).contains(&(did.node)) } ast::expr_fn_block(*) | ast::expr_fn(*) => { self.is_stack_closure(expr.id) diff --git a/src/rustc/middle/check_alt.rs b/src/rustc/middle/check_alt.rs index 0d8d8b8dfe0..32801ed760c 100644 --- a/src/rustc/middle/check_alt.rs +++ b/src/rustc/middle/check_alt.rs @@ -275,7 +275,7 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> Option { let variants = ty::enum_variants(tcx, eid); if found.len() != (*variants).len() { for vec::each(*variants) |v| { - if !found.contains(variant(v.id)) { + if !found.contains(&(variant(v.id))) { return Some(variant(v.id)); } } diff --git a/src/rustc/middle/check_const.rs b/src/rustc/middle/check_const.rs index e194a907ffd..53bdf3db868 100644 --- a/src/rustc/middle/check_const.rs +++ b/src/rustc/middle/check_const.rs @@ -169,7 +169,7 @@ fn check_item_recursion(sess: session, ast_map: ast_map::map, visitor.visit_item(it, env, visitor); fn visit_item(it: @item, &&env: env, v: visit::vt) { - if (*env.idstack).contains(it.id) { + if (*env.idstack).contains(&(it.id)) { env.sess.span_fatal(env.root_it.span, ~"recursive constant"); } (*env.idstack).push(it.id); diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index 0f918ba92a9..4f9045ec77e 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -199,13 +199,13 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span, let id = ast_util::def_id_of_def(fv.def).node; // skip over free variables that appear in the cap clause - if captured_vars.contains(id) { loop; } + if captured_vars.contains(&id) { loop; } // if this is the last use of the variable, then it will be // a move and not a copy let is_move = { match cx.last_use_map.find(fn_id) { - Some(vars) => (*vars).contains(id), + Some(vars) => (*vars).contains(&id), None => false } }; @@ -588,7 +588,7 @@ fn check_cast_for_escaping_regions( do ty::walk_ty(source_ty) |ty| { match ty::get(ty).sty { ty::ty_param(source_param) => { - if target_params.contains(source_param) { + if target_params.contains(&source_param) { /* case (2) */ } else { check_owned(cx.tcx, ty, source.span); /* case (3) */ diff --git a/src/rustc/middle/privacy.rs b/src/rustc/middle/privacy.rs index 6b0df4630da..4d291ceb590 100644 --- a/src/rustc/middle/privacy.rs +++ b/src/rustc/middle/privacy.rs @@ -56,7 +56,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) { if method.vis == private && (impl_id.crate != local_crate || !privileged_items - .contains(impl_id.node)) { + .contains(&(impl_id.node))) { tcx.sess.span_err(span, fmt!("method `%s` is \ private", @@ -95,9 +95,9 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) { } match methods[method_num] { provided(method) - if method.vis == private && - !privileged_items - .contains(trait_id.node) => { + if method.vis == private && + !privileged_items + .contains(&(trait_id.node)) => { tcx.sess.span_err(span, fmt!("method `%s` \ @@ -157,7 +157,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) { match ty::get(ty::expr_ty(tcx, base)).sty { ty_class(id, _) if id.crate != local_crate || - !privileged_items.contains(id.node) => { + !privileged_items.contains(&(id.node)) => { match method_map.find(expr.id) { None => { debug!("(privacy checking) checking \ @@ -178,7 +178,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) { match ty::get(ty::expr_ty(tcx, expr)).sty { ty_class(id, _) => { if id.crate != local_crate || - !privileged_items.contains(id.node) { + !privileged_items.contains(&(id.node)) { for fields.each |field| { debug!("(privacy checking) checking \ field in struct literal"); @@ -205,7 +205,7 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) { match ty::get(ty::pat_ty(tcx, pattern)).sty { ty_class(id, _) => { if id.crate != local_crate || - !privileged_items.contains(id.node) { + !privileged_items.contains(&(id.node)) { for fields.each |field| { debug!("(privacy checking) checking \ struct pattern"); diff --git a/src/rustc/middle/region.rs b/src/rustc/middle/region.rs index cf496ae6683..ae1c739b26b 100644 --- a/src/rustc/middle/region.rs +++ b/src/rustc/middle/region.rs @@ -485,7 +485,7 @@ impl determine_rp_ctxt { } }; let dep = {ambient_variance: self.ambient_variance, id: self.item_id}; - if !vec.contains(dep) { vec.push(dep); } + if !vec.contains(&dep) { vec.push(dep); } } // Determines whether a reference to a region that appears in the diff --git a/src/rustc/middle/trans/expr.rs b/src/rustc/middle/trans/expr.rs index 0a38e19a26c..17a1ff112cd 100644 --- a/src/rustc/middle/trans/expr.rs +++ b/src/rustc/middle/trans/expr.rs @@ -813,7 +813,7 @@ fn trans_local_var(bcx: block, ref_id: ast::node_id, def: ast::def) -> Datum { nid: ast::node_id) -> Datum { let is_last_use = match bcx.ccx().maps.last_use_map.find(ref_id) { None => false, - Some(vars) => (*vars).contains(nid) + Some(vars) => (*vars).contains(&nid) }; let source = if is_last_use {FromLastUseLvalue} else {FromLvalue}; diff --git a/src/rustc/middle/typeck/check/method.rs b/src/rustc/middle/typeck/check/method.rs index 085ee51eff7..d08d3e9b847 100644 --- a/src/rustc/middle/typeck/check/method.rs +++ b/src/rustc/middle/typeck/check/method.rs @@ -182,7 +182,7 @@ impl LookupContext { ty_enum(did, _) => { // Watch out for newtype'd enums like "enum t = @T". // See discussion in typeck::check::do_autoderef(). - if enum_dids.contains(did) { + if enum_dids.contains(&did) { return None; } enum_dids.push(did); diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index 648d1d7a322..50ebef05afb 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -5,7 +5,7 @@ use config::Config; fn main(args: ~[~str]) { - if args.contains(~"-h") || args.contains(~"--help") { + if args.contains(&~"-h") || args.contains(&~"--help") { config::usage(); return; } diff --git a/src/test/run-pass/early-vtbl-resolution.rs b/src/test/run-pass/early-vtbl-resolution.rs index 24faa53fda4..2bbbbf7ef17 100644 --- a/src/test/run-pass/early-vtbl-resolution.rs +++ b/src/test/run-pass/early-vtbl-resolution.rs @@ -9,7 +9,7 @@ fn foo_func>(x: B) -> Option { x.foo() } fn main() { - for iter::eachi(Some({a: 0})) |i, a| { + for iter::eachi(&(Some({a: 0}))) |i, a| { #debug["%u %d", i, a.a]; } diff --git a/src/test/run-pass/iter-contains.rs b/src/test/run-pass/iter-contains.rs index 43bce3e7dcb..6036b5b2d24 100644 --- a/src/test/run-pass/iter-contains.rs +++ b/src/test/run-pass/iter-contains.rs @@ -1,10 +1,10 @@ fn main() { - assert []/_.contains(22u) == false; - assert [1u, 3u]/_.contains(22u) == false; - assert [22u, 1u, 3u]/_.contains(22u) == true; - assert [1u, 22u, 3u]/_.contains(22u) == true; - assert [1u, 3u, 22u]/_.contains(22u) == true; - assert None.contains(22u) == false; - assert Some(1u).contains(22u) == false; - assert Some(22u).contains(22u) == true; + assert []/_.contains(&22u) == false; + assert [1u, 3u]/_.contains(&22u) == false; + assert [22u, 1u, 3u]/_.contains(&22u) == true; + assert [1u, 22u, 3u]/_.contains(&22u) == true; + assert [1u, 3u, 22u]/_.contains(&22u) == true; + assert None.contains(&22u) == false; + assert Some(1u).contains(&22u) == false; + assert Some(22u).contains(&22u) == true; } diff --git a/src/test/run-pass/iter-count.rs b/src/test/run-pass/iter-count.rs index ba22cc7710b..0b6f94367be 100644 --- a/src/test/run-pass/iter-count.rs +++ b/src/test/run-pass/iter-count.rs @@ -1,9 +1,9 @@ fn main() { - assert []/_.count(22u) == 0u; - assert [1u, 3u]/_.count(22u) == 0u; - assert [22u, 1u, 3u]/_.count(22u) == 1u; - assert [22u, 1u, 22u]/_.count(22u) == 2u; - assert None.count(22u) == 0u; - assert Some(1u).count(22u) == 0u; - assert Some(22u).count(22u) == 1u; + assert []/_.count(&22u) == 0u; + assert [1u, 3u]/_.count(&22u) == 0u; + assert [22u, 1u, 3u]/_.count(&22u) == 1u; + assert [22u, 1u, 22u]/_.count(&22u) == 2u; + assert None.count(&22u) == 0u; + assert Some(1u).count(&22u) == 0u; + assert Some(22u).count(&22u) == 1u; } -- cgit 1.4.1-3-g733a5 From 95bc32dc4f5041e1e354dd23fbb70431fe8f31ca Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 25 Sep 2012 22:12:54 -0700 Subject: Fix borked tests --- src/test/bench/core-std.rs | 2 +- src/test/bench/graph500-bfs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test') diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 535b76bc94b..a7312cc8320 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -30,7 +30,7 @@ fn maybe_run_test(argv: &[~str], name: ~str, test: fn()) { if os::getenv(~"RUST_BENCH").is_some() { run_test = true } else if argv.len() > 0 { - run_test = argv.contains(~"all") || argv.contains(name) + run_test = argv.contains(&~"all") || argv.contains(&name) } if !run_test { return } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 89ca8eadde4..61d556b4613 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -374,7 +374,7 @@ fn validate(edges: ~[(node_id, node_id)], true } else { - edges.contains((u, v)) || edges.contains((v, u)) + edges.contains(&(u, v)) || edges.contains(&(v, u)) } }; -- cgit 1.4.1-3-g733a5 From ef23d77633484e4e85f8b37431e3b08ede3e4802 Mon Sep 17 00:00:00 2001 From: Vincent Belliard Date: Wed, 26 Sep 2012 10:47:21 +0200 Subject: fix issue #3535 and add colon between mode and type when dumping funcion prototype --- src/libsyntax/parse/parser.rs | 45 ++++++++++++++++---------- src/rustc/util/ppaux.rs | 2 +- src/test/compile-fail/unnamed_argument_mode.rs | 14 ++++++++ src/test/run-pass/unnamed_argument_mode.rs | 11 +++++++ 4 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 src/test/compile-fail/unnamed_argument_mode.rs create mode 100644 src/test/run-pass/unnamed_argument_mode.rs (limited to 'src/test') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 681d6296d4e..bc232f1259e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -584,6 +584,29 @@ impl parser { } else { infer(self.get_id()) } } + fn is_named_argument() -> bool { + let offset = if self.token == token::BINOP(token::AND) { + 1 + } else if self.token == token::BINOP(token::MINUS) { + 1 + } else if self.token == token::ANDAND { + 1 + } else if self.token == token::BINOP(token::PLUS) { + if self.look_ahead(1) == token::BINOP(token::PLUS) { + 2 + } else { + 1 + } + } else { 0 }; + if offset == 0 { + is_plain_ident(self.token) + && self.look_ahead(1) == token::COLON + } else { + is_plain_ident(self.look_ahead(offset)) + && self.look_ahead(offset + 1) == token::COLON + } + } + fn parse_capture_item_or(parse_arg_fn: fn(parser) -> arg_or_capture_item) -> arg_or_capture_item { @@ -605,29 +628,17 @@ impl parser { // This version of parse arg doesn't necessarily require // identifier names. fn parse_arg_general(require_name: bool) -> arg { - let m = self.parse_arg_mode(); - let i = if require_name { + let mut m; + let i = if require_name || self.is_named_argument() { + m = self.parse_arg_mode(); let name = self.parse_value_ident(); self.expect(token::COLON); name } else { - if is_plain_ident(self.token) - && self.look_ahead(1u) == token::COLON { - let name = self.parse_value_ident(); - self.bump(); - name - } else { special_idents::invalid } + m = infer(self.get_id()); + special_idents::invalid }; - match m { - expl(_) => { - if i == special_idents::invalid { - self.obsolete(copy self.span, ObsoleteModeInFnType); - } - } - _ => {} - } - let t = self.parse_ty(false); {mode: m, ty: t, ident: i, id: self.get_id()} diff --git a/src/rustc/util/ppaux.rs b/src/rustc/util/ppaux.rs index 9ade20c5568..0498a0f9541 100644 --- a/src/rustc/util/ppaux.rs +++ b/src/rustc/util/ppaux.rs @@ -261,7 +261,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { m == ty::default_arg_mode_for_ty(cx, ty) { ~"" } else { - mode_to_str(ast::expl(m)) + mode_to_str(ast::expl(m)) + ":" } } }; diff --git a/src/test/compile-fail/unnamed_argument_mode.rs b/src/test/compile-fail/unnamed_argument_mode.rs new file mode 100644 index 00000000000..36e6edc96f9 --- /dev/null +++ b/src/test/compile-fail/unnamed_argument_mode.rs @@ -0,0 +1,14 @@ +//error-pattern: mismatched types + +fn bad(&a: int) { +} + +// unnamed argument &int is now parsed x: &int +// it's not parsed &x: int anymore + +fn called(f: fn(&int)) { +} + +fn main() { +called(bad); +} diff --git a/src/test/run-pass/unnamed_argument_mode.rs b/src/test/run-pass/unnamed_argument_mode.rs new file mode 100644 index 00000000000..97e7582e142 --- /dev/null +++ b/src/test/run-pass/unnamed_argument_mode.rs @@ -0,0 +1,11 @@ +fn good(a: &int) { +} + +// unnamed argument &int is now parse x: &int + +fn called(f: fn(&int)) { +} + +fn main() { +called(good); +} -- cgit 1.4.1-3-g733a5 From d38b97a170eaea47933c30937cee5f525573116d Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 26 Sep 2012 10:13:27 -0700 Subject: fix modes on dtors --- src/libsyntax/ast_util.rs | 2 +- src/test/run-pass/dtor-explicit-mode.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/dtor-explicit-mode.rs (limited to 'src/test') diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index b0df0ea1c8d..828f72eb99d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -399,7 +399,7 @@ fn operator_prec(op: ast::binop) -> uint { fn dtor_dec() -> fn_decl { let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()}; // dtor has one argument, of type () - {inputs: ~[{mode: ast::expl(ast::by_ref), + {inputs: ~[{mode: ast::infer(0), // tjc: node id??? ty: nil_t, ident: parse::token::special_idents::underscore, id: 0}], output: nil_t, cf: return_val} diff --git a/src/test/run-pass/dtor-explicit-mode.rs b/src/test/run-pass/dtor-explicit-mode.rs new file mode 100644 index 00000000000..c1f7890ab58 --- /dev/null +++ b/src/test/run-pass/dtor-explicit-mode.rs @@ -0,0 +1,6 @@ +struct Foo { + x: int, + drop { } +} + +fn main() {} -- cgit 1.4.1-3-g733a5 From 101bc62ad91927e7fd9cf58ee431adf06574e2a7 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 26 Sep 2012 10:43:11 -0700 Subject: Revert "fix modes on dtors" This reverts commit d38b97a170eaea47933c30937cee5f525573116d. (Accidentally checked this in, oops) --- src/libsyntax/ast_util.rs | 2 +- src/test/run-pass/dtor-explicit-mode.rs | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 src/test/run-pass/dtor-explicit-mode.rs (limited to 'src/test') diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 828f72eb99d..b0df0ea1c8d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -399,7 +399,7 @@ fn operator_prec(op: ast::binop) -> uint { fn dtor_dec() -> fn_decl { let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()}; // dtor has one argument, of type () - {inputs: ~[{mode: ast::infer(0), // tjc: node id??? + {inputs: ~[{mode: ast::expl(ast::by_ref), ty: nil_t, ident: parse::token::special_idents::underscore, id: 0}], output: nil_t, cf: return_val} diff --git a/src/test/run-pass/dtor-explicit-mode.rs b/src/test/run-pass/dtor-explicit-mode.rs deleted file mode 100644 index c1f7890ab58..00000000000 --- a/src/test/run-pass/dtor-explicit-mode.rs +++ /dev/null @@ -1,6 +0,0 @@ -struct Foo { - x: int, - drop { } -} - -fn main() {} -- cgit 1.4.1-3-g733a5 From d2506a1787f27741dc9b577531d72db2b50ca446 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 18 Sep 2012 12:08:42 -0700 Subject: test: Add a test for auto_serialize2 --- src/test/run-pass/auto_serialize2.rs | 152 +++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/test/run-pass/auto_serialize2.rs (limited to 'src/test') diff --git a/src/test/run-pass/auto_serialize2.rs b/src/test/run-pass/auto_serialize2.rs new file mode 100644 index 00000000000..da48de2ffab --- /dev/null +++ b/src/test/run-pass/auto_serialize2.rs @@ -0,0 +1,152 @@ +extern mod std; + +// These tests used to be separate files, but I wanted to refactor all +// the common code. + +use cmp::Eq; +use std::ebml2; +use io::Writer; +use std::serialization2::{Serializer, Serializable, deserialize}; +use std::prettyprint2; + +fn test_ser_and_deser( + a1: A, + expected: ~str +) { + + // check the pretty printer: + let s = io::with_str_writer(|w| a1.serialize(w)); + debug!("s == %?", s); + assert s == expected; + + // check the EBML serializer: + let bytes = do io::with_bytes_writer |wr| { + let ebml_w = ebml2::Serializer(wr); + a1.serialize(ebml_w) + }; + let d = ebml2::Doc(@bytes); + let a2: A = deserialize(ebml2::Deserializer(d)); + assert a1 == a2; +} + +#[auto_serialize2] +enum Expr { + Val(uint), + Plus(@Expr, @Expr), + Minus(@Expr, @Expr) +} + +impl AnEnum : cmp::Eq { + pure fn eq(&&other: AnEnum) -> bool { + self.v == other.v + } + pure fn ne(&&other: AnEnum) -> bool { !self.eq(other) } +} + +impl Point : cmp::Eq { + pure fn eq(&&other: Point) -> bool { + self.x == other.x && self.y == other.y + } + pure fn ne(&&other: Point) -> bool { !self.eq(other) } +} + +impl Quark : cmp::Eq { + pure fn eq(&&other: Quark) -> bool { + match self { + Top(ref q) => match other { + Top(ref r) => q == r, + Bottom(_) => false + }, + Bottom(ref q) => match other { + Top(_) => false, + Bottom(ref r) => q == r + } + } + } + pure fn ne(&&other: Quark) -> bool { !self.eq(other) } +} + +impl CLike : cmp::Eq { + pure fn eq(&&other: CLike) -> bool { + self as int == other as int + } + pure fn ne(&&other: CLike) -> bool { !self.eq(other) } +} + +impl Expr : cmp::Eq { + pure fn eq(&&other: Expr) -> bool { + match self { + Val(e0a) => { + match other { + Val(e0b) => e0a == e0b, + _ => false + } + } + Plus(e0a, e1a) => { + match other { + Plus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + Minus(e0a, e1a) => { + match other { + Minus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + } + } + pure fn ne(&&other: Expr) -> bool { !self.eq(other) } +} + +#[auto_serialize2] +type Spanned = {lo: uint, hi: uint, node: T}; + +impl Spanned : cmp::Eq { + pure fn eq(&&other: Spanned) -> bool { + self.lo == other.lo && self.hi == other.hi && self.node.eq(other.node) + } + pure fn ne(&&other: Spanned) -> bool { !self.eq(other) } +} + +#[auto_serialize2] +type SomeRec = {v: ~[uint]}; + +#[auto_serialize2] +enum AnEnum = SomeRec; + +#[auto_serialize2] +type Point = {x: uint, y: uint}; + +#[auto_serialize2] +enum Quark { + Top(T), + Bottom(T) +} + +#[auto_serialize2] +enum CLike { A, B, C } + +fn main() { + + test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), + @Plus(@Val(22u), @Val(5u))), + ~"Plus(@Minus(@Val(3u), @Val(10u)), \ + @Plus(@Val(22u), @Val(5u)))"); + + test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, + ~"{lo: 0u, hi: 5u, node: 22u}"); + + test_ser_and_deser(AnEnum({v: ~[1u, 2u, 3u]}), + ~"AnEnum({v: [1u, 2u, 3u]})"); + + test_ser_and_deser({x: 3u, y: 5u}, ~"{x: 3u, y: 5u}"); + + test_ser_and_deser(~[1u, 2u, 3u], ~"[1u, 2u, 3u]"); + + test_ser_and_deser(Top(22u), ~"Top(22u)"); + test_ser_and_deser(Bottom(222u), ~"Bottom(222u)"); + + test_ser_and_deser(A, ~"A"); + test_ser_and_deser(B, ~"B"); +} -- cgit 1.4.1-3-g733a5 From c0b9986c8f11c85c74ee0ba64dccf4495027a645 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 25 Sep 2012 10:50:54 -0700 Subject: libstd: change serialization2 to take &self argument methods Unfortunately this trips over issue (#3585), where auto-ref isn't playing nicely with @T implementations. Most serializers don't care, but prettyprint2 won't properly display "@" until #3585 is fixed. --- src/libstd/serialization2.rs | 366 +++++++++++++++++-------------- src/libstd/std.rc | 1 - src/libsyntax/ext/auto_serialize2.rs | 47 +++- src/test/run-pass/auto_serialize2-box.rs | 73 ++++++ src/test/run-pass/auto_serialize2.rs | 91 +++----- 5 files changed, 339 insertions(+), 239 deletions(-) create mode 100644 src/test/run-pass/auto_serialize2-box.rs (limited to 'src/test') diff --git a/src/libstd/serialization2.rs b/src/libstd/serialization2.rs index 92461fed258..81941627ef6 100644 --- a/src/libstd/serialization2.rs +++ b/src/libstd/serialization2.rs @@ -4,179 +4,214 @@ Core serialization interfaces. */ -trait Serializer { +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; +#[forbid(non_camel_case_types)]; + +pub trait Serializer { // Primitive types: - fn emit_nil(); - fn emit_uint(v: uint); - fn emit_u64(v: u64); - fn emit_u32(v: u32); - fn emit_u16(v: u16); - fn emit_u8(v: u8); - fn emit_int(v: int); - fn emit_i64(v: i64); - fn emit_i32(v: i32); - fn emit_i16(v: i16); - fn emit_i8(v: i8); - fn emit_bool(v: bool); - fn emit_float(v: float); - fn emit_f64(v: f64); - fn emit_f32(v: f32); - fn emit_str(v: &str); + fn emit_nil(&self); + fn emit_uint(&self, v: uint); + fn emit_u64(&self, v: u64); + fn emit_u32(&self, v: u32); + fn emit_u16(&self, v: u16); + fn emit_u8(&self, v: u8); + fn emit_int(&self, v: int); + fn emit_i64(&self, v: i64); + fn emit_i32(&self, v: i32); + fn emit_i16(&self, v: i16); + fn emit_i8(&self, v: i8); + fn emit_bool(&self, v: bool); + fn emit_float(&self, v: float); + fn emit_f64(&self, v: f64); + fn emit_f32(&self, v: f32); + fn emit_str(&self, v: &str); // Compound types: - fn emit_enum(name: &str, f: fn()); - fn emit_enum_variant(v_name: &str, v_id: uint, sz: uint, f: fn()); - fn emit_enum_variant_arg(idx: uint, f: fn()); - fn emit_vec(len: uint, f: fn()); - fn emit_vec_elt(idx: uint, f: fn()); - fn emit_box(f: fn()); - fn emit_uniq(f: fn()); - fn emit_rec(f: fn()); - fn emit_rec_field(f_name: &str, f_idx: uint, f: fn()); - fn emit_tup(sz: uint, f: fn()); - fn emit_tup_elt(idx: uint, f: fn()); -} - -trait Deserializer { + fn emit_enum(&self, name: &str, f: fn()); + fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: fn()); + fn emit_enum_variant_arg(&self, idx: uint, f: fn()); + fn emit_vec(&self, len: uint, f: fn()); + fn emit_vec_elt(&self, idx: uint, f: fn()); + fn emit_box(&self, f: fn()); + fn emit_uniq(&self, f: fn()); + fn emit_rec(&self, f: fn()); + fn emit_rec_field(&self, f_name: &str, f_idx: uint, f: fn()); + fn emit_tup(&self, sz: uint, f: fn()); + fn emit_tup_elt(&self, idx: uint, f: fn()); +} + +pub trait Deserializer { // Primitive types: - fn read_nil() -> (); - fn read_uint() -> uint; - fn read_u64() -> u64; - fn read_u32() -> u32; - fn read_u16() -> u16; - fn read_u8() -> u8; - fn read_int() -> int; - fn read_i64() -> i64; - fn read_i32() -> i32; - fn read_i16() -> i16; - fn read_i8() -> i8; - fn read_bool() -> bool; - fn read_f64() -> f64; - fn read_f32() -> f32; - fn read_float() -> float; - fn read_str() -> ~str; + fn read_nil(&self) -> (); + fn read_uint(&self) -> uint; + fn read_u64(&self) -> u64; + fn read_u32(&self) -> u32; + fn read_u16(&self) -> u16; + fn read_u8(&self) -> u8; + fn read_int(&self) -> int; + fn read_i64(&self) -> i64; + fn read_i32(&self) -> i32; + fn read_i16(&self) -> i16; + fn read_i8(&self) -> i8; + fn read_bool(&self) -> bool; + fn read_f64(&self) -> f64; + fn read_f32(&self) -> f32; + fn read_float(&self) -> float; + fn read_str(&self) -> ~str; // Compound types: - fn read_enum(name: ~str, f: fn() -> T) -> T; - fn read_enum_variant(f: fn(uint) -> T) -> T; - fn read_enum_variant_arg(idx: uint, f: fn() -> T) -> T; - fn read_vec(f: fn(uint) -> T) -> T; - fn read_vec_elt(idx: uint, f: fn() -> T) -> T; - fn read_box(f: fn() -> T) -> T; - fn read_uniq(f: fn() -> T) -> T; - fn read_rec(f: fn() -> T) -> T; - fn read_rec_field(f_name: ~str, f_idx: uint, f: fn() -> T) -> T; - fn read_tup(sz: uint, f: fn() -> T) -> T; - fn read_tup_elt(idx: uint, f: fn() -> T) -> T; -} - -trait Serializable { - fn serialize(s: S); - static fn deserialize(d: D) -> self; -} - -impl uint: Serializable { - fn serialize(s: S) { s.emit_uint(self) } - static fn deserialize(d: D) -> uint { d.read_uint() } + fn read_enum(&self, name: ~str, f: fn() -> T) -> T; + fn read_enum_variant(&self, f: fn(uint) -> T) -> T; + fn read_enum_variant_arg(&self, idx: uint, f: fn() -> T) -> T; + fn read_vec(&self, f: fn(uint) -> T) -> T; + fn read_vec_elt(&self, idx: uint, f: fn() -> T) -> T; + fn read_box(&self, f: fn() -> T) -> T; + fn read_uniq(&self, f: fn() -> T) -> T; + fn read_rec(&self, f: fn() -> T) -> T; + fn read_rec_field(&self, f_name: ~str, f_idx: uint, f: fn() -> T) -> T; + fn read_tup(&self, sz: uint, f: fn() -> T) -> T; + fn read_tup_elt(&self, idx: uint, f: fn() -> T) -> T; +} + +pub trait Serializable { + fn serialize(&self, s: &S); + static fn deserialize(&self, d: &D) -> self; +} + +pub impl uint: Serializable { + fn serialize(&self, s: &S) { s.emit_uint(*self) } + static fn deserialize(&self, d: &D) -> uint { + d.read_uint() + } } -impl u8: Serializable { - fn serialize(s: S) { s.emit_u8(self) } - static fn deserialize(d: D) -> u8 { d.read_u8() } +pub impl u8: Serializable { + fn serialize(&self, s: &S) { s.emit_u8(*self) } + static fn deserialize(&self, d: &D) -> u8 { + d.read_u8() + } } -impl u16: Serializable { - fn serialize(s: S) { s.emit_u16(self) } - static fn deserialize(d: D) -> u16 { d.read_u16() } +pub impl u16: Serializable { + fn serialize(&self, s: &S) { s.emit_u16(*self) } + static fn deserialize(&self, d: &D) -> u16 { + d.read_u16() + } } -impl u32: Serializable { - fn serialize(s: S) { s.emit_u32(self) } - static fn deserialize(d: D) -> u32 { d.read_u32() } +pub impl u32: Serializable { + fn serialize(&self, s: &S) { s.emit_u32(*self) } + static fn deserialize(&self, d: &D) -> u32 { + d.read_u32() + } } -impl u64: Serializable { - fn serialize(s: S) { s.emit_u64(self) } - static fn deserialize(d: D) -> u64 { d.read_u64() } +pub impl u64: Serializable { + fn serialize(&self, s: &S) { s.emit_u64(*self) } + static fn deserialize(&self, d: &D) -> u64 { + d.read_u64() + } } -impl int: Serializable { - fn serialize(s: S) { s.emit_int(self) } - static fn deserialize(d: D) -> int { d.read_int() } +pub impl int: Serializable { + fn serialize(&self, s: &S) { s.emit_int(*self) } + static fn deserialize(&self, d: &D) -> int { + d.read_int() + } } -impl i8: Serializable { - fn serialize(s: S) { s.emit_i8(self) } - static fn deserialize(d: D) -> i8 { d.read_i8() } +pub impl i8: Serializable { + fn serialize(&self, s: &S) { s.emit_i8(*self) } + static fn deserialize(&self, d: &D) -> i8 { + d.read_i8() + } } -impl i16: Serializable { - fn serialize(s: S) { s.emit_i16(self) } - static fn deserialize(d: D) -> i16 { d.read_i16() } +pub impl i16: Serializable { + fn serialize(&self, s: &S) { s.emit_i16(*self) } + static fn deserialize(&self, d: &D) -> i16 { + d.read_i16() + } } -impl i32: Serializable { - fn serialize(s: S) { s.emit_i32(self) } - static fn deserialize(d: D) -> i32 { d.read_i32() } +pub impl i32: Serializable { + fn serialize(&self, s: &S) { s.emit_i32(*self) } + static fn deserialize(&self, d: &D) -> i32 { + d.read_i32() + } } -impl i64: Serializable { - fn serialize(s: S) { s.emit_i64(self) } - static fn deserialize(d: D) -> i64 { d.read_i64() } +pub impl i64: Serializable { + fn serialize(&self, s: &S) { s.emit_i64(*self) } + static fn deserialize(&self, d: &D) -> i64 { + d.read_i64() + } } -impl ~str: Serializable { - fn serialize(s: S) { s.emit_str(self) } - static fn deserialize(d: D) -> ~str { d.read_str() } +pub impl ~str: Serializable { + fn serialize(&self, s: &S) { s.emit_str(*self) } + static fn deserialize(&self, d: &D) -> ~str { + d.read_str() + } } -impl float: Serializable { - fn serialize(s: S) { s.emit_float(self) } - static fn deserialize(d: D) -> float { d.read_float() } +pub impl float: Serializable { + fn serialize(&self, s: &S) { s.emit_float(*self) } + static fn deserialize(&self, d: &D) -> float { + d.read_float() + } } -impl f32: Serializable { - fn serialize(s: S) { s.emit_f32(self) } - static fn deserialize(d: D) -> f32 { d.read_f32() } +pub impl f32: Serializable { + fn serialize(&self, s: &S) { s.emit_f32(*self) } + static fn deserialize(&self, d: &D) -> f32 { + d.read_f32() } } -impl f64: Serializable { - fn serialize(s: S) { s.emit_f64(self) } - static fn deserialize(d: D) -> f64 { d.read_f64() } +pub impl f64: Serializable { + fn serialize(&self, s: &S) { s.emit_f64(*self) } + static fn deserialize(&self, d: &D) -> f64 { + d.read_f64() + } } -impl bool: Serializable { - fn serialize(s: S) { s.emit_bool(self) } - static fn deserialize(d: D) -> bool { d.read_bool() } +pub impl bool: Serializable { + fn serialize(&self, s: &S) { s.emit_bool(*self) } + static fn deserialize(&self, d: &D) -> bool { + d.read_bool() + } } -impl (): Serializable { - fn serialize(s: S) { s.emit_nil() } - static fn deserialize(d: D) -> () { d.read_nil() } +pub impl (): Serializable { + fn serialize(&self, s: &S) { s.emit_nil() } + static fn deserialize(&self, d: &D) -> () { + d.read_nil() + } } -impl @T: Serializable { - fn serialize(s: S) { +pub impl @T: Serializable { + fn serialize(&self, s: &S) { s.emit_box(|| (*self).serialize(s)) } - static fn deserialize(d: D) -> @T { + static fn deserialize(&self, d: &D) -> @T { d.read_box(|| @deserialize(d)) } } -impl ~T: Serializable { - fn serialize(s: S) { +pub impl ~T: Serializable { + fn serialize(&self, s: &S) { s.emit_uniq(|| (*self).serialize(s)) } - static fn deserialize(d: D) -> ~T { + static fn deserialize(&self, d: &D) -> ~T { d.read_uniq(|| ~deserialize(d)) } } -impl ~[T]: Serializable { - fn serialize(s: S) { +pub impl ~[T]: Serializable { + fn serialize(&self, s: &S) { do s.emit_vec(self.len()) { for self.eachi |i, e| { s.emit_vec_elt(i, || e.serialize(s)) @@ -184,7 +219,7 @@ impl ~[T]: Serializable { } } - static fn deserialize(d: D) -> ~[T] { + static fn deserialize(&self, d: &D) -> ~[T] { do d.read_vec |len| { do vec::from_fn(len) |i| { d.read_vec_elt(i, || deserialize(d)) @@ -193,10 +228,10 @@ impl ~[T]: Serializable { } } -impl Option: Serializable { - fn serialize(s: S) { +pub impl Option: Serializable { + fn serialize(&self, s: &S) { do s.emit_enum(~"option") { - match self { + match *self { None => do s.emit_enum_variant(~"none", 0u, 0u) { }, @@ -207,7 +242,7 @@ impl Option: Serializable { } } - static fn deserialize(d: D) -> Option { + static fn deserialize(&self, d: &D) -> Option { do d.read_enum(~"option") { do d.read_enum_variant |i| { match i { @@ -220,12 +255,12 @@ impl Option: Serializable { } } -impl< +pub impl< T0: Serializable, T1: Serializable > (T0, T1): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1) => { do s.emit_tup(2) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -235,7 +270,7 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1) { + static fn deserialize(&self, d: &D) -> (T0, T1) { do d.read_tup(2) { ( d.read_tup_elt(0, || deserialize(d)), @@ -245,13 +280,13 @@ impl< } } -impl< +pub impl< T0: Serializable, T1: Serializable, T2: Serializable > (T0, T1, T2): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1, t2) => { do s.emit_tup(3) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -262,7 +297,7 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1, T2) { + static fn deserialize(&self, d: &D) -> (T0, T1, T2) { do d.read_tup(3) { ( d.read_tup_elt(0, || deserialize(d)), @@ -273,14 +308,14 @@ impl< } } -impl< +pub impl< T0: Serializable, T1: Serializable, T2: Serializable, T3: Serializable > (T0, T1, T2, T3): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1, t2, t3) => { do s.emit_tup(4) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -292,7 +327,7 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1, T2, T3) { + static fn deserialize(&self, d: &D) -> (T0, T1, T2, T3) { do d.read_tup(4) { ( d.read_tup_elt(0, || deserialize(d)), @@ -304,15 +339,15 @@ impl< } } -impl< +pub impl< T0: Serializable, T1: Serializable, T2: Serializable, T3: Serializable, T4: Serializable > (T0, T1, T2, T3, T4): Serializable { - fn serialize(s: S) { - match self { + fn serialize(&self, s: &S) { + match *self { (t0, t1, t2, t3, t4) => { do s.emit_tup(5) { s.emit_tup_elt(0, || t0.serialize(s)); @@ -325,7 +360,8 @@ impl< } } - static fn deserialize(d: D) -> (T0, T1, T2, T3, T4) { + static fn deserialize(&self, d: &D) + -> (T0, T1, T2, T3, T4) { do d.read_tup(5) { ( d.read_tup_elt(0, || deserialize(d)), @@ -343,40 +379,32 @@ impl< // // In some cases, these should eventually be coded as traits. -fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { - do s.emit_vec(v.len()) { - for v.eachi |i, e| { - do s.emit_vec_elt(i) { - f(*e) - } - } - } +pub trait SerializerHelpers { + fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)); } -fn read_to_vec(d: D, f: fn() -> T) -> ~[T] { - do d.read_vec |len| { - do vec::from_fn(len) |i| { - d.read_vec_elt(i, || f()) +pub impl S: SerializerHelpers { + fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)) { + do self.emit_vec(v.len()) { + for v.eachi |i, e| { + do self.emit_vec_elt(i) { + f(e) + } + } } } } -trait SerializerHelpers { - fn emit_from_vec(v: ~[T], f: fn(T)); +pub trait DeserializerHelpers { + fn read_to_vec(&self, f: fn() -> T) -> ~[T]; } -impl S: SerializerHelpers { - fn emit_from_vec(v: ~[T], f: fn(T)) { - emit_from_vec(self, v, f) - } -} - -trait DeserializerHelpers { - fn read_to_vec(f: fn() -> T) -> ~[T]; -} - -impl D: DeserializerHelpers { - fn read_to_vec(f: fn() -> T) -> ~[T] { - read_to_vec(self, f) +pub impl D: DeserializerHelpers { + fn read_to_vec(&self, f: fn() -> T) -> ~[T] { + do self.read_vec |len| { + do vec::from_fn(len) |i| { + self.read_vec_elt(i, || f()) + } + } } } diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 5979b98478f..548ec1c31b4 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -144,7 +144,6 @@ mod unicode; mod test; #[legacy_exports] mod serialization; -#[legacy_exports] mod serialization2; // Local Variables: diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index e2e308f7e2c..264711584fc 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -232,9 +232,24 @@ fn mk_ser_method( bounds: @~[ast::bound_trait(ser_bound)], }]; + let ty_s = @{ + id: cx.next_id(), + node: ast::ty_rptr( + @{ + id: cx.next_id(), + node: ast::re_anon, + }, + { + ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]), + mutbl: ast::m_imm + } + ), + span: span, + }; + let ser_inputs = ~[{ - mode: ast::expl(ast::by_ref), - ty: cx.ty_path(span, ~[cx.ident_of(~"__S")], ~[]), + mode: ast::infer(cx.next_id()), + ty: ty_s, ident: cx.ident_of(~"__s"), id: cx.next_id(), }]; @@ -255,7 +270,7 @@ fn mk_ser_method( ident: cx.ident_of(~"serialize"), attrs: ~[], tps: ser_tps, - self_ty: { node: ast::sty_by_ref, span: span }, + self_ty: { node: ast::sty_region(ast::m_imm), span: span }, purity: ast::impure_fn, decl: ser_decl, body: ser_body, @@ -288,9 +303,24 @@ fn mk_deser_method( bounds: @~[ast::bound_trait(deser_bound)], }]; + let ty_d = @{ + id: cx.next_id(), + node: ast::ty_rptr( + @{ + id: cx.next_id(), + node: ast::re_anon, + }, + { + ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]), + mutbl: ast::m_imm + } + ), + span: span, + }; + let deser_inputs = ~[{ - mode: ast::expl(ast::by_ref), - ty: cx.ty_path(span, ~[cx.ident_of(~"__D")], ~[]), + mode: ast::infer(cx.next_id()), + ty: ty_d, ident: cx.ident_of(~"__d"), id: cx.next_id(), }]; @@ -608,11 +638,14 @@ fn mk_enum_ser_body( } }; - // ast for `match self { $(arms) }` + // ast for `match *self { $(arms) }` let match_expr = cx.expr( span, ast::expr_match( - cx.expr_var(span, ~"self"), + cx.expr( + span, + ast::expr_unary(ast::deref, cx.expr_var(span, ~"self")) + ), arms ) ); diff --git a/src/test/run-pass/auto_serialize2-box.rs b/src/test/run-pass/auto_serialize2-box.rs new file mode 100644 index 00000000000..e395b1bfe5d --- /dev/null +++ b/src/test/run-pass/auto_serialize2-box.rs @@ -0,0 +1,73 @@ +// xfail-test FIXME Blocked on (#3585) + +extern mod std; + +// These tests used to be separate files, but I wanted to refactor all +// the common code. + +use cmp::Eq; +use std::ebml2; +use io::Writer; +use std::serialization2::{Serializer, Serializable, deserialize}; +use std::prettyprint2; + +fn test_ser_and_deser( + a1: A, + expected: ~str +) { + // check the pretty printer: + let s = do io::with_str_writer |w| { + a1.serialize(&prettyprint2::Serializer(w)) + }; + debug!("s == %?", s); + assert s == expected; + + // check the EBML serializer: + let bytes = do io::with_bytes_writer |wr| { + let ebml_w = &ebml2::Serializer(wr); + a1.serialize(ebml_w) + }; + let d = ebml2::Doc(@bytes); + let a2: A = deserialize(&ebml2::Deserializer(d)); + assert a1 == a2; +} + +#[auto_serialize2] +enum Expr { + Val(uint), + Plus(@Expr, @Expr), + Minus(@Expr, @Expr) +} + +impl Expr : cmp::Eq { + pure fn eq(other: &Expr) -> bool { + match self { + Val(e0a) => { + match *other { + Val(e0b) => e0a == e0b, + _ => false + } + } + Plus(e0a, e1a) => { + match *other { + Plus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + Minus(e0a, e1a) => { + match *other { + Minus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + } + } + pure fn ne(other: &Expr) -> bool { !self.eq(other) } +} + +fn main() { + test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), + @Plus(@Val(22u), @Val(5u))), + ~"Plus(@Minus(@Val(3u), @Val(10u)), \ + @Plus(@Val(22u), @Val(5u)))"); +} diff --git a/src/test/run-pass/auto_serialize2.rs b/src/test/run-pass/auto_serialize2.rs index da48de2ffab..ac526a8f0b6 100644 --- a/src/test/run-pass/auto_serialize2.rs +++ b/src/test/run-pass/auto_serialize2.rs @@ -15,98 +15,71 @@ fn test_ser_and_deser( ) { // check the pretty printer: - let s = io::with_str_writer(|w| a1.serialize(w)); + let s = do io::with_str_writer |w| { + a1.serialize(&prettyprint2::Serializer(w)) + }; debug!("s == %?", s); assert s == expected; // check the EBML serializer: let bytes = do io::with_bytes_writer |wr| { - let ebml_w = ebml2::Serializer(wr); + let ebml_w = &ebml2::Serializer(wr); a1.serialize(ebml_w) }; let d = ebml2::Doc(@bytes); - let a2: A = deserialize(ebml2::Deserializer(d)); + let a2: A = deserialize(&ebml2::Deserializer(d)); assert a1 == a2; } -#[auto_serialize2] -enum Expr { - Val(uint), - Plus(@Expr, @Expr), - Minus(@Expr, @Expr) -} - impl AnEnum : cmp::Eq { - pure fn eq(&&other: AnEnum) -> bool { + pure fn eq(other: &AnEnum) -> bool { self.v == other.v } - pure fn ne(&&other: AnEnum) -> bool { !self.eq(other) } + pure fn ne(other: &AnEnum) -> bool { !self.eq(other) } } impl Point : cmp::Eq { - pure fn eq(&&other: Point) -> bool { + pure fn eq(other: &Point) -> bool { self.x == other.x && self.y == other.y } - pure fn ne(&&other: Point) -> bool { !self.eq(other) } + pure fn ne(other: &Point) -> bool { !self.eq(other) } } impl Quark : cmp::Eq { - pure fn eq(&&other: Quark) -> bool { + pure fn eq(other: &Quark) -> bool { match self { - Top(ref q) => match other { - Top(ref r) => q == r, - Bottom(_) => false - }, - Bottom(ref q) => match other { - Top(_) => false, - Bottom(ref r) => q == r - } + Top(ref q) => { + match *other { + Top(ref r) => q == r, + Bottom(_) => false + } + }, + Bottom(ref q) => { + match *other { + Top(_) => false, + Bottom(ref r) => q == r + } + }, } } - pure fn ne(&&other: Quark) -> bool { !self.eq(other) } + pure fn ne(other: &Quark) -> bool { !self.eq(other) } } impl CLike : cmp::Eq { - pure fn eq(&&other: CLike) -> bool { - self as int == other as int - } - pure fn ne(&&other: CLike) -> bool { !self.eq(other) } -} - -impl Expr : cmp::Eq { - pure fn eq(&&other: Expr) -> bool { - match self { - Val(e0a) => { - match other { - Val(e0b) => e0a == e0b, - _ => false - } - } - Plus(e0a, e1a) => { - match other { - Plus(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - Minus(e0a, e1a) => { - match other { - Minus(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - } + pure fn eq(other: &CLike) -> bool { + self as int == *other as int } - pure fn ne(&&other: Expr) -> bool { !self.eq(other) } + pure fn ne(other: &CLike) -> bool { !self.eq(other) } } #[auto_serialize2] type Spanned = {lo: uint, hi: uint, node: T}; impl Spanned : cmp::Eq { - pure fn eq(&&other: Spanned) -> bool { - self.lo == other.lo && self.hi == other.hi && self.node.eq(other.node) + pure fn eq(other: &Spanned) -> bool { + self.lo == other.lo && self.hi == other.hi && self.node == other.node } - pure fn ne(&&other: Spanned) -> bool { !self.eq(other) } + pure fn ne(other: &Spanned) -> bool { !self.eq(other) } } #[auto_serialize2] @@ -128,12 +101,6 @@ enum Quark { enum CLike { A, B, C } fn main() { - - test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), - @Plus(@Val(22u), @Val(5u))), - ~"Plus(@Minus(@Val(3u), @Val(10u)), \ - @Plus(@Val(22u), @Val(5u)))"); - test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, ~"{lo: 0u, hi: 5u, node: 22u}"); -- cgit 1.4.1-3-g733a5 From 49d00b2f22576e7043a27f444804f563100212fe Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 24 Sep 2012 09:55:42 -0700 Subject: libstd: port json over to serialization2 --- src/cargo/cargo.rs | 119 ++-- src/libstd/json.rs | 1216 ++++++++++++++++++++++++--------------- src/test/run-pass/issue-2804.rs | 11 +- 3 files changed, 819 insertions(+), 527 deletions(-) (limited to 'src/test') diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 5a04d2d821c..b5c9fc17416 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -11,6 +11,7 @@ use syntax::diagnostic; use result::{Ok, Err}; use io::WriterUtil; +use send_map::linear::LinearMap; use std::{map, json, tempfile, term, sort, getopts}; use map::HashMap; use to_str::to_str; @@ -400,7 +401,7 @@ fn need_dir(s: &Path) { } } -fn valid_pkg_name(s: ~str) -> bool { +fn valid_pkg_name(s: &str) -> bool { fn is_valid_digit(c: char) -> bool { ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || @@ -412,27 +413,27 @@ fn valid_pkg_name(s: ~str) -> bool { s.all(is_valid_digit) } -fn parse_source(name: ~str, j: json::Json) -> @Source { +fn parse_source(name: ~str, j: &json::Json) -> @Source { if !valid_pkg_name(name) { fail fmt!("'%s' is an invalid source name", name); } - match j { - json::Dict(j) => { - let mut url = match j.find(~"url") { - Some(json::String(u)) => *u, + match *j { + json::Object(j) => { + let mut url = match j.find(&~"url") { + Some(json::String(u)) => u, _ => fail ~"needed 'url' field in source" }; - let method = match j.find(~"method") { - Some(json::String(u)) => *u, + let method = match j.find(&~"method") { + Some(json::String(u)) => u, _ => assume_source_method(url) }; - let key = match j.find(~"key") { - Some(json::String(u)) => Some(*u), + let key = match j.find(&~"key") { + Some(json::String(u)) => Some(u), _ => None }; - let keyfp = match j.find(~"keyfp") { - Some(json::String(u)) => Some(*u), + let keyfp = match j.find(&~"keyfp") { + Some(json::String(u)) => Some(u), _ => None }; if method == ~"file" { @@ -454,10 +455,10 @@ fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, @Source>) { if !os::path_exists(filename) { return; } let c = io::read_whole_file_str(filename); match json::from_str(c.get()) { - Ok(json::Dict(j)) => { - for j.each |k, v| { - sources.insert(k, parse_source(k, v)); - debug!("source: %s", k); + Ok(json::Object(j)) => { + for j.each |k, v| { + sources.insert(copy *k, parse_source(*k, v)); + debug!("source: %s", *k); } } Ok(_) => fail ~"malformed sources.json", @@ -465,17 +466,17 @@ fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, @Source>) { } } -fn load_one_source_package(src: @Source, p: map::HashMap<~str, json::Json>) { - let name = match p.find(~"name") { +fn load_one_source_package(src: @Source, p: &json::Object) { + let name = match p.find(&~"name") { Some(json::String(n)) => { - if !valid_pkg_name(*n) { + if !valid_pkg_name(n) { warn(~"malformed source json: " - + src.name + ~", '" + *n + ~"'"+ + + src.name + ~", '" + n + ~"'"+ ~" is an invalid name (alphanumeric, underscores and" + ~" dashes only)"); return; } - *n + n } _ => { warn(~"malformed source json: " + src.name + ~" (missing name)"); @@ -483,15 +484,15 @@ fn load_one_source_package(src: @Source, p: map::HashMap<~str, json::Json>) { } }; - let uuid = match p.find(~"uuid") { + let uuid = match p.find(&~"uuid") { Some(json::String(n)) => { - if !is_uuid(*n) { + if !is_uuid(n) { warn(~"malformed source json: " - + src.name + ~", '" + *n + ~"'"+ + + src.name + ~", '" + n + ~"'"+ ~" is an invalid uuid"); return; } - *n + n } _ => { warn(~"malformed source json: " + src.name + ~" (missing uuid)"); @@ -499,16 +500,16 @@ fn load_one_source_package(src: @Source, p: map::HashMap<~str, json::Json>) { } }; - let url = match p.find(~"url") { - Some(json::String(n)) => *n, + let url = match p.find(&~"url") { + Some(json::String(n)) => n, _ => { warn(~"malformed source json: " + src.name + ~" (missing url)"); return; } }; - let method = match p.find(~"method") { - Some(json::String(n)) => *n, + let method = match p.find(&~"method") { + Some(json::String(n)) => n, _ => { warn(~"malformed source json: " + src.name + ~" (missing method)"); @@ -516,17 +517,17 @@ fn load_one_source_package(src: @Source, p: map::HashMap<~str, json::Json>) { } }; - let reference = match p.find(~"ref") { - Some(json::String(n)) => Some(*n), + let reference = match p.find(&~"ref") { + Some(json::String(n)) => Some(n), _ => None }; let mut tags = ~[]; - match p.find(~"tags") { + match p.find(&~"tags") { Some(json::List(js)) => { - for (*js).each |j| { + for js.each |j| { match *j { - json::String(j) => vec::grow(tags, 1u, *j), + json::String(j) => vec::grow(tags, 1u, j), _ => () } } @@ -534,8 +535,8 @@ fn load_one_source_package(src: @Source, p: map::HashMap<~str, json::Json>) { _ => () } - let description = match p.find(~"description") { - Some(json::String(n)) => *n, + let description = match p.find(&~"description") { + Some(json::String(n)) => n, _ => { warn(~"malformed source json: " + src.name + ~" (missing description)"); @@ -573,8 +574,8 @@ fn load_source_info(c: &Cargo, src: @Source) { if !os::path_exists(&srcfile) { return; } let srcstr = io::read_whole_file_str(&srcfile); match json::from_str(srcstr.get()) { - Ok(json::Dict(s)) => { - let o = parse_source(src.name, json::Dict(s)); + Ok(ref json @ json::Object(_)) => { + let o = parse_source(src.name, json); src.key = o.key; src.keyfp = o.keyfp; @@ -596,9 +597,9 @@ fn load_source_packages(c: &Cargo, src: @Source) { let pkgstr = io::read_whole_file_str(&pkgfile); match json::from_str(pkgstr.get()) { Ok(json::List(js)) => { - for (*js).each |j| { + for js.each |j| { match *j { - json::Dict(p) => { + json::Object(p) => { load_one_source_package(src, p); } _ => { @@ -663,11 +664,11 @@ fn configure(opts: Options) -> Cargo { let p = get_cargo_dir().get(); - let sources = map::HashMap(); + let sources = HashMap(); try_parse_sources(&home.push("sources.json"), sources); try_parse_sources(&home.push("local-sources.json"), sources); - let dep_cache = map::HashMap(); + let dep_cache = HashMap(); let mut c = Cargo { pgp: pgp::supported(), @@ -707,10 +708,10 @@ fn configure(opts: Options) -> Cargo { c } -fn for_each_package(c: &Cargo, b: fn(s: @Source, p: Package)) { +fn for_each_package(c: &Cargo, b: fn(s: @Source, p: &Package)) { for c.sources.each_value |v| { for v.packages.each |p| { - b(v, *p); + b(v, p); } } } @@ -876,7 +877,7 @@ fn install_package(c: &Cargo, src: ~str, wd: &Path, pkg: Package) { match method { ~"git" => install_git(c, wd, url, copy pkg.reference), ~"file" => install_file(c, wd, &Path(url)), - ~"curl" => install_curl(c, wd, copy url), + ~"curl" => install_curl(c, wd, url), _ => () } } @@ -895,7 +896,7 @@ fn install_uuid(c: &Cargo, wd: &Path, uuid: ~str) { let mut ps = ~[]; for_each_package(c, |s, p| { if p.uuid == uuid { - vec::grow(ps, 1u, (s.name, copy p)); + vec::push(ps, (s.name, copy *p)); } }); if vec::len(ps) == 1u { @@ -919,7 +920,7 @@ fn install_named(c: &Cargo, wd: &Path, name: ~str) { let mut ps = ~[]; for_each_package(c, |s, p| { if p.name == name { - vec::grow(ps, 1u, (s.name, copy p)); + vec::push(ps, (s.name, copy *p)); } }); if vec::len(ps) == 1u { @@ -1477,7 +1478,7 @@ fn cmd_init(c: &Cargo) { info(fmt!("initialized .cargo in %s", c.root.to_str())); } -fn print_pkg(s: @Source, p: Package) { +fn print_pkg(s: @Source, p: &Package) { let mut m = s.name + ~"/" + p.name + ~" (" + p.uuid + ~")"; if vec::len(p.tags) > 0u { m = m + ~" [" + str::connect(p.tags, ~", ") + ~"]"; @@ -1572,7 +1573,7 @@ fn dump_cache(c: &Cargo) { need_dir(&c.root); let out = c.root.push("cache.json"); - let _root = json::Dict(map::HashMap()); + let _root = json::Object(~LinearMap()); if os::path_exists(&out) { copy_warn(&out, &c.root.push("cache.json.old")); @@ -1593,33 +1594,31 @@ fn dump_sources(c: &Cargo) { match io::buffered_file_writer(&out) { result::Ok(writer) => { - let hash = map::HashMap(); - let root = json::Dict(hash); + let mut hash = ~LinearMap(); - for c.sources.each |k, v| { - let chash = map::HashMap(); - let child = json::Dict(chash); + for c.sources.each |k, v| { + let mut chash = ~LinearMap(); - chash.insert(~"url", json::String(@v.url)); - chash.insert(~"method", json::String(@v.method)); + chash.insert(~"url", json::String(v.url)); + chash.insert(~"method", json::String(v.method)); match copy v.key { Some(key) => { - chash.insert(~"key", json::String(@key)); + chash.insert(~"key", json::String(copy key)); } _ => () } match copy v.keyfp { Some(keyfp) => { - chash.insert(~"keyfp", json::String(@keyfp)); + chash.insert(~"keyfp", json::String(copy keyfp)); } _ => () } - hash.insert(k, child); + hash.insert(copy k, json::Object(chash)); } - writer.write_str(json::to_str(root)); + json::to_writer(writer, &json::Object(hash)) } result::Err(e) => { error(fmt!("could not dump sources: %s", e)); diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 00e09f6604d..f75f033bb8e 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -11,214 +11,327 @@ use result::{Result, Ok, Err}; use io::{WriterUtil, ReaderUtil}; use map::HashMap; use map::Map; +use send_map::linear; use sort::Sort; -export Json; -export Error; -export to_writer; -export to_writer_pretty; -export to_str; -export to_str_pretty; -export from_reader; -export from_str; -export eq; -export ToJson; - -export Num; -export String; -export Boolean; -export List; -export Dict; -export Null; - /// Represents a json value -enum Json { - Num(float), - String(@~str), +pub enum Json { + Number(float), + String(~str), Boolean(bool), - List(@~[Json]), - Dict(map::HashMap<~str, Json>), + List(List), + Object(~Object), Null, } -type Error = { +pub type List = ~[Json]; +pub type Object = linear::LinearMap<~str, Json>; + +pub struct Error { line: uint, col: uint, msg: @~str, -}; +} -/// Serializes a json value into a io::writer -fn to_writer(wr: io::Writer, j: Json) { - match j { - Num(n) => wr.write_str(float::to_str(n, 6u)), - String(s) => wr.write_str(escape_str(*s)), - Boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }), - List(v) => { - wr.write_char('['); - let mut first = true; - for (*v).each |item| { - if !first { - wr.write_str(~", "); - } - first = false; - to_writer(wr, *item); - }; - wr.write_char(']'); - } - Dict(d) => { - if d.size() == 0u { - wr.write_str(~"{}"); - return; +fn escape_str(s: &str) -> ~str { + let mut escaped = ~"\""; + for str::chars_each(s) |c| { + match c { + '"' => escaped += ~"\\\"", + '\\' => escaped += ~"\\\\", + '\x08' => escaped += ~"\\b", + '\x0c' => escaped += ~"\\f", + '\n' => escaped += ~"\\n", + '\r' => escaped += ~"\\r", + '\t' => escaped += ~"\\t", + _ => escaped += str::from_char(c) } + }; - wr.write_str(~"{ "); - let mut first = true; - for d.each |key, value| { - if !first { - wr.write_str(~", "); - } - first = false; - wr.write_str(escape_str(key)); - wr.write_str(~": "); - to_writer(wr, value); - }; - wr.write_str(~" }"); - } - Null => wr.write_str(~"null") - } + escaped += ~"\""; + + escaped } -/// Serializes a json value into a io::writer -fn to_writer_pretty(wr: io::Writer, j: Json, indent: uint) { - fn spaces(n: uint) -> ~str { - let mut ss = ~""; - for n.times { str::push_str(&mut ss, " "); } - return ss; - } - - match j { - Num(n) => wr.write_str(float::to_str(n, 6u)), - String(s) => wr.write_str(escape_str(*s)), - Boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }), - List(vv) => { - if vv.len() == 0u { - wr.write_str(~"[]"); - return; +fn spaces(n: uint) -> ~str { + let mut ss = ~""; + for n.times { str::push_str(&ss, " "); } + return ss; +} + +pub struct Serializer { + priv wr: io::Writer, +} + +pub fn Serializer(wr: io::Writer) -> Serializer { + Serializer { wr: wr } +} + +pub impl Serializer: serialization2::Serializer { + fn emit_nil(&self) { self.wr.write_str("null") } + + fn emit_uint(&self, v: uint) { self.emit_float(v as float); } + fn emit_u64(&self, v: u64) { self.emit_float(v as float); } + fn emit_u32(&self, v: u32) { self.emit_float(v as float); } + fn emit_u16(&self, v: u16) { self.emit_float(v as float); } + fn emit_u8(&self, v: u8) { self.emit_float(v as float); } + + fn emit_int(&self, v: int) { self.emit_float(v as float); } + fn emit_i64(&self, v: i64) { self.emit_float(v as float); } + fn emit_i32(&self, v: i32) { self.emit_float(v as float); } + fn emit_i16(&self, v: i16) { self.emit_float(v as float); } + fn emit_i8(&self, v: i8) { self.emit_float(v as float); } + + fn emit_bool(&self, v: bool) { + if v { + self.wr.write_str("true"); + } else { + self.wr.write_str("false"); } + } - let inner_indent = indent + 2; + fn emit_f64(&self, v: f64) { self.emit_float(v as float); } + fn emit_f32(&self, v: f32) { self.emit_float(v as float); } + fn emit_float(&self, v: float) { + self.wr.write_str(float::to_str(v, 6u)); + } - // [ - wr.write_str("[\n"); - wr.write_str(spaces(inner_indent)); + fn emit_str(&self, v: &str) { + let s = escape_str(v); + self.wr.write_str(s); + } - // [ elem, - // elem, - // elem ] - let mut first = true; - for (*vv).each |item| { - if !first { - wr.write_str(~",\n"); - wr.write_str(spaces(inner_indent)); - } - first = false; - to_writer_pretty(wr, *item, inner_indent); - }; + fn emit_enum(&self, name: &str, f: fn()) { + if name != "option" { fail ~"only supports option enum" } + f() + } + fn emit_enum_variant(&self, _name: &str, id: uint, _cnt: uint, f: fn()) { + if id == 0 { + self.emit_nil(); + } else { + f() + } + } + fn emit_enum_variant_arg(&self, _idx: uint, f: fn()) { + f() + } + + fn emit_vec(&self, _len: uint, f: fn()) { + self.wr.write_char('['); + f(); + self.wr.write_char(']'); + } + + fn emit_vec_elt(&self, idx: uint, f: fn()) { + if idx != 0 { self.wr.write_char(','); } + f() + } + + fn emit_box(&self, f: fn()) { f() } + fn emit_uniq(&self, f: fn()) { f() } + fn emit_rec(&self, f: fn()) { + self.wr.write_char('{'); + f(); + self.wr.write_char('}'); + } + fn emit_rec_field(&self, name: &str, idx: uint, f: fn()) { + if idx != 0 { self.wr.write_char(','); } + self.wr.write_str(escape_str(name)); + self.wr.write_char(':'); + f(); + } + fn emit_tup(&self, sz: uint, f: fn()) { + self.emit_vec(sz, f); + } + fn emit_tup_elt(&self, idx: uint, f: fn()) { + self.emit_vec_elt(idx, f) + } +} + +pub struct PrettySerializer { + priv wr: io::Writer, + priv mut indent: uint, +} + +pub fn PrettySerializer(wr: io::Writer) -> PrettySerializer { + PrettySerializer { wr: wr, indent: 0 } +} - // ] - wr.write_str("\n"); - wr.write_str(spaces(indent)); - wr.write_str(~"]"); - } - Dict(dd) => { - if dd.size() == 0u { - wr.write_str(~"{}"); - return; +pub impl PrettySerializer: serialization2::Serializer { + fn emit_nil(&self) { self.wr.write_str("null") } + + fn emit_uint(&self, v: uint) { self.emit_float(v as float); } + fn emit_u64(&self, v: u64) { self.emit_float(v as float); } + fn emit_u32(&self, v: u32) { self.emit_float(v as float); } + fn emit_u16(&self, v: u16) { self.emit_float(v as float); } + fn emit_u8(&self, v: u8) { self.emit_float(v as float); } + + fn emit_int(&self, v: int) { self.emit_float(v as float); } + fn emit_i64(&self, v: i64) { self.emit_float(v as float); } + fn emit_i32(&self, v: i32) { self.emit_float(v as float); } + fn emit_i16(&self, v: i16) { self.emit_float(v as float); } + fn emit_i8(&self, v: i8) { self.emit_float(v as float); } + + fn emit_bool(&self, v: bool) { + if v { + self.wr.write_str("true"); + } else { + self.wr.write_str("false"); } + } + + fn emit_f64(&self, v: f64) { self.emit_float(v as float); } + fn emit_f32(&self, v: f32) { self.emit_float(v as float); } + fn emit_float(&self, v: float) { + self.wr.write_str(float::to_str(v, 6u)); + } - let inner_indent = indent + 2; + fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)); } - // convert from a dictionary - let mut pairs = ~[]; - for dd.each |key, value| { - vec::push(pairs, (key, value)); + fn emit_enum(&self, name: &str, f: fn()) { + if name != "option" { fail ~"only supports option enum" } + f() + } + fn emit_enum_variant(&self, _name: &str, id: uint, _cnt: uint, f: fn()) { + if id == 0 { + self.emit_nil(); + } else { + f() } + } + fn emit_enum_variant_arg(&self, _idx: uint, f: fn()) { + f() + } - // sort by key strings - let sorted_pairs = sort::merge_sort(|a,b| *a <= *b, pairs); - - // { - wr.write_str(~"{\n"); - wr.write_str(spaces(inner_indent)); - - // { k: v, - // k: v, - // k: v } - let mut first = true; - for sorted_pairs.each |kv| { - let (key, value) = *kv; - if !first { - wr.write_str(~",\n"); - wr.write_str(spaces(inner_indent)); - } - first = false; - let key = str::append(escape_str(key), ~": "); - let key_indent = inner_indent + str::len(key); - wr.write_str(key); - to_writer_pretty(wr, value, key_indent); - }; + fn emit_vec(&self, _len: uint, f: fn()) { + self.wr.write_char('['); + self.indent += 2; + f(); + self.indent -= 2; + self.wr.write_char(']'); + } + + fn emit_vec_elt(&self, idx: uint, f: fn()) { + if idx == 0 { + self.wr.write_char('\n'); + } else { + self.wr.write_str(",\n"); + } + self.wr.write_str(spaces(self.indent)); + f() + } - // } - wr.write_str(~"\n"); - wr.write_str(spaces(indent)); - wr.write_str(~"}"); - } - Null => wr.write_str(~"null") + fn emit_box(&self, f: fn()) { f() } + fn emit_uniq(&self, f: fn()) { f() } + fn emit_rec(&self, f: fn()) { + self.wr.write_char('{'); + self.indent += 2; + f(); + self.indent -= 2; + self.wr.write_char('}'); + } + fn emit_rec_field(&self, name: &str, idx: uint, f: fn()) { + if idx == 0 { + self.wr.write_char('\n'); + } else { + self.wr.write_str(",\n"); + } + self.wr.write_str(spaces(self.indent)); + self.wr.write_str(escape_str(name)); + self.wr.write_str(": "); + f(); + } + fn emit_tup(&self, sz: uint, f: fn()) { + self.emit_vec(sz, f); + } + fn emit_tup_elt(&self, idx: uint, f: fn()) { + self.emit_vec_elt(idx, f) } } -fn escape_str(s: &str) -> ~str { - let mut escaped = ~"\""; - for str::chars_each(s) |c| { - match c { - '"' => escaped += ~"\\\"", - '\\' => escaped += ~"\\\\", - '\x08' => escaped += ~"\\b", - '\x0c' => escaped += ~"\\f", - '\n' => escaped += ~"\\n", - '\r' => escaped += ~"\\r", - '\t' => escaped += ~"\\t", - _ => escaped += str::from_char(c) +pub fn to_serializer(ser: &S, json: &Json) { + match *json { + Number(f) => ser.emit_float(f), + String(s) => ser.emit_str(s), + Boolean(b) => ser.emit_bool(b), + List(v) => { + do ser.emit_vec(v.len()) || { + for v.eachi |i, elt| { + ser.emit_vec_elt(i, || to_serializer(ser, elt)) + } + } } - }; + Object(o) => { + do ser.emit_rec || { + let mut idx = 0; + for o.each |key, value| { + do ser.emit_rec_field(*key, idx) { + to_serializer(ser, value); + } + idx += 1; + } + } + } + Null => ser.emit_nil(), + } +} - escaped += ~"\""; +/// Serializes a json value into a io::writer +pub fn to_writer(wr: io::Writer, json: &Json) { + to_serializer(&Serializer(wr), json) +} - escaped +/// Serializes a json value into a string +pub fn to_str(json: &Json) -> ~str { + io::with_str_writer(|wr| to_writer(wr, json)) +} + +/// Serializes a json value into a io::writer +pub fn to_pretty_writer(wr: io::Writer, json: &Json) { + to_serializer(&PrettySerializer(wr), json) } /// Serializes a json value into a string -fn to_str(j: Json) -> ~str { - io::with_str_writer(|wr| to_writer(wr, j)) +pub fn to_pretty_str(json: &Json) -> ~str { + io::with_str_writer(|wr| to_pretty_writer(wr, json)) } -/// Serializes a json value into a string, with whitespace and sorting -fn to_str_pretty(j: Json) -> ~str { - io::with_str_writer(|wr| to_writer_pretty(wr, j, 0)) +pub struct Parser { + priv rdr: io::Reader, + priv mut ch: char, + priv mut line: uint, + priv mut col: uint, } -type Parser_ = { - rdr: io::Reader, - mut ch: char, - mut line: uint, - mut col: uint, -}; +/// Deserializes a json value from an io::reader +pub fn Parser(rdr: io::Reader) -> Parser { + Parser { + rdr: rdr, + ch: rdr.read_char(), + line: 1u, + col: 1u, + } +} -enum Parser { - Parser_(Parser_) +pub impl Parser { + fn parse() -> Result { + match move self.parse_value() { + Ok(move value) => { + // Skip trailing whitespaces. + self.parse_whitespace(); + // Make sure there is no trailing characters. + if self.eof() { + Ok(value) + } else { + self.error(~"trailing characters") + } + } + Err(move e) => Err(e) + } + } } -impl Parser { +priv impl Parser { fn eof() -> bool { self.ch == -1 as char } fn bump() { @@ -238,23 +351,7 @@ impl Parser { } fn error(+msg: ~str) -> Result { - Err({ line: self.line, col: self.col, msg: @msg }) - } - - fn parse() -> Result { - match self.parse_value() { - Ok(value) => { - // Skip trailing whitespaces. - self.parse_whitespace(); - // Make sure there is no trailing characters. - if self.eof() { - Ok(value) - } else { - self.error(~"trailing characters") - } - } - e => e - } + Err(Error { line: self.line, col: self.col, msg: @msg }) } fn parse_value() -> Result { @@ -267,10 +364,11 @@ impl Parser { 't' => self.parse_ident(~"rue", Boolean(true)), 'f' => self.parse_ident(~"alse", Boolean(false)), '0' .. '9' | '-' => self.parse_number(), - '"' => match self.parse_str() { - Ok(s) => Ok(String(s)), - Err(e) => Err(e) - }, + '"' => + match move self.parse_str() { + Ok(move s) => Ok(String(s)), + Err(move e) => Err(e), + }, '[' => self.parse_list(), '{' => self.parse_object(), _ => self.error(~"invalid syntax") @@ -281,10 +379,10 @@ impl Parser { while char::is_whitespace(self.ch) { self.bump(); } } - fn parse_ident(ident: ~str, value: Json) -> Result { + fn parse_ident(ident: ~str, +value: Json) -> Result { if str::all(ident, |c| c == self.next_char()) { self.bump(); - Ok(value) + Ok(move value) } else { self.error(~"invalid syntax") } @@ -317,7 +415,7 @@ impl Parser { } } - Ok(Num(neg * res)) + Ok(Number(neg * res)) } fn parse_integer() -> Result { @@ -419,7 +517,7 @@ impl Parser { Ok(res) } - fn parse_str() -> Result<@~str, Error> { + fn parse_str() -> Result<~str, Error> { let mut escape = false; let mut res = ~""; @@ -428,14 +526,14 @@ impl Parser { if (escape) { match self.ch { - '"' => str::push_char(&mut res, '"'), - '\\' => str::push_char(&mut res, '\\'), - '/' => str::push_char(&mut res, '/'), - 'b' => str::push_char(&mut res, '\x08'), - 'f' => str::push_char(&mut res, '\x0c'), - 'n' => str::push_char(&mut res, '\n'), - 'r' => str::push_char(&mut res, '\r'), - 't' => str::push_char(&mut res, '\t'), + '"' => str::push_char(&res, '"'), + '\\' => str::push_char(&res, '\\'), + '/' => str::push_char(&res, '/'), + 'b' => str::push_char(&res, '\x08'), + 'f' => str::push_char(&res, '\x0c'), + 'n' => str::push_char(&res, '\n'), + 'r' => str::push_char(&res, '\r'), + 't' => str::push_char(&res, '\t'), 'u' => { // Parse \u1234. let mut i = 0u; @@ -464,7 +562,7 @@ impl Parser { ~"invalid \\u escape (not four digits)"); } - str::push_char(&mut res, n as char); + str::push_char(&res, n as char); } _ => return self.error(~"invalid escape") } @@ -474,9 +572,9 @@ impl Parser { } else { if self.ch == '"' { self.bump(); - return Ok(@res); + return Ok(res); } - str::push_char(&mut res, self.ch); + str::push_char(&res, self.ch); } } @@ -491,13 +589,13 @@ impl Parser { if self.ch == ']' { self.bump(); - return Ok(List(@values)); + return Ok(List(values)); } loop { - match self.parse_value() { - Ok(v) => vec::push(values, v), - e => return e + match move self.parse_value() { + Ok(move v) => vec::push(values, v), + Err(move e) => return Err(e) } self.parse_whitespace(); @@ -507,7 +605,7 @@ impl Parser { match self.ch { ',' => self.bump(), - ']' => { self.bump(); return Ok(List(@values)); } + ']' => { self.bump(); return Ok(List(values)); } _ => return self.error(~"expected `,` or `]`") } }; @@ -517,11 +615,11 @@ impl Parser { self.bump(); self.parse_whitespace(); - let values = map::HashMap(); + let mut values = ~linear::LinearMap(); if self.ch == '}' { self.bump(); - return Ok(Dict(values)); + return Ok(Object(values)); } while !self.eof() { @@ -531,9 +629,9 @@ impl Parser { return self.error(~"key must be a string"); } - let key = match self.parse_str() { - Ok(key) => key, - Err(e) => return Err(e) + let key = match move self.parse_str() { + Ok(move key) => key, + Err(move e) => return Err(e) }; self.parse_whitespace(); @@ -544,15 +642,15 @@ impl Parser { } self.bump(); - match self.parse_value() { - Ok(value) => { values.insert(copy *key, value); } - e => return e + match move self.parse_value() { + Ok(move value) => { values.insert(key, value); } + Err(move e) => return Err(e) } self.parse_whitespace(); match self.ch { ',' => self.bump(), - '}' => { self.bump(); return Ok(Dict(values)); } + '}' => { self.bump(); return Ok(Object(values)); } _ => { if self.eof() { break; } return self.error(~"expected `,` or `}`"); @@ -565,198 +663,382 @@ impl Parser { } /// Deserializes a json value from an io::reader -fn from_reader(rdr: io::Reader) -> Result { - let parser = Parser_({ - rdr: rdr, - mut ch: rdr.read_char(), - mut line: 1u, - mut col: 1u, - }); - - parser.parse() +pub fn from_reader(rdr: io::Reader) -> Result { + Parser(rdr).parse() } /// Deserializes a json value from a string -fn from_str(s: &str) -> Result { - io::with_str_reader(s, from_reader) +pub fn from_str(s: &str) -> Result { + do io::with_str_reader(s) |rdr| { + from_reader(rdr) + } } -/// Test if two json values are equal -pure fn eq(value0: Json, value1: Json) -> bool { - match (value0, value1) { - (Num(f0), Num(f1)) => f0 == f1, - (String(s0), String(s1)) => s0 == s1, - (Boolean(b0), Boolean(b1)) => b0 == b1, - (List(l0), List(l1)) => vec::all2(*l0, *l1, eq), - (Dict(d0), Dict(d1)) => { - if d0.size() == d1.size() { - let mut equal = true; - for d0.each |k, v0| { - match d1.find(k) { - Some(v1) => if !eq(v0, v1) { equal = false }, - None => equal = false - } - }; - equal - } else { - false - } - } - (Null, Null) => true, - _ => false +pub struct Deserializer { + priv json: Json, + priv mut stack: ~[&Json], +} + +pub fn Deserializer(rdr: io::Reader) -> Result { + match move from_reader(rdr) { + Ok(move json) => { + let des = Deserializer { json: json, stack: ~[] }; + Ok(move des) + } + Err(move e) => Err(e) } } -/// Test if two json values are less than one another -pure fn lt(value0: Json, value1: Json) -> bool { - match value0 { - Num(f0) => { - match value1 { - Num(f1) => f0 < f1, - String(_) | Boolean(_) | List(_) | Dict(_) | Null => true - } +priv impl Deserializer { + fn peek() -> &self/Json { + if self.stack.len() == 0 { vec::push(self.stack, &self.json); } + vec::last(self.stack) + } + + fn pop() -> &self/Json { + if self.stack.len() == 0 { vec::push(self.stack, &self.json); } + vec::pop(self.stack) + } +} + +pub impl Deserializer: serialization2::Deserializer { + fn read_nil(&self) -> () { + debug!("read_nil"); + match *self.pop() { + Null => (), + _ => fail ~"not a null" } + } - String(s0) => { - match value1 { - Num(_) => false, - String(s1) => s0 < s1, - Boolean(_) | List(_) | Dict(_) | Null => true - } + fn read_u64(&self) -> u64 { self.read_float() as u64 } + fn read_u32(&self) -> u32 { self.read_float() as u32 } + fn read_u16(&self) -> u16 { self.read_float() as u16 } + fn read_u8 (&self) -> u8 { self.read_float() as u8 } + fn read_uint(&self) -> uint { self.read_float() as uint } + + fn read_i64(&self) -> i64 { self.read_float() as i64 } + fn read_i32(&self) -> i32 { self.read_float() as i32 } + fn read_i16(&self) -> i16 { self.read_float() as i16 } + fn read_i8 (&self) -> i8 { self.read_float() as i8 } + fn read_int(&self) -> int { self.read_float() as int } + + fn read_bool(&self) -> bool { + debug!("read_bool"); + match *self.pop() { + Boolean(b) => b, + _ => fail ~"not a boolean" } + } - Boolean(b0) => { - match value1 { - Num(_) | String(_) => false, - Boolean(b1) => b0 < b1, - List(_) | Dict(_) | Null => true - } + fn read_f64(&self) -> f64 { self.read_float() as f64 } + fn read_f32(&self) -> f32 { self.read_float() as f32 } + fn read_float(&self) -> float { + debug!("read_float"); + match *self.pop() { + Number(f) => f, + _ => fail ~"not a number" + } + } + + fn read_str(&self) -> ~str { + debug!("read_str"); + match *self.pop() { + String(ref s) => copy *s, + _ => fail ~"not a string" } + } + + fn read_enum(&self, name: ~str, f: fn() -> T) -> T { + debug!("read_enum(%s)", name); + if name != ~"option" { fail ~"only supports the option enum" } + f() + } + + fn read_enum_variant(&self, f: fn(uint) -> T) -> T { + debug!("read_enum_variant()"); + let idx = match *self.peek() { + Null => 0, + _ => 1, + }; + f(idx) + } + + fn read_enum_variant_arg(&self, idx: uint, f: fn() -> T) -> T { + debug!("read_enum_variant_arg(idx=%u)", idx); + if idx != 0 { fail ~"unknown index" } + f() + } - List(l0) => { - match value1 { - Num(_) | String(_) | Boolean(_) => false, - List(l1) => l0 < l1, - Dict(_) | Null => true + fn read_vec(&self, f: fn(uint) -> T) -> T { + debug!("read_vec()"); + let len = match *self.peek() { + List(list) => list.len(), + _ => fail ~"not a list", + }; + let res = f(len); + self.pop(); + res + } + + fn read_vec_elt(&self, idx: uint, f: fn() -> T) -> T { + debug!("read_vec_elt(idx=%u)", idx); + match *self.peek() { + List(ref list) => { + vec::push(self.stack, &list[idx]); + f() } + _ => fail ~"not a list", } + } - Dict(d0) => { - match value1 { - Num(_) | String(_) | Boolean(_) | List(_) => false, - Dict(d1) => { - unsafe { - let (d0_flat, d1_flat) = { - let d0_flat = dvec::DVec(); - for d0.each |k, v| { d0_flat.push((k, v)); } - let mut d0_flat = dvec::unwrap(move d0_flat); - d0_flat.qsort(); + fn read_box(&self, f: fn() -> T) -> T { + debug!("read_box()"); + f() + } - let mut d1_flat = dvec::DVec(); - for d1.each |k, v| { d1_flat.push((k, v)); } - let mut d1_flat = dvec::unwrap(move d1_flat); - d1_flat.qsort(); + fn read_uniq(&self, f: fn() -> T) -> T { + debug!("read_uniq()"); + f() + } - (move d0_flat, move d1_flat) - }; + fn read_rec(&self, f: fn() -> T) -> T { + debug!("read_rec()"); + let value = f(); + self.pop(); + value + } - d0_flat < d1_flat + fn read_rec_field(&self, f_name: ~str, f_idx: uint, + f: fn() -> T) -> T { + debug!("read_rec_field(%s, idx=%u)", f_name, f_idx); + let top = self.peek(); + match *top { + Object(ref obj) => { + // FIXME(#3148) This hint should not be necessary. + let obj: &self/~Object = obj; + + match obj.find_ref(&f_name) { + None => fail fmt!("no such field: %s", f_name), + Some(json) => { + vec::push(self.stack, json); + f() } } - Null => true } - } + Number(_) => fail ~"num", + String(_) => fail ~"str", + Boolean(_) => fail ~"bool", + List(_) => fail fmt!("list: %?", top), + Null => fail ~"null", - Null => { - match value1 { - Num(_) | String(_) | Boolean(_) | List(_) | Dict(_) => false, - Null => true - } + //_ => fail fmt!("not an object: %?", *top) } } -} -impl Error : Eq { - pure fn eq(other: &Error) -> bool { - self.line == (*other).line && - self.col == (*other).col && - self.msg == (*other).msg + fn read_tup(&self, sz: uint, f: fn() -> T) -> T { + debug!("read_tup(sz=%u)", sz); + let value = f(); + self.pop(); + value + } + + fn read_tup_elt(&self, idx: uint, f: fn() -> T) -> T { + debug!("read_tup_elt(idx=%u)", idx); + match *self.peek() { + List(list) => { + vec::push(self.stack, &list[idx]); + f() + } + _ => fail ~"not a list" + } } - pure fn ne(other: &Error) -> bool { !self.eq(other) } } impl Json : Eq { - pure fn eq(other: &Json) -> bool { eq(self, (*other)) } + pure fn eq(other: &Json) -> bool { + // XXX: This is ugly because matching on references is broken, and + // we can't match on dereferenced tuples without a copy. + match self { + Number(f0) => + match *other { Number(f1) => f0 == f1, _ => false }, + String(s0) => + match *other { String(s1) => s0 == s1, _ => false }, + Boolean(b0) => + match *other { Boolean(b1) => b0 == b1, _ => false }, + Null => + match *other { Null => true, _ => false }, + List(v0) => + match *other { List(v1) => v0 == v1, _ => false }, + Object(ref d0) => { + match *other { + Object(ref d1) => { + if d0.len() == d1.len() { + let mut equal = true; + for d0.each |k, v0| { + match d1.find_ref(k) { + Some(v1) if v0 == v1 => { }, + _ => { equal = false; break } + } + }; + equal + } else { + false + } + } + _ => false + } + } + } + } pure fn ne(other: &Json) -> bool { !self.eq(other) } } +/// Test if two json values are less than one another impl Json : Ord { - pure fn lt(other: &Json) -> bool { lt(self, (*other)) } + pure fn lt(other: &Json) -> bool { + match self { + Number(f0) => { + match *other { + Number(f1) => f0 < f1, + String(_) | Boolean(_) | List(_) | Object(_) | + Null => true + } + } + + String(s0) => { + match *other { + Number(_) => false, + String(s1) => s0 < s1, + Boolean(_) | List(_) | Object(_) | Null => true + } + } + + Boolean(b0) => { + match *other { + Number(_) | String(_) => false, + Boolean(b1) => b0 < b1, + List(_) | Object(_) | Null => true + } + } + + List(l0) => { + match *other { + Number(_) | String(_) | Boolean(_) => false, + List(l1) => l0 < l1, + Object(_) | Null => true + } + } + + Object(d0) => { + match *other { + Number(_) | String(_) | Boolean(_) | List(_) => false, + Object(d1) => { + unsafe { + let mut d0_flat = ~[]; + let mut d1_flat = ~[]; + + // XXX: this is horribly inefficient... + for d0.each |k, v| { + vec::push(d0_flat, (@copy *k, @copy *v)); + } + d0_flat.qsort(); + + for d1.each |k, v| { + vec::push(d1_flat, (@copy *k, @copy *v)); + } + d1_flat.qsort(); + + d0_flat < d1_flat + } + } + Null => true + } + } + + Null => { + match *other { + Number(_) | String(_) | Boolean(_) | List(_) | + Object(_) => + false, + Null => true + } + } + } + } pure fn le(other: &Json) -> bool { !(*other).lt(&self) } - pure fn ge(other: &Json) -> bool { !self.lt(other) } + pure fn ge(other: &Json) -> bool { !self.lt(other) } pure fn gt(other: &Json) -> bool { (*other).lt(&self) } } +impl Error : Eq { + pure fn eq(other: &Error) -> bool { + self.line == other.line && + self.col == other.col && + self.msg == other.msg + } + pure fn ne(other: &Error) -> bool { !self.eq(other) } +} + trait ToJson { fn to_json() -> Json; } impl Json: ToJson { - fn to_json() -> Json { self } + fn to_json() -> Json { copy self } } impl @Json: ToJson { - fn to_json() -> Json { *self } + fn to_json() -> Json { (*self).to_json() } } impl int: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl i8: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl i16: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl i32: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl i64: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl uint: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl u8: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl u16: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl u32: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl u64: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl float: ToJson { - fn to_json() -> Json { Num(self) } + fn to_json() -> Json { Number(self) } } impl f32: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl f64: ToJson { - fn to_json() -> Json { Num(self as float) } + fn to_json() -> Json { Number(self as float) } } impl (): ToJson { @@ -768,47 +1050,58 @@ impl bool: ToJson { } impl ~str: ToJson { - fn to_json() -> Json { String(@copy self) } + fn to_json() -> Json { String(copy self) } } impl @~str: ToJson { - fn to_json() -> Json { String(self) } + fn to_json() -> Json { String(copy *self) } } impl (A, B): ToJson { fn to_json() -> Json { match self { (a, b) => { - List(@~[a.to_json(), b.to_json()]) + List(~[a.to_json(), b.to_json()]) } } } } impl (A, B, C): ToJson { - fn to_json() -> Json { match self { (a, b, c) => { - List(@~[a.to_json(), b.to_json(), c.to_json()]) + List(~[a.to_json(), b.to_json(), c.to_json()]) } } } } impl ~[A]: ToJson { - fn to_json() -> Json { List(@self.map(|elt| elt.to_json())) } + fn to_json() -> Json { List(self.map(|elt| elt.to_json())) } } -impl HashMap<~str, A>: ToJson { +impl linear::LinearMap<~str, A>: ToJson { fn to_json() -> Json { - let d = map::HashMap(); + let mut d = linear::LinearMap(); for self.each() |key, value| { - d.insert(copy key, value.to_json()); + d.insert(copy *key, value.to_json()); + } + Object(~d) + } +} + +/* +impl @std::map::HashMap<~str, A>: ToJson { + fn to_json() -> Json { + let mut d = linear::LinearMap(); + for self.each_ref |key, value| { + d.insert(copy *key, value.to_json()); } - Dict(d) + Object(~d) } } +*/ impl Option: ToJson { fn to_json() -> Json { @@ -820,7 +1113,7 @@ impl Option: ToJson { } impl Json: to_str::ToStr { - fn to_str() -> ~str { to_str(self) } + fn to_str() -> ~str { to_str(&self) } } impl Error: to_str::ToStr { @@ -831,105 +1124,104 @@ impl Error: to_str::ToStr { #[cfg(test)] mod tests { - #[legacy_exports]; - fn mk_dict(items: &[(~str, Json)]) -> Json { - let d = map::HashMap(); + fn mk_object(items: &[(~str, Json)]) -> Json { + let mut d = ~linear::LinearMap(); - for vec::each(items) |item| { - let (key, value) = copy *item; - d.insert(key, value); + for items.each |item| { + match *item { + (key, value) => { d.insert(copy key, copy value); }, + } }; - Dict(d) + Object(d) } #[test] fn test_write_null() { - assert to_str(Null) == ~"null"; + assert to_str(&Null) == ~"null"; } #[test] - fn test_write_num() { - assert to_str(Num(3f)) == ~"3"; - assert to_str(Num(3.1f)) == ~"3.1"; - assert to_str(Num(-1.5f)) == ~"-1.5"; - assert to_str(Num(0.5f)) == ~"0.5"; + fn test_write_number() { + assert to_str(&Number(3f)) == ~"3"; + assert to_str(&Number(3.1f)) == ~"3.1"; + assert to_str(&Number(-1.5f)) == ~"-1.5"; + assert to_str(&Number(0.5f)) == ~"0.5"; } #[test] fn test_write_str() { - assert to_str(String(@~"")) == ~"\"\""; - assert to_str(String(@~"foo")) == ~"\"foo\""; + assert to_str(&String(~"")) == ~"\"\""; + assert to_str(&String(~"foo")) == ~"\"foo\""; } #[test] fn test_write_bool() { - assert to_str(Boolean(true)) == ~"true"; - assert to_str(Boolean(false)) == ~"false"; + assert to_str(&Boolean(true)) == ~"true"; + assert to_str(&Boolean(false)) == ~"false"; } #[test] fn test_write_list() { - assert to_str(List(@~[])) == ~"[]"; - assert to_str(List(@~[Boolean(true)])) == ~"[true]"; - assert to_str(List(@~[ + assert to_str(&List(~[])) == ~"[]"; + assert to_str(&List(~[Boolean(true)])) == ~"[true]"; + assert to_str(&List(~[ Boolean(false), Null, - List(@~[String(@~"foo\nbar"), Num(3.5f)]) - ])) == ~"[false, null, [\"foo\\nbar\", 3.5]]"; + List(~[String(~"foo\nbar"), Number(3.5f)]) + ])) == ~"[false,null,[\"foo\\nbar\",3.5]]"; } #[test] - fn test_write_dict() { - assert to_str(mk_dict(~[])) == ~"{}"; - assert to_str(mk_dict(~[(~"a", Boolean(true))])) - == ~"{ \"a\": true }"; - let a = mk_dict(~[ + fn test_write_object() { + assert to_str(&mk_object(~[])) == ~"{}"; + assert to_str(&mk_object(~[(~"a", Boolean(true))])) + == ~"{\"a\":true}"; + let a = mk_object(~[ (~"a", Boolean(true)), - (~"b", List(@~[ - mk_dict(~[(~"c", String(@~"\x0c\r"))]), - mk_dict(~[(~"d", String(@~""))]) + (~"b", List(~[ + mk_object(~[(~"c", String(~"\x0c\r"))]), + mk_object(~[(~"d", String(~""))]) ])) ]); - let astr = to_str(a); - let b = result::get(&from_str(astr)); - let bstr = to_str(b); - assert astr == bstr; + // We can't compare the strings directly because the object fields be + // printed in a different order. + let b = result::unwrap(from_str(to_str(&a))); assert a == b; } #[test] fn test_trailing_characters() { assert from_str(~"nulla") == - Err({line: 1u, col: 5u, msg: @~"trailing characters"}); + Err(Error {line: 1u, col: 5u, msg: @~"trailing characters"}); assert from_str(~"truea") == - Err({line: 1u, col: 5u, msg: @~"trailing characters"}); + Err(Error {line: 1u, col: 5u, msg: @~"trailing characters"}); assert from_str(~"falsea") == - Err({line: 1u, col: 6u, msg: @~"trailing characters"}); + Err(Error {line: 1u, col: 6u, msg: @~"trailing characters"}); assert from_str(~"1a") == - Err({line: 1u, col: 2u, msg: @~"trailing characters"}); + Err(Error {line: 1u, col: 2u, msg: @~"trailing characters"}); assert from_str(~"[]a") == - Err({line: 1u, col: 3u, msg: @~"trailing characters"}); + Err(Error {line: 1u, col: 3u, msg: @~"trailing characters"}); assert from_str(~"{}a") == - Err({line: 1u, col: 3u, msg: @~"trailing characters"}); + Err(Error {line: 1u, col: 3u, msg: @~"trailing characters"}); } #[test] fn test_read_identifiers() { assert from_str(~"n") == - Err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"}); assert from_str(~"nul") == - Err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"}); assert from_str(~"t") == - Err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"}); assert from_str(~"truz") == - Err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"}); assert from_str(~"f") == - Err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"}); assert from_str(~"faz") == - Err({line: 1u, col: 3u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 3u, msg: @~"invalid syntax"}); assert from_str(~"null") == Ok(Null); assert from_str(~"true") == Ok(Boolean(true)); @@ -940,125 +1232,125 @@ mod tests { } #[test] - fn test_read_num() { + fn test_read_number() { assert from_str(~"+") == - Err({line: 1u, col: 1u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 1u, msg: @~"invalid syntax"}); assert from_str(~".") == - Err({line: 1u, col: 1u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 1u, msg: @~"invalid syntax"}); assert from_str(~"-") == - Err({line: 1u, col: 2u, msg: @~"invalid number"}); + Err(Error {line: 1u, col: 2u, msg: @~"invalid number"}); assert from_str(~"00") == - Err({line: 1u, col: 2u, msg: @~"invalid number"}); + Err(Error {line: 1u, col: 2u, msg: @~"invalid number"}); assert from_str(~"1.") == - Err({line: 1u, col: 3u, msg: @~"invalid number"}); + Err(Error {line: 1u, col: 3u, msg: @~"invalid number"}); assert from_str(~"1e") == - Err({line: 1u, col: 3u, msg: @~"invalid number"}); + Err(Error {line: 1u, col: 3u, msg: @~"invalid number"}); assert from_str(~"1e+") == - Err({line: 1u, col: 4u, msg: @~"invalid number"}); - - assert from_str(~"3") == Ok(Num(3f)); - assert from_str(~"3.1") == Ok(Num(3.1f)); - assert from_str(~"-1.2") == Ok(Num(-1.2f)); - assert from_str(~"0.4") == Ok(Num(0.4f)); - assert from_str(~"0.4e5") == Ok(Num(0.4e5f)); - assert from_str(~"0.4e+15") == Ok(Num(0.4e15f)); - assert from_str(~"0.4e-01") == Ok(Num(0.4e-01f)); - assert from_str(~" 3 ") == Ok(Num(3f)); + Err(Error {line: 1u, col: 4u, msg: @~"invalid number"}); + + assert from_str(~"3") == Ok(Number(3f)); + assert from_str(~"3.1") == Ok(Number(3.1f)); + assert from_str(~"-1.2") == Ok(Number(-1.2f)); + assert from_str(~"0.4") == Ok(Number(0.4f)); + assert from_str(~"0.4e5") == Ok(Number(0.4e5f)); + assert from_str(~"0.4e+15") == Ok(Number(0.4e15f)); + assert from_str(~"0.4e-01") == Ok(Number(0.4e-01f)); + assert from_str(~" 3 ") == Ok(Number(3f)); } #[test] fn test_read_str() { assert from_str(~"\"") == - Err({line: 1u, col: 2u, msg: @~"EOF while parsing string"}); + Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing string"}); assert from_str(~"\"lol") == - Err({line: 1u, col: 5u, msg: @~"EOF while parsing string"}); - - assert from_str(~"\"\"") == Ok(String(@~"")); - assert from_str(~"\"foo\"") == Ok(String(@~"foo")); - assert from_str(~"\"\\\"\"") == Ok(String(@~"\"")); - assert from_str(~"\"\\b\"") == Ok(String(@~"\x08")); - assert from_str(~"\"\\n\"") == Ok(String(@~"\n")); - assert from_str(~"\"\\r\"") == Ok(String(@~"\r")); - assert from_str(~"\"\\t\"") == Ok(String(@~"\t")); - assert from_str(~" \"foo\" ") == Ok(String(@~"foo")); + Err(Error {line: 1u, col: 5u, msg: @~"EOF while parsing string"}); + + assert from_str(~"\"\"") == Ok(String(~"")); + assert from_str(~"\"foo\"") == Ok(String(~"foo")); + assert from_str(~"\"\\\"\"") == Ok(String(~"\"")); + assert from_str(~"\"\\b\"") == Ok(String(~"\x08")); + assert from_str(~"\"\\n\"") == Ok(String(~"\n")); + assert from_str(~"\"\\r\"") == Ok(String(~"\r")); + assert from_str(~"\"\\t\"") == Ok(String(~"\t")); + assert from_str(~" \"foo\" ") == Ok(String(~"foo")); } #[test] fn test_unicode_hex_escapes_in_str() { - assert from_str(~"\"\\u12ab\"") == Ok(String(@~"\u12ab")); - assert from_str(~"\"\\uAB12\"") == Ok(String(@~"\uAB12")); + assert from_str(~"\"\\u12ab\"") == Ok(String(~"\u12ab")); + assert from_str(~"\"\\uAB12\"") == Ok(String(~"\uAB12")); } #[test] fn test_read_list() { assert from_str(~"[") == - Err({line: 1u, col: 2u, msg: @~"EOF while parsing value"}); + Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing value"}); assert from_str(~"[1") == - Err({line: 1u, col: 3u, msg: @~"EOF while parsing list"}); + Err(Error {line: 1u, col: 3u, msg: @~"EOF while parsing list"}); assert from_str(~"[1,") == - Err({line: 1u, col: 4u, msg: @~"EOF while parsing value"}); + Err(Error {line: 1u, col: 4u, msg: @~"EOF while parsing value"}); assert from_str(~"[1,]") == - Err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"}); assert from_str(~"[6 7]") == - Err({line: 1u, col: 4u, msg: @~"expected `,` or `]`"}); - - assert from_str(~"[]") == Ok(List(@~[])); - assert from_str(~"[ ]") == Ok(List(@~[])); - assert from_str(~"[true]") == Ok(List(@~[Boolean(true)])); - assert from_str(~"[ false ]") == Ok(List(@~[Boolean(false)])); - assert from_str(~"[null]") == Ok(List(@~[Null])); - assert from_str(~"[3, 1]") == Ok(List(@~[Num(3f), Num(1f)])); - assert from_str(~"\n[3, 2]\n") == Ok(List(@~[Num(3f), Num(2f)])); + Err(Error {line: 1u, col: 4u, msg: @~"expected `,` or `]`"}); + + assert from_str(~"[]") == Ok(List(~[])); + assert from_str(~"[ ]") == Ok(List(~[])); + assert from_str(~"[true]") == Ok(List(~[Boolean(true)])); + assert from_str(~"[ false ]") == Ok(List(~[Boolean(false)])); + assert from_str(~"[null]") == Ok(List(~[Null])); + assert from_str(~"[3, 1]") == Ok(List(~[Number(3f), Number(1f)])); + assert from_str(~"\n[3, 2]\n") == Ok(List(~[Number(3f), Number(2f)])); assert from_str(~"[2, [4, 1]]") == - Ok(List(@~[Num(2f), List(@~[Num(4f), Num(1f)])])); + Ok(List(~[Number(2f), List(~[Number(4f), Number(1f)])])); } #[test] - fn test_read_dict() { + fn test_read_object() { assert from_str(~"{") == - Err({line: 1u, col: 2u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing object"}); assert from_str(~"{ ") == - Err({line: 1u, col: 3u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 3u, msg: @~"EOF while parsing object"}); assert from_str(~"{1") == - Err({line: 1u, col: 2u, msg: @~"key must be a string"}); + Err(Error {line: 1u, col: 2u, msg: @~"key must be a string"}); assert from_str(~"{ \"a\"") == - Err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 6u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\"") == - Err({line: 1u, col: 5u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 5u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\" ") == - Err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 6u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\" 1") == - Err({line: 1u, col: 6u, msg: @~"expected `:`"}); + Err(Error {line: 1u, col: 6u, msg: @~"expected `:`"}); assert from_str(~"{\"a\":") == - Err({line: 1u, col: 6u, msg: @~"EOF while parsing value"}); + Err(Error {line: 1u, col: 6u, msg: @~"EOF while parsing value"}); assert from_str(~"{\"a\":1") == - Err({line: 1u, col: 7u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 7u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\":1 1") == - Err({line: 1u, col: 8u, msg: @~"expected `,` or `}`"}); + Err(Error {line: 1u, col: 8u, msg: @~"expected `,` or `}`"}); assert from_str(~"{\"a\":1,") == - Err({line: 1u, col: 8u, msg: @~"EOF while parsing object"}); + Err(Error {line: 1u, col: 8u, msg: @~"EOF while parsing object"}); - assert eq(result::get(&from_str(~"{}")), mk_dict(~[])); - assert eq(result::get(&from_str(~"{\"a\": 3}")), - mk_dict(~[(~"a", Num(3.0f))])); + assert result::unwrap(from_str(~"{}")) == mk_object(~[]); + assert result::unwrap(from_str(~"{\"a\": 3}")) == + mk_object(~[(~"a", Number(3.0f))]); - assert eq(result::get(&from_str(~"{ \"a\": null, \"b\" : true }")), - mk_dict(~[ + assert result::unwrap(from_str(~"{ \"a\": null, \"b\" : true }")) == + mk_object(~[ (~"a", Null), - (~"b", Boolean(true))])); - assert eq(result::get(&from_str( - ~"\n{ \"a\": null, \"b\" : true }\n")), - mk_dict(~[ + (~"b", Boolean(true))]); + assert result::unwrap( + from_str(~"\n{ \"a\": null, \"b\" : true }\n")) == + mk_object(~[ (~"a", Null), - (~"b", Boolean(true))])); - assert eq(result::get(&from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), - mk_dict(~[ - (~"a", Num(1.0)), - (~"b", List(@~[Boolean(true)])) - ])); - assert eq(result::get(&from_str( + (~"b", Boolean(true))]); + assert result::unwrap(from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")) == + mk_object(~[ + (~"a", Number(1.0)), + (~"b", List(~[Boolean(true)])) + ]); + assert result::unwrap(from_str( ~"{" + ~"\"a\": 1.0, " + ~"\"b\": [" + @@ -1066,22 +1358,22 @@ mod tests { ~"\"foo\\nbar\", " + ~"{ \"c\": {\"d\": null} } " + ~"]" + - ~"}")), - mk_dict(~[ - (~"a", Num(1.0f)), - (~"b", List(@~[ + ~"}")) == + mk_object(~[ + (~"a", Number(1.0f)), + (~"b", List(~[ Boolean(true), - String(@~"foo\nbar"), - mk_dict(~[ - (~"c", mk_dict(~[(~"d", Null)])) + String(~"foo\nbar"), + mk_object(~[ + (~"c", mk_object(~[(~"d", Null)])) ]) ])) - ])); + ]); } #[test] fn test_multiline_errors() { assert from_str(~"{\n \"foo\":\n \"bar\"") == - Err({line: 3u, col: 8u, msg: @~"EOF while parsing object"}); + Err(Error {line: 3u, col: 8u, msg: @~"EOF while parsing object"}); } } diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 9088f6e3584..7ef4ef22560 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -1,6 +1,7 @@ extern mod std; use io::WriterUtil; use std::map::HashMap; +use std::json; enum object { @@ -8,13 +9,13 @@ enum object int_value(i64), } -fn lookup(table: std::map::HashMap<~str, std::json::Json>, key: ~str, default: ~str) -> ~str +fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str { - match table.find(key) + match table.find(&key) { option::Some(std::json::String(s)) => { - *s + s } option::Some(value) => { @@ -32,7 +33,7 @@ fn add_interface(store: int, managed_ip: ~str, data: std::json::Json) -> (~str, { match data { - std::json::Dict(interface) => + std::json::Object(interface) => { let name = lookup(interface, ~"ifDescr", ~""); let label = fmt!("%s-%s", managed_ip, name); @@ -53,7 +54,7 @@ fn add_interfaces(store: int, managed_ip: ~str, device: std::map::HashMap<~str, { std::json::List(interfaces) => { - do vec::map(*interfaces) |interface| { + do vec::map(interfaces) |interface| { add_interface(store, managed_ip, *interface) } } -- cgit 1.4.1-3-g733a5 From 26a8fe35537ec9dbd7bbd34479673b2f6d935140 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 26 Sep 2012 17:03:02 -0700 Subject: Fix test/run-pass/issue-2904 --- src/test/run-pass/issue-2904.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 704e8f79fb1..3eb6561eb96 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -1,5 +1,7 @@ /// Map representation +use io::ReaderUtil; + extern mod std; enum square { @@ -50,7 +52,7 @@ fn read_board_grid(+in: rdr) -> ~[~[square]] { let mut grid = ~[]; for in.each_line |line| { let mut row = ~[]; - for line.each_char |c| { + for str::each_char(line) |c| { vec::push(row, square_from_char(c)) } vec::push(grid, row) -- cgit 1.4.1-3-g733a5 From 67a8e7128aea292445b763b47b04bc5f4fd43cb2 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 26 Sep 2012 17:33:34 -0700 Subject: Demode vec::push (and convert to method) --- doc/rust.md | 2 +- doc/tutorial.md | 2 +- src/cargo/cargo.rs | 4 +- src/compiletest/compiletest.rs | 2 +- src/compiletest/header.rs | 6 +- src/compiletest/procsrv.rs | 2 +- src/compiletest/runtest.rs | 2 +- src/fuzzer/cycles.rs | 4 +- src/fuzzer/fuzzer.rs | 4 +- src/fuzzer/ivec_fuzz.rs | 8 +- src/fuzzer/rand_util.rs | 2 +- src/libcore/core.rs | 2 + src/libcore/dvec.rs | 8 +- src/libcore/either.rs | 28 +-- src/libcore/extfmt.rs | 4 +- src/libcore/flate.rs | 4 +- src/libcore/float.rs | 2 +- src/libcore/io.rs | 18 +- src/libcore/os.rs | 2 +- src/libcore/path.rs | 10 +- src/libcore/pipes.rs | 2 +- src/libcore/private.rs | 2 +- src/libcore/rand.rs | 2 +- src/libcore/result.rs | 4 +- src/libcore/run.rs | 12 +- src/libcore/send_map.rs | 15 +- src/libcore/str.rs | 23 ++- src/libcore/vec.rs | 189 ++++++++++++--------- src/libstd/arc.rs | 4 +- src/libstd/base64.rs | 12 +- src/libstd/deque.rs | 4 +- src/libstd/ebml.rs | 2 +- src/libstd/ebml2.rs | 2 +- src/libstd/getopts.rs | 21 ++- src/libstd/json.rs | 29 ++-- src/libstd/md4.rs | 4 +- src/libstd/net_ip.rs | 2 +- src/libstd/net_tcp.rs | 4 +- src/libstd/net_url.rs | 2 +- src/libstd/par.rs | 2 +- src/libstd/rope.rs | 2 +- src/libstd/sort.rs | 4 +- src/libstd/sync.rs | 8 +- src/libstd/test.rs | 4 +- src/libsyntax/ast_map.rs | 4 +- src/libsyntax/ast_util.rs | 4 +- src/libsyntax/attr.rs | 2 +- src/libsyntax/codemap.rs | 4 +- src/libsyntax/ext/auto_serialize2.rs | 2 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/fmt.rs | 4 +- src/libsyntax/ext/pipes/liveness.rs | 2 +- src/libsyntax/ext/pipes/pipec.rs | 86 +++++----- src/libsyntax/ext/simplext.rs | 13 +- src/libsyntax/ext/tt/macro_parser.rs | 24 +-- src/libsyntax/ext/tt/transcribe.rs | 4 +- src/libsyntax/fold.rs | 10 +- src/libsyntax/parse/comments.rs | 14 +- src/libsyntax/parse/common.rs | 4 +- src/libsyntax/parse/eval.rs | 6 +- src/libsyntax/parse/parser.rs | 136 +++++++-------- src/rustc/back/link.rs | 42 ++--- src/rustc/back/rpath.rs | 10 +- src/rustc/back/upcall.rs | 2 +- src/rustc/driver/driver.rs | 4 +- src/rustc/front/test.rs | 4 +- src/rustc/metadata/cstore.rs | 8 +- src/rustc/metadata/decoder.rs | 40 ++--- src/rustc/metadata/encoder.rs | 55 +++--- src/rustc/metadata/filesearch.rs | 10 +- src/rustc/metadata/loader.rs | 2 +- src/rustc/metadata/tydecode.rs | 16 +- src/rustc/middle/capture.rs | 2 +- src/rustc/middle/check_alt.rs | 4 +- src/rustc/middle/freevars.rs | 2 +- src/rustc/middle/kind.rs | 8 +- src/rustc/middle/lint.rs | 2 +- src/rustc/middle/liveness.rs | 6 +- src/rustc/middle/pat_util.rs | 2 +- src/rustc/middle/region.rs | 2 +- src/rustc/middle/resolve.rs | 6 +- src/rustc/middle/trans/alt.rs | 12 +- src/rustc/middle/trans/base.rs | 16 +- src/rustc/middle/trans/build.rs | 2 +- src/rustc/middle/trans/callee.rs | 10 +- src/rustc/middle/trans/closure.rs | 20 +-- src/rustc/middle/trans/common.rs | 24 +-- src/rustc/middle/trans/debuginfo.rs | 4 +- src/rustc/middle/trans/expr.rs | 4 +- src/rustc/middle/trans/foreign.rs | 22 +-- src/rustc/middle/trans/monomorphize.rs | 2 +- src/rustc/middle/trans/tvec.rs | 4 +- src/rustc/middle/trans/type_of.rs | 10 +- src/rustc/middle/ty.rs | 46 ++--- src/rustc/middle/typeck/check.rs | 11 +- src/rustc/middle/typeck/check/regionmanip.rs | 4 +- src/rustc/middle/typeck/check/vtable.rs | 10 +- src/rustc/middle/typeck/check/writeback.rs | 2 +- src/rustc/middle/typeck/coherence.rs | 9 +- .../middle/typeck/infer/region_var_bindings.rs | 8 +- src/rustc/middle/typeck/infer/resolve.rs | 2 +- src/rustc/middle/typeck/infer/unify.rs | 2 +- src/rustc/util/common.rs | 2 +- src/rustc/util/ppaux.rs | 6 +- src/rustdoc/extract.rs | 2 +- src/rustdoc/path_pass.rs | 4 +- src/test/bench/core-std.rs | 6 +- src/test/bench/core-vec-append.rs | 2 +- src/test/bench/graph500-bfs.rs | 2 +- src/test/bench/msgsend-pipes-shared.rs | 2 +- src/test/bench/msgsend-pipes.rs | 2 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 4 +- src/test/bench/msgsend-ring-pipes.rs | 2 +- src/test/bench/msgsend-ring-rw-arcs.rs | 4 +- src/test/bench/msgsend-ring.rs | 2 +- src/test/bench/msgsend.rs | 2 +- src/test/bench/shootout-chameneos-redux.rs | 2 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/bench/shootout-pfib.rs | 2 +- src/test/bench/task-perf-one-million.rs | 2 +- src/test/bench/task-perf-word-count-generic.rs | 7 +- src/test/compile-fail/purity-infer-fail.rs | 2 +- src/test/run-fail/zip-different-lengths.rs | 4 +- src/test/run-pass/auto-ref-sliceable.rs | 2 +- src/test/run-pass/autoref-vec-push.rs | 17 -- src/test/run-pass/borrowck-mut-uniq.rs | 2 +- src/test/run-pass/issue-2904.rs | 7 +- src/test/run-pass/task-comm-3.rs | 2 +- src/test/run-pass/task-comm.rs | 4 +- src/test/run-pass/vec-push.rs | 2 +- src/test/run-pass/zip-same-length.rs | 4 +- 134 files changed, 684 insertions(+), 670 deletions(-) delete mode 100644 src/test/run-pass/autoref-vec-push.rs (limited to 'src/test') diff --git a/doc/rust.md b/doc/rust.md index ccc5a532cdd..6f6a7bb86b6 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -1016,7 +1016,7 @@ fn iter(seq: ~[T], f: fn(T)) { } fn map(seq: ~[T], f: fn(T) -> U) -> ~[U] { let mut acc = ~[]; - for seq.each |elt| { vec::push(acc, f(elt)); } + for seq.each |elt| { acc.push(f(elt)); } acc } ~~~~ diff --git a/doc/tutorial.md b/doc/tutorial.md index 7244206b2eb..4b76152cdb0 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1651,7 +1651,7 @@ may be invoked on multiple types. fn map(vector: &[T], function: fn(v: &T) -> U) -> ~[U] { let mut accumulator = ~[]; for vec::each(vector) |element| { - vec::push(accumulator, function(element)); + accumulator.push(function(element)); } return accumulator; } diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index b5c9fc17416..853060ea571 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -345,7 +345,7 @@ fn load_crate(filename: &Path) -> Option { match *ps.interner.get(attr_name) { ~"std" | ~"core" => (), - _ => vec::push(e.deps, query) + _ => e.deps.push(query) } } _ => () @@ -801,7 +801,7 @@ fn install_source(c: &Cargo, path: &Path) { let mut cratefiles = ~[]; for os::walk_dir(&Path(".")) |p| { if p.filetype() == Some(~".rc") { - vec::push(cratefiles, *p); + cratefiles.push(*p); } } diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 5bee7fb255d..8d48669ab17 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -141,7 +141,7 @@ fn make_tests(config: config) -> ~[test::TestDesc] { let file = copy *file; debug!("inspecting file %s", file.to_str()); if is_test(config, file) { - vec::push(tests, make_test(config, file)) + tests.push(make_test(config, file)) } } return tests; diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 5cd54a115ff..19a3c621d27 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -28,7 +28,7 @@ fn load_props(testfile: &Path) -> test_props { let mut pp_exact = option::None; for iter_header(testfile) |ln| { match parse_error_pattern(ln) { - option::Some(ep) => vec::push(error_patterns, ep), + option::Some(ep) => error_patterns.push(ep), option::None => () }; @@ -41,11 +41,11 @@ fn load_props(testfile: &Path) -> test_props { } do parse_aux_build(ln).iter |ab| { - vec::push(aux_builds, ab); + aux_builds.push(ab); } do parse_exec_env(ln).iter |ee| { - vec::push(exec_env, ee); + exec_env.push(ee); } }; return { diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index d62f2fe5837..641425f2b8e 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -19,7 +19,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] { else { (k,v) } }; if str::ends_with(prog, ~"rustc.exe") { - vec::push(env, (~"RUST_THREADS", ~"1")); + env.push((~"RUST_THREADS", ~"1")); } return env; } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index fcb007eca8b..dae5105ce71 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -121,7 +121,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) { procres); } - vec::push(srcs, procres.stdout); + srcs.push(procres.stdout); round += 1; } diff --git a/src/fuzzer/cycles.rs b/src/fuzzer/cycles.rs index 17ed1c0fb96..ec263ead954 100644 --- a/src/fuzzer/cycles.rs +++ b/src/fuzzer/cycles.rs @@ -62,7 +62,7 @@ fn test_cycles(r : rand::rng, k: uint, n: uint) // Create a graph with no edges range(0u, vlen) {|_i| - vec::push(v, empty_pointy()); + v.push(empty_pointy()); } // Fill in the graph with random edges, with density k/n @@ -77,7 +77,7 @@ fn test_cycles(r : rand::rng, k: uint, n: uint) // https://github.com/mozilla/rust/issues/1899 if (likelihood(r, k, n)) { v[i].m = [p(choice(r, v))]; } - if (likelihood(r, k, n)) { vec::push(v[i].n, mut p(choice(r, v))); } + if (likelihood(r, k, n)) { v[i].n.push(mut p(choice(r, v))); } if (likelihood(r, k, n)) { v[i].o = {x: 0, y: p(choice(r, v))}; } } diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 9f1cc419d15..5329d3c14dc 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -30,7 +30,7 @@ fn contains(haystack: ~str, needle: ~str) -> bool { fn find_rust_files(files: &mut ~[Path], path: &Path) { if path.filetype() == Some(~".rs") && !contains(path.to_str(), ~"utf8") { // ignoring "utf8" tests because something is broken - vec::push(*files, *path); + files.push(*path); } else if os::path_is_dir(path) && !contains(path.to_str(), ~"compile-fail") && !contains(path.to_str(), ~"build") { @@ -124,7 +124,7 @@ fn stash_ty_if(c: fn@(@ast::ty, test_mode)->bool, e: @ast::ty, tm: test_mode) { if c(e, tm) { - vec::push(*es,*e); + es.push(e); } else {/* now my indices are wrong :( */ } } diff --git a/src/fuzzer/ivec_fuzz.rs b/src/fuzzer/ivec_fuzz.rs index 9351e23acf0..49d34e76992 100644 --- a/src/fuzzer/ivec_fuzz.rs +++ b/src/fuzzer/ivec_fuzz.rs @@ -55,11 +55,11 @@ fn vec_edits(v: ~[T], xs: ~[T]) -> ~[~[T]] { if Lv != 1u { // When Lv == 1u, this is redundant with omit. - vec::push(edits, ~[]); + edits.push(~[]); } if Lv >= 3u { // When Lv == 2u, this is redundant with swap. - vec::push(edits, vec::reversed(v)); + edits.push(vec::reversed(v)); } ix(0u, 1u, Lv) {|i| edits += ~[vec_omit(v, i)]; } ix(0u, 1u, Lv) {|i| edits += ~[vec_dup(v, i)]; } @@ -69,10 +69,10 @@ fn vec_edits(v: ~[T], xs: ~[T]) -> ~[~[T]] { ix(0u, 1u, len(xs)) {|j| ix(0u, 1u, Lv) {|i| - vec::push(edits, vec_poke(v, i, xs[j])); + edits.push(vec_poke(v, i, xs[j])); } ix(0u, 0u, Lv) {|i| - vec::push(edits, vec_insert(v, i, xs[j])); + edits.push(vec_insert(v, i, xs[j])); } } diff --git a/src/fuzzer/rand_util.rs b/src/fuzzer/rand_util.rs index 39301d17a45..6745805e2d8 100644 --- a/src/fuzzer/rand_util.rs +++ b/src/fuzzer/rand_util.rs @@ -61,7 +61,7 @@ fn weighted_vec(v : ~[weighted]) -> ~[T] { for {weight: weight, item: item} in v { let i = 0u; while i < weight { - vec::push(r, item); + r.push(item); i += 1u; } } diff --git a/src/libcore/core.rs b/src/libcore/core.rs index 8806131c9fb..dae77d66f25 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -17,6 +17,7 @@ use tuple::{TupleOps, ExtendedTupleOps}; use str::{StrSlice, UniqueStr}; use vec::{ConstVector, CopyableVector, ImmutableVector}; use vec::{ImmutableEqVector, ImmutableCopyableVector}; +use vec::{MutableVector, MutableCopyableVector}; use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter}; use iter::{CopyableOrderedIter, Times, TimesIx}; use num::Num; @@ -33,6 +34,7 @@ export Num, Times, TimesIx; export StrSlice, UniqueStr; export ConstVector, CopyableVector, ImmutableVector; export ImmutableEqVector, ImmutableCopyableVector, IterTraitExtensions; +export MutableVector, MutableCopyableVector; export BaseIter, CopyableIter, CopyableOrderedIter, ExtendedIter, EqIter; export TupleOps, ExtendedTupleOps; export Ptr; diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 9d3d2e97f9a..eb221926fc1 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -172,7 +172,7 @@ impl DVec { if data_ptr.is_null() { fail ~"Recursive use of dvec"; } log(error, ~"a"); self.data <- ~[move t]; - vec::push_all_move(self.data, move data); + self.data.push_all_move(move data); log(error, ~"b"); } } @@ -180,7 +180,7 @@ impl DVec { /// Append a single item to the end of the list fn push(+t: A) { self.check_not_borrowed(); - vec::push(self.data, move t); + self.data.push(move t); } /// Remove and return the first element @@ -240,7 +240,7 @@ impl DVec { vec::reserve(&mut v, new_len); let mut i = from_idx; while i < to_idx { - vec::push(v, ts[i]); + v.push(ts[i]); i += 1u; } move v @@ -266,7 +266,7 @@ impl DVec { } }; - for ts.each |t| { vec::push(v, *t) }; + for ts.each |t| { v.push(*t) }; v } } diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 55e22f7cfe9..d93074e4a40 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -32,27 +32,27 @@ fn either(f_left: fn((&T)) -> V, fn lefts(eithers: &[Either]) -> ~[T] { //! Extracts from a vector of either all the left values - let mut result: ~[T] = ~[]; - for vec::each(eithers) |elt| { - match *elt { - Left(l) => vec::push(result, l), - _ => { /* fallthrough */ } + do vec::build_sized(eithers.len()) |push| { + for vec::each(eithers) |elt| { + match *elt { + Left(ref l) => { push(*l); } + _ => { /* fallthrough */ } + } } } - move result } fn rights(eithers: &[Either]) -> ~[U] { //! Extracts from a vector of either all the right values - let mut result: ~[U] = ~[]; - for vec::each(eithers) |elt| { - match *elt { - Right(r) => vec::push(result, r), - _ => { /* fallthrough */ } + do vec::build_sized(eithers.len()) |push| { + for vec::each(eithers) |elt| { + match *elt { + Right(ref r) => { push(*r); } + _ => { /* fallthrough */ } + } } } - move result } fn partition(eithers: &[Either]) @@ -68,8 +68,8 @@ fn partition(eithers: &[Either]) let mut rights: ~[U] = ~[]; for vec::each(eithers) |elt| { match *elt { - Left(l) => vec::push(lefts, l), - Right(r) => vec::push(rights, r) + Left(l) => lefts.push(l), + Right(r) => rights.push(r) } } return {lefts: move lefts, rights: move rights}; diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 9a992143a11..fda3f50ca29 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -90,7 +90,7 @@ mod ct { fn flush_buf(+buf: ~str, &pieces: ~[Piece]) -> ~str { if str::len(buf) > 0 { let piece = PieceString(move buf); - vec::push(pieces, move piece); + pieces.push(move piece); } return ~""; } @@ -110,7 +110,7 @@ mod ct { } else { buf = flush_buf(move buf, pieces); let rs = parse_conversion(s, i, lim, error); - vec::push(pieces, copy rs.piece); + pieces.push(copy rs.piece); i = rs.next; } } else { buf += curr; i += size; } diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index b75894e0c1b..6b4c93949e5 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -71,12 +71,12 @@ fn test_flate_round_trip() { let r = rand::Rng(); let mut words = ~[]; for 20.times { - vec::push(words, r.gen_bytes(r.gen_uint_range(1, 10))); + words.push(r.gen_bytes(r.gen_uint_range(1, 10))); } for 20.times { let mut in = ~[]; for 2000.times { - vec::push_all(in, r.choose(words)); + in.push_all(r.choose(words)); } debug!("de/inflate of %u bytes of random word-sequences", in.len()); diff --git a/src/libcore/float.rs b/src/libcore/float.rs index eaa51814056..cf8a10b9c7b 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -143,7 +143,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { // store the next digit frac *= 10.0; let digit = frac as uint; - vec::push(fractionalParts, digit); + fractionalParts.push(digit); // calculate the next frac frac -= digit as float; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 97039800fb6..385df30e824 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -76,7 +76,7 @@ impl T : ReaderUtil { loop { let ch = self.read_byte(); if ch == -1 || ch == 10 { break; } - vec::push(buf, ch as u8); + buf.push(ch as u8); } str::from_bytes(buf) } @@ -94,7 +94,7 @@ impl T : ReaderUtil { i += 1; assert (w > 0); if w == 1 { - vec::push(*chars, b0 as char); + chars.push(b0 as char); loop; } // can't satisfy this char with the existing data @@ -113,7 +113,7 @@ impl T : ReaderUtil { // See str::char_at val += ((b0 << ((w + 1) as u8)) as uint) << (w - 1) * 6 - w - 1u; - vec::push(*chars, val as char); + chars.push(val as char); } return (i, 0); } @@ -128,7 +128,7 @@ impl T : ReaderUtil { // we're split in a unicode char? break; } - vec::push_all(buf, data); + buf.push_all(data); let (offset, nbreq) = chars_from_bytes::(&buf, &mut chars); let ncreq = n - chars.len(); // again we either know we need a certain number of bytes @@ -155,7 +155,7 @@ impl T : ReaderUtil { let mut buf: ~[u8] = ~[]; loop { let ch = self.read_byte(); - if ch < 1 { break; } else { vec::push(buf, ch as u8); } + if ch < 1 { break; } else { buf.push(ch as u8); } } str::from_bytes(buf) } @@ -190,7 +190,7 @@ impl T : ReaderUtil { fn read_whole_stream() -> ~[u8] { let mut buf: ~[u8] = ~[]; - while !self.eof() { vec::push_all(buf, self.read_bytes(2048u)); } + while !self.eof() { buf.push_all(self.read_bytes(2048u)); } move buf } @@ -503,7 +503,7 @@ fn u64_to_le_bytes(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { let mut bytes: ~[u8] = ~[], i = size, n = n; while i > 0u { - vec::push(bytes, (n & 255_u64) as u8); + bytes.push((n & 255_u64) as u8); n >>= 8_u64; i -= 1u; } @@ -535,7 +535,7 @@ fn u64_to_be_bytes(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { let mut i = size; while i > 0u { let shift = ((i - 1u) * 8u) as u64; - vec::push(bytes, (n >> shift) as u8); + bytes.push((n >> shift) as u8); i -= 1u; } f(bytes) @@ -737,7 +737,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str { let mut v = with_bytes_writer(f); // Make sure the vector has a trailing null and is proper utf8. - vec::push(v, 0); + v.push(0); assert str::is_utf8(v); unsafe { move ::cast::transmute(v) } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index b4c284cbd82..0a2f00e3f2b 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -219,7 +219,7 @@ mod global_env { for vec::each(rustrt::rust_env_pairs()) |p| { let vs = str::splitn_char(*p, '=', 1u); assert vec::len(vs) == 2u; - vec::push(pairs, (copy vs[0], copy vs[1])); + pairs.push((copy vs[0], copy vs[1])); } move pairs } diff --git a/src/libcore/path.rs b/src/libcore/path.rs index ab847702d68..505ecff2bcf 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -206,7 +206,7 @@ impl PosixPath : GenericPath { let mut ss = str::split_nonempty( *e, |c| windows::is_sep(c as u8)); - unsafe { vec::push_all_move(v, move ss); } + unsafe { v.push_all_move(move ss); } } PosixPath { components: move v, ..self } } @@ -214,7 +214,7 @@ impl PosixPath : GenericPath { pure fn push(s: &str) -> PosixPath { let mut v = copy self.components; let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8)); - unsafe { vec::push_all_move(v, move ss); } + unsafe { v.push_all_move(move ss); } PosixPath { components: move v, ..self } } @@ -400,7 +400,7 @@ impl WindowsPath : GenericPath { let mut ss = str::split_nonempty( *e, |c| windows::is_sep(c as u8)); - unsafe { vec::push_all_move(v, move ss); } + unsafe { v.push_all_move(move ss); } } return WindowsPath { components: move v, ..self } } @@ -408,7 +408,7 @@ impl WindowsPath : GenericPath { pure fn push(s: &str) -> WindowsPath { let mut v = copy self.components; let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8)); - unsafe { vec::push_all_move(v, move ss); } + unsafe { v.push_all_move(move ss); } return WindowsPath { components: move v, ..self } } @@ -440,7 +440,7 @@ pure fn normalize(components: &[~str]) -> ~[~str] { vec::pop(cs); loop; } - vec::push(cs, copy *c); + cs.push(copy *c); } } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index bbabceafe8e..c4a7fa1437a 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -1059,7 +1059,7 @@ pub fn PortSet() -> PortSet{ impl PortSet : Recv { fn add(+port: pipes::Port) { - vec::push(self.ports, move port) + self.ports.push(move port) } fn chan() -> Chan { diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 4021ad5e88f..7eba81803b3 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -564,7 +564,7 @@ pub mod tests { for uint::range(0u, num_tasks) |_i| { let total = total.clone(); - vec::push(futures, future::spawn(|| { + futures.push(future::spawn(|| { for uint::range(0u, count) |_i| { do total.with |count| { **count += 1u; diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 02aa8530072..d68bd97ae5d 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -215,7 +215,7 @@ impl Rng { let mut r = ~[]; for v.each |item| { for uint::range(0u, item.weight) |_i| { - vec::push(r, item.item); + r.push(item.item); } } move r diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7644175f93c..3968b0264d9 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -280,7 +280,7 @@ fn map_vec( let mut vs: ~[V] = vec::with_capacity(vec::len(ts)); for vec::each(ts) |t| { match op(t) { - Ok(v) => vec::push(vs, v), + Ok(v) => vs.push(v), Err(u) => return Err(u) } } @@ -317,7 +317,7 @@ fn map_vec2(ss: &[S], ts: &[T], let mut i = 0u; while i < n { match op(&ss[i],&ts[i]) { - Ok(v) => vec::push(vs, v), + Ok(v) => vs.push(v), Err(u) => return Err(u) } i += 1u; diff --git a/src/libcore/run.rs b/src/libcore/run.rs index e3e8491e15a..abeff1bd1d6 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -82,10 +82,10 @@ fn with_argv(prog: &str, args: &[~str], let mut tmps = ~[]; for vec::each(args) |arg| { let t = @copy *arg; - vec::push(tmps, t); - vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b])); + tmps.push(t); + argptrs.push_all(str::as_c_str(*t, |b| ~[b])); } - vec::push(argptrs, ptr::null()); + argptrs.push(ptr::null()); vec::as_imm_buf(argptrs, |buf, _len| cb(buf)) } @@ -102,10 +102,10 @@ fn with_envp(env: &Option<~[(~str,~str)]>, for vec::each(es) |e| { let (k,v) = copy *e; let t = @(fmt!("%s=%s", k, v)); - vec::push(tmps, t); - vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b])); + tmps.push(t); + ptrs.push_all(str::as_c_str(*t, |b| ~[b])); } - vec::push(ptrs, ptr::null()); + ptrs.push(ptr::null()); vec::as_imm_buf(ptrs, |p, _len| unsafe { cb(::cast::reinterpret_cast(&p)) } ) diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index ac9a012c373..7ed962b4a90 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -283,18 +283,9 @@ pub mod linear { FoundEntry(idx) => { match self.buckets[idx] { Some(ref bkt) => { - let ptr = unsafe { - // FIXME(#3148)--region inference - // fails to capture needed deps. - // Here, the bucket value is known to - // live as long as self, because self - // is immutable. But the region - // inference stupidly infers a - // lifetime for `ref bkt` that is - // shorter than it needs to be. - cast::copy_lifetime(self, &bkt.value) - }; - Some(ptr) + // FIXME(#3148)---should be inferred + let bkt: &self/Bucket = bkt; + Some(&bkt.value) } None => { fail ~"LinearMap::find: internal logic error" diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 13fb2260045..0993d1df63f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -468,7 +468,7 @@ pure fn chars(s: &str) -> ~[char] { let len = len(s); while i < len { let {ch, next} = char_range_at(s, i); - unsafe { vec::push(buf, ch); } + unsafe { buf.push(ch); } i = next; } move buf @@ -537,8 +537,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool) while i < l && done < count { if s[i] == b { if allow_empty || start < i unsafe { - vec::push(result, - unsafe { raw::slice_bytes(s, start, i) }); + result.push(unsafe { raw::slice_bytes(s, start, i) }); } start = i + 1u; done += 1u; @@ -546,7 +545,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool) i += 1u; } if allow_empty || start < l { - unsafe { vec::push(result, raw::slice_bytes(s, start, l) ) }; + unsafe { result.push(raw::slice_bytes(s, start, l) ) }; } move result } else { @@ -581,7 +580,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint, let {ch, next} = char_range_at(s, i); if sepfn(ch) { if allow_empty || start < i unsafe { - vec::push(result, unsafe { raw::slice_bytes(s, start, i)}); + result.push(unsafe { raw::slice_bytes(s, start, i)}); } start = next; done += 1u; @@ -589,7 +588,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint, i = next; } if allow_empty || start < l unsafe { - vec::push(result, unsafe { raw::slice_bytes(s, start, l) }); + result.push(unsafe { raw::slice_bytes(s, start, l) }); } move result } @@ -643,7 +642,7 @@ pure fn iter_between_matches(s: &a/str, sep: &b/str, f: fn(uint, uint)) { pure fn split_str(s: &a/str, sep: &b/str) -> ~[~str] { let mut result = ~[]; do iter_between_matches(s, sep) |from, to| { - unsafe { vec::push(result, raw::slice_bytes(s, from, to)); } + unsafe { result.push(raw::slice_bytes(s, from, to)); } } move result } @@ -652,7 +651,7 @@ pure fn split_str_nonempty(s: &a/str, sep: &b/str) -> ~[~str] { let mut result = ~[]; do iter_between_matches(s, sep) |from, to| { if to > from { - unsafe { vec::push(result, raw::slice_bytes(s, from, to)); } + unsafe { result.push(raw::slice_bytes(s, from, to)); } } } move result @@ -1535,14 +1534,14 @@ pure fn to_utf16(s: &str) -> ~[u16] { if (ch & 0xFFFF_u32) == ch unsafe { // The BMP falls through (assuming non-surrogate, as it should) assert ch <= 0xD7FF_u32 || ch >= 0xE000_u32; - vec::push(u, ch as u16) + u.push(ch as u16) } else unsafe { // Supplementary planes break into surrogates. assert ch >= 0x1_0000_u32 && ch <= 0x10_FFFF_u32; ch -= 0x1_0000_u32; let w1 = 0xD800_u16 | ((ch >> 10) as u16); let w2 = 0xDC00_u16 | ((ch as u16) & 0x3FF_u16); - vec::push_all(u, ~[w1, w2]) + u.push_all(~[w1, w2]) } } move u @@ -2010,7 +2009,7 @@ mod raw { ptr::memcpy(vbuf, buf as *u8, len) }); vec::raw::set_len(v, len); - vec::push(v, 0u8); + v.push(0u8); assert is_utf8(v); return ::cast::transmute(move v); @@ -2067,7 +2066,7 @@ mod raw { ptr::memcpy(vbuf, src, end - begin); } vec::raw::set_len(v, end - begin); - vec::push(v, 0u8); + v.push(0u8); ::cast::transmute(move v) } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 7c5f242e8ba..50011dbacec 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -92,6 +92,8 @@ export CopyableVector; export ImmutableVector; export ImmutableEqVector; export ImmutableCopyableVector; +export MutableVector; +export MutableCopyableVector; export IterTraitExtensions; export vec_concat; export traits; @@ -238,7 +240,7 @@ pure fn with_capacity(capacity: uint) -> ~[T] { pure fn build_sized(size: uint, builder: fn(push: pure fn(+v: A))) -> ~[A] { let mut vec = with_capacity(size); - builder(|+x| unsafe { push(vec, move x) }); + builder(|+x| unsafe { vec.push(move x) }); move vec } @@ -330,7 +332,7 @@ pure fn slice(v: &[const T], start: uint, end: uint) -> ~[T] { assert (end <= len(v)); let mut result = ~[]; unsafe { - for uint::range(start, end) |i| { vec::push(result, v[i]) } + for uint::range(start, end) |i| { result.push(v[i]) } } move result } @@ -383,14 +385,14 @@ fn split(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while start < ln { match position_between(v, start, ln, f) { - None => break, - Some(i) => { - push(result, slice(v, start, i)); - start = i + 1u; - } + None => break, + Some(i) => { + result.push(slice(v, start, i)); + start = i + 1u; + } } } - push(result, slice(v, start, ln)); + result.push(slice(v, start, ln)); move result } @@ -407,16 +409,16 @@ fn splitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while start < ln && count > 0u { match position_between(v, start, ln, f) { - None => break, - Some(i) => { - push(result, slice(v, start, i)); - // Make sure to skip the separator. - start = i + 1u; - count -= 1u; - } + None => break, + Some(i) => { + result.push(slice(v, start, i)); + // Make sure to skip the separator. + start = i + 1u; + count -= 1u; + } } } - push(result, slice(v, start, ln)); + result.push(slice(v, start, ln)); move result } @@ -432,14 +434,14 @@ fn rsplit(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while end > 0u { match rposition_between(v, 0u, end, f) { - None => break, - Some(i) => { - push(result, slice(v, i + 1u, end)); - end = i; - } + None => break, + Some(i) => { + result.push(slice(v, i + 1u, end)); + end = i; + } } } - push(result, slice(v, 0u, end)); + result.push(slice(v, 0u, end)); reverse(result); return move result; } @@ -457,16 +459,16 @@ fn rsplitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while end > 0u && count > 0u { match rposition_between(v, 0u, end, f) { - None => break, - Some(i) => { - push(result, slice(v, i + 1u, end)); - // Make sure to skip the separator. - end = i; - count -= 1u; - } + None => break, + Some(i) => { + result.push(slice(v, i + 1u, end)); + // Make sure to skip the separator. + end = i; + count -= 1u; + } } } - push(result, slice(v, 0u, end)); + result.push(slice(v, 0u, end)); reverse(result); move result } @@ -489,7 +491,7 @@ fn shift(&v: ~[T]) -> T { for uint::range(1, ln) |i| { let r <- *ptr::offset(vv, i); - push(v, move r); + v.push(move r); } } raw::set_len(vv, 0); @@ -503,7 +505,7 @@ fn unshift(&v: ~[T], +x: T) { let mut vv = ~[move x]; v <-> vv; while len(vv) > 0 { - push(v, shift(vv)); + v.push(shift(vv)); } } @@ -568,9 +570,9 @@ fn swap_remove(&v: ~[const T], index: uint) -> T { /// Append an element to a vector #[inline(always)] -fn push(&v: ~[T], +initval: T) { +fn push(v: &mut ~[T], +initval: T) { unsafe { - let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::transmute(copy v); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, move initval); @@ -583,8 +585,8 @@ fn push(&v: ~[T], +initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please -unsafe fn push_fast(&v: ~[T], +initval: T) { - let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); +unsafe fn push_fast(+v: &mut ~[T], +initval: T) { + let repr: **raw::VecRepr = ::cast::transmute(v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); let p = ptr::addr_of((**repr).unboxed.data); @@ -593,14 +595,14 @@ unsafe fn push_fast(&v: ~[T], +initval: T) { } #[inline(never)] -fn push_slow(&v: ~[T], +initval: T) { - reserve_at_least(&mut v, v.len() + 1u); +fn push_slow(+v: &mut ~[T], +initval: T) { + reserve_at_least(v, v.len() + 1u); unsafe { push_fast(v, move initval) } } #[inline(always)] -fn push_all(&v: ~[T], rhs: &[const T]) { - reserve(&mut v, v.len() + rhs.len()); +fn push_all(+v: &mut ~[T], rhs: &[const T]) { + reserve(v, v.len() + rhs.len()); for uint::range(0u, rhs.len()) |i| { push(v, unsafe { raw::get(rhs, i) }) @@ -608,8 +610,8 @@ fn push_all(&v: ~[T], rhs: &[const T]) { } #[inline(always)] -fn push_all_move(&v: ~[T], -rhs: ~[const T]) { - reserve(&mut v, v.len() + rhs.len()); +fn push_all_move(v: &mut ~[T], -rhs: ~[const T]) { + reserve(v, v.len() + rhs.len()); unsafe { do as_imm_buf(rhs) |p, len| { for uint::range(0, len) |i| { @@ -675,7 +677,7 @@ fn dedup(&v: ~[const T]) unsafe { pure fn append(+lhs: ~[T], rhs: &[const T]) -> ~[T] { let mut v <- lhs; unsafe { - push_all(v, rhs); + v.push_all(rhs); } move v } @@ -683,7 +685,7 @@ pure fn append(+lhs: ~[T], rhs: &[const T]) -> ~[T] { #[inline(always)] pure fn append_one(+lhs: ~[T], +x: T) -> ~[T] { let mut v <- lhs; - unsafe { push(v, move x); } + unsafe { v.push(move x); } move v } @@ -705,7 +707,10 @@ fn grow(&v: ~[T], n: uint, initval: T) { reserve_at_least(&mut v, len(v) + n); let mut i: uint = 0u; - while i < n { push(v, initval); i += 1u; } + while i < n { + v.push(initval); + i += 1u; + } } /** @@ -724,7 +729,10 @@ fn grow(&v: ~[T], n: uint, initval: T) { fn grow_fn(&v: ~[T], n: uint, op: iter::InitOp) { reserve_at_least(&mut v, len(v) + n); let mut i: uint = 0u; - while i < n { push(v, op(i)); i += 1u; } + while i < n { + v.push(op(i)); + i += 1u; + } } /** @@ -745,14 +753,18 @@ fn grow_set(&v: ~[T], index: uint, initval: T, val: T) { /// Apply a function to each element of a vector and return the results pure fn map(v: &[T], f: fn(v: &T) -> U) -> ~[U] { let mut result = with_capacity(len(v)); - for each(v) |elem| { unsafe { push(result, f(elem)); } } + for each(v) |elem| { + unsafe { + result.push(f(elem)); + } + } move result } fn map_consume(+v: ~[T], f: fn(+v: T) -> U) -> ~[U] { let mut result = ~[]; do consume(move v) |_i, x| { - vec::push(result, f(move x)); + result.push(f(move x)); } move result } @@ -772,7 +784,7 @@ pure fn mapi(v: &[T], f: fn(uint, v: &T) -> U) -> ~[U] { */ pure fn flat_map(v: &[T], f: fn(T) -> ~[U]) -> ~[U] { let mut result = ~[]; - for each(v) |elem| { unsafe{ push_all_move(result, f(*elem)); } } + for each(v) |elem| { unsafe{ result.push_all_move(f(*elem)); } } move result } @@ -784,7 +796,7 @@ pure fn map2(v0: &[T], v1: &[U], let mut u: ~[V] = ~[]; let mut i = 0u; while i < v0_len { - unsafe { push(u, f(copy v0[i], copy v1[i])) }; + unsafe { u.push(f(copy v0[i], copy v1[i])) }; i += 1u; } move u @@ -802,7 +814,7 @@ pure fn filter_map(v: &[T], f: fn(T) -> Option) for each(v) |elem| { match f(*elem) { None => {/* no-op */ } - Some(result_elem) => unsafe { push(result, result_elem); } + Some(result_elem) => unsafe { result.push(result_elem); } } } move result @@ -818,7 +830,7 @@ pure fn filter_map(v: &[T], f: fn(T) -> Option) pure fn filter(v: &[T], f: fn(T) -> bool) -> ~[T] { let mut result = ~[]; for each(v) |elem| { - if f(*elem) { unsafe { push(result, *elem); } } + if f(*elem) { unsafe { result.push(*elem); } } } move result } @@ -830,7 +842,7 @@ pure fn filter(v: &[T], f: fn(T) -> bool) -> ~[T] { */ pure fn concat(v: &[~[T]]) -> ~[T] { let mut r = ~[]; - for each(v) |inner| { unsafe { push_all(r, *inner); } } + for each(v) |inner| { unsafe { r.push_all(*inner); } } move r } @@ -839,8 +851,8 @@ pure fn connect(v: &[~[T]], sep: T) -> ~[T] { let mut r: ~[T] = ~[]; let mut first = true; for each(v) |inner| { - if first { first = false; } else { unsafe { push(r, sep); } } - unsafe { push_all(r, *inner) }; + if first { first = false; } else { unsafe { r.push(sep); } } + unsafe { r.push_all(*inner) }; } move r } @@ -1059,15 +1071,15 @@ pure fn rposition_between(v: &[T], start: uint, end: uint, * Convert a vector of pairs into a pair of vectors, by reference. As unzip(). */ pure fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { - let mut as_ = ~[], bs = ~[]; + let mut ts = ~[], us = ~[]; for each(v) |p| { - let (a, b) = *p; + let (t, u) = *p; unsafe { - vec::push(as_, a); - vec::push(bs, b); + ts.push(t); + us.push(u); } } - return (move as_, move bs); + return (move ts, move us); } /** @@ -1082,9 +1094,9 @@ pure fn unzip(+v: ~[(T, U)]) -> (~[T], ~[U]) { let mut ts = ~[], us = ~[]; unsafe { do consume(move v) |_i, p| { - let (a,b) = move p; - push(ts, move a); - push(us, move b); + let (t, u) = move p; + ts.push(move t); + us.push(move u); } } (move ts, move us) @@ -1099,7 +1111,7 @@ pure fn zip_slice(v: &[const T], u: &[const U]) let sz = len(v); let mut i = 0u; assert sz == len(u); - while i < sz unsafe { vec::push(zipped, (v[i], u[i])); i += 1u; } + while i < sz unsafe { zipped.push((v[i], u[i])); i += 1u; } move zipped } @@ -1114,7 +1126,7 @@ pure fn zip(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] { assert i == len(u); let mut w = with_capacity(i); while i > 0 { - unsafe { push(w, (pop(v),pop(u))); } + unsafe { w.push((pop(v),pop(u))); } i -= 1; } unsafe { reverse(w); } @@ -1147,8 +1159,8 @@ pure fn reversed(v: &[const T]) -> ~[T] { let mut i = len::(v); if i == 0 { return (move rs); } else { i -= 1; } unsafe { - while i != 0 { vec::push(rs, v[i]); i -= 1; } - vec::push(rs, v[0]); + while i != 0 { rs.push(v[i]); i -= 1; } + rs.push(v[0]); } move rs } @@ -1283,7 +1295,7 @@ pure fn permute(v: &[const T], put: fn(~[T])) { let elt = v[i]; let mut rest = slice(v, 0u, i); unsafe { - push_all(rest, const_view(v, i+1u, ln)); + rest.push_all(const_view(v, i+1u, ln)); permute(rest, |permutation| { put(append(~[elt], permutation)) }) @@ -1299,7 +1311,7 @@ pure fn windowed(nn: uint, xx: &[TT]) -> ~[~[TT]] { for vec::eachi (xx) |ii, _x| { let len = vec::len(xx); if ii+nn <= len unsafe { - vec::push(ww, vec::slice(xx, ii, ii+nn)); + ww.push(vec::slice(xx, ii, ii+nn)); } } move ww @@ -1551,7 +1563,7 @@ impl &[T]: ImmutableVector { let mut r = ~[]; let mut i = 0; while i < self.len() { - push(r, f(&self[i])); + r.push(f(&self[i])); i += 1; } move r @@ -1637,6 +1649,31 @@ impl &[T]: ImmutableCopyableVector { pure fn rfind(f: fn(T) -> bool) -> Option { rfind(self, f) } } +trait MutableVector { + fn push(&mut self, +t: T); + fn push_all_move(&mut self, -rhs: ~[const T]); +} + +trait MutableCopyableVector { + fn push_all(&mut self, rhs: &[const T]); +} + +impl ~[T]: MutableVector { + fn push(&mut self, +t: T) { + push(self, move t); + } + + fn push_all_move(&mut self, -rhs: ~[const T]) { + push_all_move(self, move rhs); + } +} + +impl ~[T]: MutableCopyableVector { + fn push_all(&mut self, rhs: &[const T]) { + push_all(self, rhs); + } +} + /// Unsafe operations mod raw { #[legacy_exports]; @@ -2109,12 +2146,12 @@ mod tests { fn test_push() { // Test on-stack push(). let mut v = ~[]; - push(v, 1); + v.push(1); assert (len(v) == 1u); assert (v[0] == 1); // Test on-heap push(). - push(v, 2); + v.push(2); assert (len(v) == 2u); assert (v[0] == 1); assert (v[1] == 2); @@ -2380,19 +2417,19 @@ mod tests { let mut results: ~[~[int]]; results = ~[]; - permute(~[], |v| vec::push(results, copy v)); + permute(~[], |v| results.push(copy v)); assert results == ~[~[]]; results = ~[]; - permute(~[7], |v| push(results, copy v)); + permute(~[7], |v| results.push(copy v)); assert results == ~[~[7]]; results = ~[]; - permute(~[1,1], |v| push(results, copy v)); + permute(~[1,1], |v| results.push(copy v)); assert results == ~[~[1,1],~[1,1]]; results = ~[]; - permute(~[5,2,0], |v| push(results, copy v)); + permute(~[5,2,0], |v| results.push(copy v)); assert results == ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]; } diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 4ffe7245113..1f26822ed9f 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -648,7 +648,7 @@ mod tests { let mut children = ~[]; for 5.times { let arc3 = ~arc.clone(); - do task::task().future_result(|+r| vec::push(children, r)).spawn { + do task::task().future_result(|+r| children.push(r)).spawn { do arc3.read |num| { assert *num >= 0; } @@ -676,7 +676,7 @@ mod tests { let mut reader_convos = ~[]; for 10.times { let ((rc1,rp1),(rc2,rp2)) = (pipes::stream(),pipes::stream()); - vec::push(reader_convos, (rc1,rp2)); + reader_convos.push((rc1,rp2)); let arcn = ~arc.clone(); do task::spawn { rp1.recv(); // wait for downgrader to give go-ahead diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 0da23db7291..e5eacd5c440 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -102,12 +102,12 @@ impl ~[u8]: FromBase64 { } else if ch == '=' { match len - i { 1u => { - vec::push(r, ((n >> 16u) & 0xFFu) as u8); - vec::push(r, ((n >> 8u ) & 0xFFu) as u8); + r.push(((n >> 16u) & 0xFFu) as u8); + r.push(((n >> 8u ) & 0xFFu) as u8); return copy r; } 2u => { - vec::push(r, ((n >> 10u) & 0xFFu) as u8); + r.push(((n >> 10u) & 0xFFu) as u8); return copy r; } _ => fail ~"invalid base64 padding" @@ -119,9 +119,9 @@ impl ~[u8]: FromBase64 { i += 1u; }; - vec::push(r, ((n >> 16u) & 0xFFu) as u8); - vec::push(r, ((n >> 8u ) & 0xFFu) as u8); - vec::push(r, ((n ) & 0xFFu) as u8); + r.push(((n >> 16u) & 0xFFu) as u8); + r.push(((n >> 8u ) & 0xFFu) as u8); + r.push(((n ) & 0xFFu) as u8); } r diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 17d4b39b01e..8506bd5f6fc 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -38,8 +38,8 @@ fn create() -> Deque { let nalloc = uint::next_power_of_two(nelts + 1u); while i < nalloc { if i < nelts { - vec::push(rv, elts[(lo + i) % nelts]); - } else { vec::push(rv, None); } + rv.push(elts[(lo + i) % nelts]); + } else { rv.push(None); } i += 1u; } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 9b7f7a79f22..3f6bcd31a73 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -211,7 +211,7 @@ impl Writer { write_vuint(self.writer, tag_id); // Write a placeholder four-byte size. - vec::push(self.size_positions, self.writer.tell()); + self.size_positions.push(self.writer.tell()); let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8]; self.writer.write(zeroes); } diff --git a/src/libstd/ebml2.rs b/src/libstd/ebml2.rs index 8b37dea6210..496010d579e 100644 --- a/src/libstd/ebml2.rs +++ b/src/libstd/ebml2.rs @@ -220,7 +220,7 @@ impl Serializer { write_vuint(self.writer, tag_id); // Write a placeholder four-byte size. - vec::push(self.size_positions, self.writer.tell()); + self.size_positions.push(self.writer.tell()); let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8]; self.writer.write(zeroes); } diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index f8b86d80061..7a47db8a7f0 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -234,10 +234,10 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { let cur = args[i]; let curlen = str::len(cur); if !is_arg(cur) { - vec::push(free, cur); + free.push(cur); } else if cur == ~"--" { let mut j = i + 1u; - while j < l { vec::push(free, args[j]); j += 1u; } + while j < l { free.push(args[j]); j += 1u; } break; } else { let mut names; @@ -287,7 +287,7 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { } } } - vec::push(names, opt); + names.push(opt); j = range.next; } } @@ -303,23 +303,22 @@ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { if !i_arg.is_none() { return Err(UnexpectedArgument(name_str(nm))); } - vec::push(vals[optid], Given); + vals[optid].push(Given); } Maybe => { if !i_arg.is_none() { - vec::push(vals[optid], Val(i_arg.get())); + vals[optid].push(Val(i_arg.get())); } else if name_pos < vec::len::(names) || i + 1u == l || is_arg(args[i + 1u]) { - vec::push(vals[optid], Given); - } else { i += 1u; vec::push(vals[optid], Val(args[i])); } + vals[optid].push(Given); + } else { i += 1u; vals[optid].push(Val(args[i])); } } Yes => { if !i_arg.is_none() { - vec::push(vals[optid], - Val(i_arg.get())); + vals[optid].push(Val(i_arg.get())); } else if i + 1u == l { return Err(ArgumentMissing(name_str(nm))); - } else { i += 1u; vec::push(vals[optid], Val(args[i])); } + } else { i += 1u; vals[optid].push(Val(args[i])); } } } } @@ -412,7 +411,7 @@ fn opts_str(+mm: Matches, names: &[~str]) -> ~str { fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { let mut acc: ~[~str] = ~[]; for vec::each(opt_vals(mm, nm)) |v| { - match *v { Val(s) => vec::push(acc, s), _ => () } + match *v { Val(s) => acc.push(s), _ => () } } return acc; } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index f75f033bb8e..29535c62b5e 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -594,7 +594,7 @@ priv impl Parser { loop { match move self.parse_value() { - Ok(move v) => vec::push(values, v), + Ok(move v) => values.push(v), Err(move e) => return Err(e) } @@ -690,13 +690,13 @@ pub fn Deserializer(rdr: io::Reader) -> Result { } priv impl Deserializer { - fn peek() -> &self/Json { - if self.stack.len() == 0 { vec::push(self.stack, &self.json); } + fn peek(&self) -> &self/Json { + if self.stack.len() == 0 { self.stack.push(&self.json); } vec::last(self.stack) } - fn pop() -> &self/Json { - if self.stack.len() == 0 { vec::push(self.stack, &self.json); } + fn pop(&self) -> &self/Json { + if self.stack.len() == 0 { self.stack.push(&self.json); } vec::pop(self.stack) } } @@ -772,7 +772,7 @@ pub impl Deserializer: serialization2::Deserializer { fn read_vec(&self, f: fn(uint) -> T) -> T { debug!("read_vec()"); let len = match *self.peek() { - List(list) => list.len(), + List(ref list) => list.len(), _ => fail ~"not a list", }; let res = f(len); @@ -784,7 +784,10 @@ pub impl Deserializer: serialization2::Deserializer { debug!("read_vec_elt(idx=%u)", idx); match *self.peek() { List(ref list) => { - vec::push(self.stack, &list[idx]); + // FIXME(#3148)---should be inferred + let list: &self/~[Json] = list; + + self.stack.push(&list[idx]); f() } _ => fail ~"not a list", @@ -820,7 +823,7 @@ pub impl Deserializer: serialization2::Deserializer { match obj.find_ref(&f_name) { None => fail fmt!("no such field: %s", f_name), Some(json) => { - vec::push(self.stack, json); + self.stack.push(json); f() } } @@ -845,8 +848,10 @@ pub impl Deserializer: serialization2::Deserializer { fn read_tup_elt(&self, idx: uint, f: fn() -> T) -> T { debug!("read_tup_elt(idx=%u)", idx); match *self.peek() { - List(list) => { - vec::push(self.stack, &list[idx]); + List(ref list) => { + // FIXME(#3148)---should be inferred + let list: &self/~[Json] = list; + self.stack.push(&list[idx]); f() } _ => fail ~"not a list" @@ -939,12 +944,12 @@ impl Json : Ord { // XXX: this is horribly inefficient... for d0.each |k, v| { - vec::push(d0_flat, (@copy *k, @copy *v)); + d0_flat.push((@copy *k, @copy *v)); } d0_flat.qsort(); for d1.each |k, v| { - vec::push(d1_flat, (@copy *k, @copy *v)); + d1_flat.push((@copy *k, @copy *v)); } d1_flat.qsort(); diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs index a4272324670..0bf4f6f8610 100644 --- a/src/libstd/md4.rs +++ b/src/libstd/md4.rs @@ -11,14 +11,14 @@ fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} { let mut msg = vec::append(vec::from_slice(msg), ~[0x80u8]); let mut bitlen = orig_len + 8u64; while (bitlen + 64u64) % 512u64 > 0u64 { - vec::push(msg, 0u8); + msg.push(0u8); bitlen += 8u64; } // append length let mut i = 0u64; while i < 8u64 { - vec::push(msg, (orig_len >> (i * 8u64)) as u8); + msg.push((orig_len >> (i * 8u64)) as u8); i += 1u64; } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 445bc62e4c9..347f2b271a1 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -277,7 +277,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, result::Err(GetAddrUnknownError)); break; }; - vec::push(out_vec, move new_ip_addr); + out_vec.push(move new_ip_addr); let next_addr = ll::get_next_addrinfo(curr_addr); if next_addr == ptr::null::() as *addrinfo { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index a1c7637dee6..a0ba8aae3f1 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -779,7 +779,7 @@ impl TcpSocketBuf: io::Reader { } } else { - vec::push_all(self.data.buf, result::unwrap(read_result)); + self.data.buf.push_all(result::unwrap(read_result)); } } @@ -790,7 +790,7 @@ impl TcpSocketBuf: io::Reader { vec::bytes::memcpy(buf, vec::view(data, 0, data.len()), count); - vec::push_all(self.data.buf, vec::view(data, count, data.len())); + self.data.buf.push_all(vec::view(data, count, data.len())); count } diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 8116bd4fb30..33e657c390b 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -329,7 +329,7 @@ fn query_from_str(rawquery: &str) -> Query { if str::len(rawquery) != 0 { for str::split_char(rawquery, '&').each |p| { let (k, v) = split_char_first(*p, '='); - vec::push(query, (decode_component(k), decode_component(v))); + query.push((decode_component(k), decode_component(v))); }; } return query; diff --git a/src/libstd/par.rs b/src/libstd/par.rs index 38a814b22e0..2f98c4bad34 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -55,7 +55,7 @@ fn map_slices( f(base, slice) } }; - vec::push(futures, move f); + futures.push(move f); }; base += items_per_task; } diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 2d49ede3507..4680448e275 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -869,7 +869,7 @@ mod node { loop { match (leaf_iterator::next(&it)) { option::None => break, - option::Some(x) => vec::push(forest, @Leaf(x)) + option::Some(x) => forest.push(@Leaf(x)) } } //2. Rebuild tree from forest diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 46f79c01948..f1abe5be5a5 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -47,9 +47,9 @@ fn merge_sort(le: Le, v: &[const T]) -> ~[T] { let mut b_ix = 0u; while a_ix < a_len && b_ix < b_len { if le(&a[a_ix], &b[b_ix]) { - vec::push(rs, a[a_ix]); + rs.push(a[a_ix]); a_ix += 1u; - } else { vec::push(rs, b[b_ix]); b_ix += 1u; } + } else { rs.push(b[b_ix]); b_ix += 1u; } } rs = vec::append(rs, vec::slice(a, a_ix, a_len)); rs = vec::append(rs, vec::slice(b, b_ix, b_len)); diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 8fdcc22b4c1..7638b43ad86 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -82,7 +82,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint) -> Sem<~[mut Waitqueue]> { let mut queues = ~[]; for num_condvars.times { - vec::push(queues, new_waitqueue()); + queues.push(new_waitqueue()); } new_sem(count, vec::to_mut(move queues)) } @@ -840,7 +840,7 @@ mod tests { for num_waiters.times { let mi = ~m.clone(); let (chan, port) = pipes::stream(); - vec::push(ports, port); + ports.push(port); do task::spawn { do mi.lock_cond |cond| { chan.send(()); @@ -930,7 +930,7 @@ mod tests { for 2.times { let (c,p) = pipes::stream(); let c = ~mut Some(c); - vec::push(sibling_convos, p); + sibling_convos.push(p); let mi = ~m2.clone(); // spawn sibling task do task::spawn { // linked @@ -1194,7 +1194,7 @@ mod tests { for num_waiters.times { let xi = ~x.clone(); let (chan, port) = pipes::stream(); - vec::push(ports, port); + ports.push(port); do task::spawn { do lock_cond(xi, dg1) |cond| { chan.send(()); diff --git a/src/libstd/test.rs b/src/libstd/test.rs index e872cba5dc9..facc43f6273 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -141,7 +141,7 @@ fn run_tests_console(opts: &TestOpts, st.failed += 1u; write_failed(st.out, st.use_color); st.out.write_line(~""); - vec::push(st.failures, copy test); + st.failures.push(copy test); } TrIgnored => { st.ignored += 1u; @@ -545,7 +545,7 @@ mod tests { for vec::each(names) |name| { let test = {name: *name, testfn: copy testfn, ignore: false, should_fail: false}; - vec::push(tests, test); + tests.push(test); } tests }; diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 09922ade073..b6d4c2d0fe3 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -273,9 +273,9 @@ fn map_item(i: @item, cx: ctx, v: vt) { } match i.node { item_mod(_) | item_foreign_mod(_) => { - vec::push(cx.path, path_mod(i.ident)); + cx.path.push(path_mod(i.ident)); } - _ => vec::push(cx.path, path_name(i.ident)) + _ => cx.path.push(path_name(i.ident)) } visit::visit_item(i, cx, v); vec::pop(cx.path); diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 98a471bd54c..329c9f362a4 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -313,8 +313,8 @@ fn split_trait_methods(trait_methods: ~[trait_method]) let mut reqd = ~[], provd = ~[]; for trait_methods.each |trt_method| { match *trt_method { - required(tm) => vec::push(reqd, tm), - provided(m) => vec::push(provd, m) + required(tm) => reqd.push(tm), + provided(m) => provd.push(m) } }; (reqd, provd) diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index eb4ffb26fb1..7ef34d8eb0b 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -91,7 +91,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value } // Get the meta_items from inside a vector of attributes fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] { let mut mitems = ~[]; - for attrs.each |a| { vec::push(mitems, attr_meta(*a)); } + for attrs.each |a| { mitems.push(attr_meta(*a)); } return mitems; } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index ae49e19c862..e07985119ec 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -84,7 +84,7 @@ fn mk_substr_filename(cm: codemap, sp: span) -> ~str } fn next_line(file: filemap, chpos: uint, byte_pos: uint) { - vec::push(file.lines, {ch: chpos, byte: byte_pos + file.start_pos.byte}); + file.lines.push({ch: chpos, byte: byte_pos + file.start_pos.byte}); } type lookup_fn = pure fn(file_pos) -> uint; @@ -204,7 +204,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { let hi = lookup_char_pos(cm, sp.hi); let mut lines = ~[]; for uint::range(lo.line - 1u, hi.line as uint) |i| { - vec::push(lines, i); + lines.push(i); }; return @{file: lo.file, lines: lines}; } diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index 264711584fc..b51184eefd8 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -750,7 +750,7 @@ fn mk_enum_deser_body( body: cx.expr_blk(cx.expr(span, ast::expr_fail(None))), }; - vec::push(arms, impossible_case); + arms.push(impossible_case); // ast for `|i| { match i { $(arms) } }` let expr_lambda = cx.expr( diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 1cbcd0f6ddb..566cdc4fa21 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -160,7 +160,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn cfg() -> ast::crate_cfg { self.cfg } fn print_backtrace() { } fn backtrace() -> expn_info { self.backtrace } - fn mod_push(i: ast::ident) { vec::push(self.mod_path, i); } + fn mod_push(i: ast::ident) { self.mod_path.push(i); } fn mod_pop() { vec::pop(self.mod_path); } fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn bt_push(ei: codemap::expn_info_) { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 8574c0c9082..8ce426f0357 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -96,7 +96,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span, let val = field.ex; let astfield = {node: {mutbl: ast::m_imm, ident: ident, expr: val}, span: sp}; - vec::push(astfields, astfield); + astfields.push(astfield); } let recexpr = ast::expr_rec(astfields, option::None::<@ast::expr>); mk_expr(cx, sp, recexpr) diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 3ea0493239f..e4f197801c2 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -245,7 +245,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, for pieces.each |pc| { match *pc { PieceString(s) => { - vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s)) + piece_exprs.push(mk_uniq_str(cx, fmt_sp, s)) } PieceConv(conv) => { n += 1u; @@ -258,7 +258,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, log_conv(conv); let arg_expr = args[n]; let c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr); - vec::push(piece_exprs, c_expr); + piece_exprs.push(c_expr); } } } diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs index 8b17ffc1104..a9bfd87ab0e 100644 --- a/src/libsyntax/ext/pipes/liveness.rs +++ b/src/libsyntax/ext/pipes/liveness.rs @@ -65,7 +65,7 @@ fn analyze(proto: protocol, _cx: ext_ctxt) { let mut self_live = ~[]; for colive.eachi |i, bv| { if bv.get(i) { - vec::push(self_live, proto.get_state_by_id(i)) + self_live.push(proto.get_state_by_id(i)) } } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 11250cfbf38..f93fa830f92 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -226,7 +226,7 @@ impl state: to_type_decls { let v = cx.variant(cx.ident_of(name), span, tys); - vec::push(items_msg, v); + items_msg.push(v); } ~[cx.item_enum_poly(name, @@ -245,44 +245,44 @@ impl state: to_type_decls { let mut items = ~[]; for self.messages.each |m| { if dir == send { - vec::push(items, m.gen_send(cx, true)); - vec::push(items, m.gen_send(cx, false)); + items.push(m.gen_send(cx, true)); + items.push(m.gen_send(cx, false)); } } if !self.proto.is_bounded() { - vec::push(items, - cx.item_ty_poly( - self.data_name(), - self.span, - cx.ty_path_ast_builder( - path(~[cx.ident_of(~"pipes"), - cx.ident_of(dir.to_str() + ~"Packet")], - empty_span()) - .add_ty(cx.ty_path_ast_builder( - path(~[cx.ident_of(self.proto.name), - self.data_name()], - empty_span()) - .add_tys(cx.ty_vars(self.ty_params))))), - self.ty_params)); + items.push( + cx.item_ty_poly( + self.data_name(), + self.span, + cx.ty_path_ast_builder( + path(~[cx.ident_of(~"pipes"), + cx.ident_of(dir.to_str() + ~"Packet")], + empty_span()) + .add_ty(cx.ty_path_ast_builder( + path(~[cx.ident_of(self.proto.name), + self.data_name()], + empty_span()) + .add_tys(cx.ty_vars(self.ty_params))))), + self.ty_params)); } else { - vec::push(items, - cx.item_ty_poly( - self.data_name(), - self.span, - cx.ty_path_ast_builder( - path(~[cx.ident_of(~"pipes"), - cx.ident_of(dir.to_str() - + ~"PacketBuffered")], - empty_span()) - .add_tys(~[cx.ty_path_ast_builder( - path(~[cx.ident_of(self.proto.name), - self.data_name()], - empty_span()) - .add_tys(cx.ty_vars(self.ty_params))), - self.proto.buffer_ty_path(cx)])), - self.ty_params)); + items.push( + cx.item_ty_poly( + self.data_name(), + self.span, + cx.ty_path_ast_builder( + path(~[cx.ident_of(~"pipes"), + cx.ident_of(dir.to_str() + + ~"PacketBuffered")], + empty_span()) + .add_tys(~[cx.ty_path_ast_builder( + path(~[cx.ident_of(self.proto.name), + self.data_name()], + empty_span()) + .add_tys(cx.ty_vars(self.ty_params))), + self.proto.buffer_ty_path(cx)])), + self.ty_params)); }; items } @@ -367,7 +367,7 @@ impl protocol: gen_init { for (copy self.states).each |s| { for s.ty_params.each |tp| { match params.find(|tpp| tp.ident == tpp.ident) { - None => vec::push(params, *tp), + None => params.push(*tp), _ => () } } @@ -383,7 +383,7 @@ impl protocol: gen_init { let fields = do (copy self.states).map_to_vec |s| { for s.ty_params.each |tp| { match params.find(|tpp| tp.ident == tpp.ident) { - None => vec::push(params, *tp), + None => params.push(*tp), _ => () } } @@ -415,17 +415,15 @@ impl protocol: gen_init { } if self.is_bounded() { - vec::push(items, self.gen_buffer_type(cx)) + items.push(self.gen_buffer_type(cx)) } - vec::push(items, - cx.item_mod(cx.ident_of(~"client"), - self.span, - client_states)); - vec::push(items, - cx.item_mod(cx.ident_of(~"server"), - self.span, - server_states)); + items.push(cx.item_mod(cx.ident_of(~"client"), + self.span, + client_states)); + items.push(cx.item_mod(cx.ident_of(~"server"), + self.span, + server_states)); cx.item_mod(cx.ident_of(self.name), self.span, items) } diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index 4729e7da39c..51239754635 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -94,7 +94,7 @@ fn option_flatten_map(f: fn@(T) -> Option, v: ~[T]) -> for v.each |elem| { match f(*elem) { None => return None, - Some(fv) => vec::push(res, fv) + Some(fv) => res.push(fv) } } return Some(res); @@ -305,8 +305,8 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], /* Whew, we now know how how many times to repeat */ let mut idx: uint = 0u; while idx < rc { - vec::push(*idx_path, idx); - vec::push(res, recur(repeat_me)); // whew! + idx_path.push(idx); + res.push(recur(repeat_me)); // whew! vec::pop(*idx_path); idx += 1u; } @@ -567,7 +567,7 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, let mut elts = ~[]; let mut idx = offset; while idx < vec::len(arg_elts) { - vec::push(elts, leaf(match_expr(arg_elts[idx]))); + elts.push(leaf(match_expr(arg_elts[idx]))); idx += 1u; } @@ -672,9 +672,8 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, None => cx.span_fatal(mac.span, ~"macro must have arguments") }; - vec::push(clauses, - @{params: pattern_to_selectors(cx, arg), - body: elts[1u]}); + clauses.push(@{params: pattern_to_selectors(cx, arg), + body: elts[1u]}); // FIXME (#2251): check duplicates (or just simplify // the macro arg situation) diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index a7a45942822..737694337e3 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -208,7 +208,7 @@ fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) -> parse_result { let mut cur_eis = ~[]; - vec::push(cur_eis, initial_matcher_pos(ms, None, rdr.peek().sp.lo)); + cur_eis.push(initial_matcher_pos(ms, None, rdr.peek().sp.lo)); loop { let mut bb_eis = ~[]; // black-box parsed by parser.rs @@ -256,7 +256,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) } new_pos.idx += 1; - vec::push(cur_eis, move new_pos); + cur_eis.push(move new_pos); } // can we go around again? @@ -267,17 +267,17 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) if tok == t { //pass the separator let ei_t <- ei; ei_t.idx += 1; - vec::push(next_eis, move ei_t); + next_eis.push(move ei_t); } } _ => { // we don't need a separator let ei_t <- ei; ei_t.idx = 0; - vec::push(cur_eis, move ei_t); + cur_eis.push(move ei_t); } } } else { - vec::push(eof_eis, move ei); + eof_eis.push(move ei); } } else { match copy ei.elts[idx].node { @@ -292,13 +292,13 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) new_ei.matches[idx].push(@matched_seq(~[], sp)); } - vec::push(cur_eis, move new_ei); + cur_eis.push(move new_ei); } let matches = vec::map(ei.matches, // fresh, same size: |_m| DVec::<@named_match>()); let ei_t <- ei; - vec::push(cur_eis, ~{ + cur_eis.push(~{ elts: matchers, sep: sep, mut idx: 0u, mut up: matcher_pos_up(Some(move ei_t)), matches: move matches, @@ -306,12 +306,12 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) sp_lo: sp.lo }); } - match_nonterminal(_,_,_) => { vec::push(bb_eis, move ei) } + match_nonterminal(_,_,_) => { bb_eis.push(move ei) } match_tok(t) => { let ei_t <- ei; if t == tok { ei_t.idx += 1; - vec::push(next_eis, move ei_t); + next_eis.push(move ei_t); } } } @@ -323,7 +323,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) if eof_eis.len() == 1u { return success( nameize(sess, ms, - vec::map(eof_eis[0u].matches, |dv| dv.pop()))); + eof_eis[0u].matches.map(|dv| dv.pop()))); } else if eof_eis.len() > 1u { return error(sp, ~"Ambiguity: multiple successful parses"); } else { @@ -350,7 +350,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) } else if (next_eis.len() > 0u) { /* Now process the next token */ while(next_eis.len() > 0u) { - vec::push(cur_eis, vec::pop(next_eis)); + cur_eis.push(vec::pop(next_eis)); } rdr.next_token(); } else /* bb_eis.len() == 1 */ { @@ -365,7 +365,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) } _ => fail } - vec::push(cur_eis, move ei); + cur_eis.push(move ei); /* this would fail if zero-length tokens existed */ while rdr.peek().sp.lo < rust_parser.span.lo { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index b208e4f8c6f..558593579bf 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -205,8 +205,8 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { r.cur.idx += 1u; return tt_next_token(r); } else { - vec::push(r.repeat_len, len); - vec::push(r.repeat_idx, 0u); + r.repeat_len.push(len); + r.repeat_idx.push(0u); r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: true, sep: sep, up: tt_frame_up(option::Some(r.cur))}; } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index f8f481c8f66..12c8dc2f7bb 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -367,9 +367,8 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { pat_rec(fields, etc) => { let mut fs = ~[]; for fields.each |f| { - vec::push(fs, - {ident: /* FIXME (#2543) */ copy f.ident, - pat: fld.fold_pat(f.pat)}); + fs.push({ident: /* FIXME (#2543) */ copy f.ident, + pat: fld.fold_pat(f.pat)}); } pat_rec(fs, etc) } @@ -377,9 +376,8 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { let pth_ = fld.fold_path(pth); let mut fs = ~[]; for fields.each |f| { - vec::push(fs, - {ident: /* FIXME (#2543) */ copy f.ident, - pat: fld.fold_pat(f.pat)}); + fs.push({ident: /* FIXME (#2543) */ copy f.ident, + pat: fld.fold_pat(f.pat)}); } pat_struct(pth_, fs, etc) } diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index ddc70a1f13e..cb8416501b3 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -130,7 +130,7 @@ fn consume_non_eol_whitespace(rdr: string_reader) { fn push_blank_line_comment(rdr: string_reader, &comments: ~[cmnt]) { debug!(">>> blank-line comment"); let v: ~[~str] = ~[]; - vec::push(comments, {style: blank_line, lines: v, pos: rdr.chpos}); + comments.push({style: blank_line, lines: v, pos: rdr.chpos}); } fn consume_whitespace_counting_blank_lines(rdr: string_reader, @@ -149,7 +149,7 @@ fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool, debug!(">>> shebang comment"); let p = rdr.chpos; debug!("<<< shebang comment"); - vec::push(comments, { + comments.push({ style: if code_to_the_left { trailing } else { isolated }, lines: ~[read_one_line_comment(rdr)], pos: p @@ -167,12 +167,12 @@ fn read_line_comments(rdr: string_reader, code_to_the_left: bool, if is_doc_comment(line) { // doc-comments are not put in comments break; } - vec::push(lines, line); + lines.push(line); consume_non_eol_whitespace(rdr); } debug!("<<< line comments"); if !lines.is_empty() { - vec::push(comments, { + comments.push({ style: if code_to_the_left { trailing } else { isolated }, lines: lines, pos: p @@ -198,7 +198,7 @@ fn trim_whitespace_prefix_and_push_line(&lines: ~[~str], } else { s1 = ~""; } } else { s1 = s; } log(debug, ~"pushing line: " + s1); - vec::push(lines, s1); + lines.push(s1); } fn read_block_comment(rdr: string_reader, code_to_the_left: bool, @@ -257,7 +257,7 @@ fn read_block_comment(rdr: string_reader, code_to_the_left: bool, style = mixed; } debug!("<<< block comment"); - vec::push(comments, {style: style, lines: lines, pos: p}); + comments.push({style: style, lines: lines, pos: p}); } fn peeking_at_comment(rdr: string_reader) -> bool { @@ -315,7 +315,7 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler, let {tok: tok, sp: sp} = rdr.peek(); if token::is_lit(tok) { let s = get_str_from(rdr, bstart); - vec::push(literals, {lit: s, pos: sp.lo}); + literals.push({lit: s, pos: sp.lo}); log(debug, ~"tok lit: " + s); } else { log(debug, ~"tok: " + token::to_str(rdr.interner, tok)); diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 4b8bfcda848..c8c30ee7fa9 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -229,7 +229,7 @@ impl parser: parser_common { } _ => () } - vec::push(v, f(self)); + v.push(f(self)); } return v; @@ -274,7 +274,7 @@ impl parser: parser_common { _ => () } if sep.trailing_sep_allowed && self.token == ket { break; } - vec::push(v, f(self)); + v.push(f(self)); } return v; } diff --git a/src/libsyntax/parse/eval.rs b/src/libsyntax/parse/eval.rs index 7127e2747eb..14dc490346e 100644 --- a/src/libsyntax/parse/eval.rs +++ b/src/libsyntax/parse/eval.rs @@ -107,7 +107,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path, // Thread defids, chpos and byte_pos through the parsers cx.sess.chpos = r0.chpos; cx.sess.byte_pos = cx.sess.byte_pos + r0.pos; - vec::push(items, i); + items.push(i); } ast::cdir_dir_mod(vis, id, cdirs, attrs) => { let path = Path(cdir_path_opt(*cx.sess.interner.get(id), attrs)); @@ -126,9 +126,9 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path, vis: vis, span: cdir.span}; cx.sess.next_id += 1; - vec::push(items, i); + items.push(i); } - ast::cdir_view_item(vi) => vec::push(view_items, vi), + ast::cdir_view_item(vi) => view_items.push(vi), ast::cdir_syntax(*) => () } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9d970e23f68..10981c5c708 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -496,7 +496,7 @@ impl parser { let mut ts = ~[self.parse_ty(false)]; while self.token == token::COMMA { self.bump(); - vec::push(ts, self.parse_ty(false)); + ts.push(self.parse_ty(false)); } let t = if vec::len(ts) == 1u { ts[0].node } else { ty_tup(ts) }; @@ -771,10 +771,10 @@ impl parser { && self.look_ahead(1u) == token::MOD_SEP; if is_not_last { - vec::push(ids, parse_ident(self)); + ids.push(parse_ident(self)); self.expect(token::MOD_SEP); } else { - vec::push(ids, parse_last_ident(self)); + ids.push(parse_last_ident(self)); break; } } @@ -903,7 +903,7 @@ impl parser { } let mut es = ~[self.parse_expr()]; while self.token == token::COMMA { - self.bump(); vec::push(es, self.parse_expr()); + self.bump(); es.push(self.parse_expr()); } hi = self.span.hi; self.expect(token::RPAREN); @@ -1049,7 +1049,7 @@ impl parser { self.bump(); let mut fields = ~[]; let mut base = None; - vec::push(fields, self.parse_field(token::COLON)); + fields.push(self.parse_field(token::COLON)); while self.token != token::RBRACE { if self.try_parse_obsolete_with() { @@ -1067,7 +1067,7 @@ impl parser { // Accept an optional trailing comma. break; } - vec::push(fields, self.parse_field(token::COLON)); + fields.push(self.parse_field(token::COLON)); } hi = pth.span.hi; @@ -1316,7 +1316,7 @@ impl parser { while self.token != ket || lparens > 0u { if self.token == token::LPAREN { lparens += 1u; } if self.token == token::RPAREN { lparens -= 1u; } - vec::push(ret_val, self.parse_matcher(name_idx)); + ret_val.push(self.parse_matcher(name_idx)); } self.bump(); @@ -1722,7 +1722,7 @@ impl parser { // record ends by an optional trailing comma break; } - vec::push(fields, self.parse_field(token::COLON)); + fields.push(self.parse_field(token::COLON)); } self.expect(token::RBRACE); return expr_rec(fields, base); @@ -1757,7 +1757,7 @@ impl parser { rules: default_blk}, span: expr.span}; - vec::push(arms, {pats: pats, guard: guard, body: blk}); + arms.push({pats: pats, guard: guard, body: blk}); } let mut hi = self.span.hi; self.bump(); @@ -1802,7 +1802,7 @@ impl parser { fn parse_pats() -> ~[@pat] { let mut pats = ~[]; loop { - vec::push(pats, self.parse_pat(true)); + pats.push(self.parse_pat(true)); if self.token == token::BINOP(token::OR) { self.bump(); } else { return pats; } }; @@ -1849,7 +1849,7 @@ impl parser { span: self.last_span }; } - vec::push(fields, {ident: fieldname, pat: subpat}); + fields.push({ident: fieldname, pat: subpat}); } return (fields, etc); } @@ -1937,7 +1937,7 @@ impl parser { let mut fields = ~[self.parse_pat(refutable)]; while self.token == token::COMMA { self.bump(); - vec::push(fields, self.parse_pat(refutable)); + fields.push(self.parse_pat(refutable)); } if vec::len(fields) == 1u { self.expect(token::COMMA); } hi = self.span.hi; @@ -2126,7 +2126,7 @@ impl parser { let lo = self.span.lo; let mut locals = ~[self.parse_local(is_mutbl, true)]; while self.eat(token::COMMA) { - vec::push(locals, self.parse_local(is_mutbl, true)); + locals.push(self.parse_local(is_mutbl, true)); } return @spanned(lo, self.last_span.hi, decl_local(locals)); } @@ -2266,8 +2266,8 @@ impl parser { for items.each |item| { let decl = @spanned(item.span.lo, item.span.hi, decl_item(*item)); - push(stmts, @spanned(item.span.lo, item.span.hi, - stmt_decl(decl, self.get_id()))); + stmts.push(@spanned(item.span.lo, item.span.hi, + stmt_decl(decl, self.get_id()))); } let mut initial_attrs = attrs_remaining; @@ -2278,43 +2278,43 @@ impl parser { while self.token != token::RBRACE { match self.token { - token::SEMI => { - self.bump(); // empty - } - _ => { - let stmt = self.parse_stmt(initial_attrs); - initial_attrs = ~[]; - match stmt.node { - stmt_expr(e, stmt_id) => { // Expression without semicolon: - match self.token { - token::SEMI => { - self.bump(); - push(stmts, - @{node: stmt_semi(e, stmt_id),.. *stmt}); - } - token::RBRACE => { - expr = Some(e); - } - t => { - if classify::stmt_ends_with_semi(*stmt) { - self.fatal(~"expected `;` or `}` after \ - expression but found `" - + token_to_str(self.reader, t) + ~"`"); + token::SEMI => { + self.bump(); // empty + } + _ => { + let stmt = self.parse_stmt(initial_attrs); + initial_attrs = ~[]; + match stmt.node { + stmt_expr(e, stmt_id) => { // Expression without semicolon: + match self.token { + token::SEMI => { + self.bump(); + stmts.push(@{node: stmt_semi(e, stmt_id), + ..*stmt}); + } + token::RBRACE => { + expr = Some(e); + } + t => { + if classify::stmt_ends_with_semi(*stmt) { + self.fatal(~"expected `;` or `}` after \ + expression but found `" + + token_to_str(self.reader, t) + ~"`"); + } + stmts.push(stmt); + } + } } - vec::push(stmts, stmt); - } - } - } - _ => { // All other kinds of statements: - vec::push(stmts, stmt); + _ => { // All other kinds of statements: + stmts.push(stmt); - if classify::stmt_ends_with_semi(*stmt) { - self.expect(token::SEMI); + if classify::stmt_ends_with_semi(*stmt) { + self.expect(token::SEMI); + } + } } - } } - } } } let mut hi = self.span.hi; @@ -2356,16 +2356,16 @@ impl parser { }; match maybe_bound { - Some(bound) => { - self.bump(); - push(bounds, bound); - } - None => { - push(bounds, bound_trait(self.parse_ty(false))); - } + Some(bound) => { + self.bump(); + bounds.push(bound); + } + None => { + bounds.push(bound_trait(self.parse_ty(false))); + } } } else { - push(bounds, bound_trait(self.parse_ty(false))); + bounds.push(bound_trait(self.parse_ty(false))); } } } @@ -2636,7 +2636,7 @@ impl parser { self.expect(token::LBRACE); while !self.eat(token::RBRACE) { let vis = self.parse_visibility(); - vec::push(meths, self.parse_method(vis)); + meths.push(self.parse_method(vis)); } (ident, item_impl(tps, opt_trait, ty, meths), None) } @@ -2722,9 +2722,9 @@ impl parser { for mms.each |mm| { match *mm { @field_member(struct_field) => - vec::push(fields, struct_field), + fields.push(struct_field), @method_member(the_method_member) => - vec::push(methods, the_method_member) + methods.push(the_method_member) } } } @@ -2896,7 +2896,7 @@ impl parser { debug!("parse_mod_items: parse_item_or_view_item(attrs=%?)", attrs); match self.parse_item_or_view_item(attrs, true) { - iovi_item(item) => vec::push(items, item), + iovi_item(item) => items.push(item), iovi_view_item(view_item) => { self.span_fatal(view_item.span, ~"view items must be \ declared at the top of the \ @@ -3000,7 +3000,7 @@ impl parser { let attrs = vec::append(initial_attrs, self.parse_outer_attributes()); initial_attrs = ~[]; - vec::push(items, self.parse_foreign_item(attrs)); + items.push(self.parse_foreign_item(attrs)); } return {sort: sort, view_items: view_items, items: items}; @@ -3113,9 +3113,9 @@ impl parser { for mms.each |mm| { match *mm { @field_member(struct_field) => - vec::push(fields, struct_field), + fields.push(struct_field), @method_member(the_method_member) => - vec::push(methods, the_method_member) + methods.push(the_method_member) } } } @@ -3184,7 +3184,7 @@ impl parser { seq_sep_trailing_disallowed(token::COMMA), |p| p.parse_ty(false)); for arg_tys.each |ty| { - vec::push(args, {ty: *ty, id: self.get_id()}); + args.push({ty: *ty, id: self.get_id()}); } kind = tuple_variant_kind(args); } else if self.eat(token::EQ) { @@ -3200,7 +3200,7 @@ impl parser { let vr = {name: ident, attrs: variant_attrs, kind: kind, id: self.get_id(), disr_expr: disr_expr, vis: vis}; - vec::push(variants, spanned(vlo, self.last_span.hi, vr)); + variants.push(spanned(vlo, self.last_span.hi, vr)); if needs_comma && !self.eat(token::COMMA) { break; } } @@ -3427,7 +3427,7 @@ impl parser { while self.token == token::MOD_SEP { self.bump(); let id = self.parse_ident(); - vec::push(path, id); + path.push(id); } let path = @{span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, types: ~[]}; @@ -3445,7 +3445,7 @@ impl parser { token::IDENT(i, _) => { self.bump(); - vec::push(path, i); + path.push(i); } // foo::bar::{a,b,c} @@ -3488,7 +3488,7 @@ impl parser { let mut vp = ~[self.parse_view_path()]; while self.token == token::COMMA { self.bump(); - vec::push(vp, self.parse_view_path()); + vp.push(self.parse_view_path()); } return vp; } @@ -3662,7 +3662,7 @@ impl parser { let mut first_outer_attr = first_outer_attr; while self.token != term { let cdir = @self.parse_crate_directive(first_outer_attr); - vec::push(cdirs, cdir); + cdirs.push(cdir); first_outer_attr = ~[]; } return cdirs; diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs index c8f5871333f..4bbd51524c4 100644 --- a/src/rustc/back/link.rs +++ b/src/rustc/back/link.rs @@ -392,14 +392,14 @@ fn build_link_meta(sess: session, c: ast::crate, output: &Path, if attr::get_meta_item_name(*meta) == ~"name" { match attr::get_meta_item_value_str(*meta) { Some(v) => { name = Some(v); } - None => vec::push(cmh_items, *meta) + None => cmh_items.push(*meta) } } else if attr::get_meta_item_name(*meta) == ~"vers" { match attr::get_meta_item_value_str(*meta) { Some(v) => { vers = Some(v); } - None => vec::push(cmh_items, *meta) + None => cmh_items.push(*meta) } - } else { vec::push(cmh_items, *meta); } + } else { cmh_items.push(*meta); } } return {name: name, vers: vers, cmh_items: cmh_items}; } @@ -657,9 +657,9 @@ fn link_binary(sess: session, let mut cc_args = vec::append(~[stage], sess.targ_cfg.target_strs.cc_args); - vec::push(cc_args, ~"-o"); - vec::push(cc_args, output.to_str()); - vec::push(cc_args, obj_filename.to_str()); + cc_args.push(~"-o"); + cc_args.push(output.to_str()); + cc_args.push(obj_filename.to_str()); let mut lib_cmd; let os = sess.targ_cfg.os; @@ -674,17 +674,17 @@ fn link_binary(sess: session, let cstore = sess.cstore; for cstore::get_used_crate_files(cstore).each |cratepath| { if cratepath.filetype() == Some(~".rlib") { - vec::push(cc_args, cratepath.to_str()); + cc_args.push(cratepath.to_str()); loop; } let dir = cratepath.dirname(); - if dir != ~"" { vec::push(cc_args, ~"-L" + dir); } + if dir != ~"" { cc_args.push(~"-L" + dir); } let libarg = unlib(sess.targ_cfg, cratepath.filestem().get()); - vec::push(cc_args, ~"-l" + libarg); + cc_args.push(~"-l" + libarg); } let ula = cstore::get_used_link_args(cstore); - for ula.each |arg| { vec::push(cc_args, *arg); } + for ula.each |arg| { cc_args.push(*arg); } // # Extern library linking @@ -695,41 +695,41 @@ fn link_binary(sess: session, // forces to make sure that library can be found at runtime. let addl_paths = sess.opts.addl_lib_search_paths; - for addl_paths.each |path| { vec::push(cc_args, ~"-L" + path.to_str()); } + for addl_paths.each |path| { cc_args.push(~"-L" + path.to_str()); } // The names of the extern libraries let used_libs = cstore::get_used_libraries(cstore); - for used_libs.each |l| { vec::push(cc_args, ~"-l" + *l); } + for used_libs.each |l| { cc_args.push(~"-l" + *l); } if sess.building_library { - vec::push(cc_args, lib_cmd); + cc_args.push(lib_cmd); // On mac we need to tell the linker to let this library // be rpathed if sess.targ_cfg.os == session::os_macos { - vec::push(cc_args, ~"-Wl,-install_name,@rpath/" + cc_args.push(~"-Wl,-install_name,@rpath/" + output.filename().get()); } } if !sess.debugging_opt(session::no_rt) { // Always want the runtime linked in - vec::push(cc_args, ~"-lrustrt"); + cc_args.push(~"-lrustrt"); } // On linux librt and libdl are an indirect dependencies via rustrt, // and binutils 2.22+ won't add them automatically if sess.targ_cfg.os == session::os_linux { - vec::push_all(cc_args, ~[~"-lrt", ~"-ldl"]); + cc_args.push_all(~[~"-lrt", ~"-ldl"]); // LLVM implements the `frem` instruction as a call to `fmod`, // which lives in libm. Similar to above, on some linuxes we // have to be explicit about linking to it. See #2510 - vec::push(cc_args, ~"-lm"); + cc_args.push(~"-lm"); } if sess.targ_cfg.os == session::os_freebsd { - vec::push_all(cc_args, ~[~"-pthread", ~"-lrt", + cc_args.push_all(~[~"-pthread", ~"-lrt", ~"-L/usr/local/lib", ~"-lexecinfo", ~"-L/usr/local/lib/gcc46", ~"-L/usr/local/lib/gcc44", ~"-lstdc++", @@ -743,15 +743,15 @@ fn link_binary(sess: session, // understand how to unwind our __morestack frame, so we have to turn it // off. This has impacted some other projects like GHC. if sess.targ_cfg.os == session::os_macos { - vec::push(cc_args, ~"-Wl,-no_compact_unwind"); + cc_args.push(~"-Wl,-no_compact_unwind"); } // Stack growth requires statically linking a __morestack function - vec::push(cc_args, ~"-lmorestack"); + cc_args.push(~"-lmorestack"); // FIXME (#2397): At some point we want to rpath our guesses as to where // extern libraries might live, based on the addl_lib_search_paths - vec::push_all(cc_args, rpath::get_rpath_flags(sess, &output)); + cc_args.push_all(rpath::get_rpath_flags(sess, &output)); debug!("%s link args: %s", cc_prog, str::connect(cc_args, ~" ")); // We run 'cc' here diff --git a/src/rustc/back/rpath.rs b/src/rustc/back/rpath.rs index 132bbc96344..8aa7caefc7a 100644 --- a/src/rustc/back/rpath.rs +++ b/src/rustc/back/rpath.rs @@ -81,8 +81,8 @@ fn get_rpaths(os: session::os, log_rpaths(~"fallback", fallback_rpaths); let mut rpaths = rel_rpaths; - vec::push_all(rpaths, abs_rpaths); - vec::push_all(rpaths, fallback_rpaths); + rpaths.push_all(abs_rpaths); + rpaths.push_all(fallback_rpaths); // Remove duplicates let rpaths = minimize_rpaths(rpaths); @@ -136,9 +136,9 @@ fn get_relative_to(abs1: &Path, abs2: &Path) -> Path { } let mut path = ~[]; - for uint::range(start_idx, len1 - 1) |_i| { vec::push(path, ~".."); }; + for uint::range(start_idx, len1 - 1) |_i| { path.push(~".."); }; - vec::push_all(path, vec::view(split2, start_idx, len2 - 1)); + path.push_all(vec::view(split2, start_idx, len2 - 1)); if vec::is_not_empty(path) { return Path("").push_many(path); @@ -172,7 +172,7 @@ fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] { for rpaths.each |rpath| { let s = rpath.to_str(); if !set.contains_key(s) { - vec::push(minimized, *rpath); + minimized.push(*rpath); set.insert(s, ()); } } diff --git a/src/rustc/back/upcall.rs b/src/rustc/back/upcall.rs index f289a0bdf27..a2c864f6f46 100644 --- a/src/rustc/back/upcall.rs +++ b/src/rustc/back/upcall.rs @@ -28,7 +28,7 @@ fn declare_upcalls(targ_cfg: @session::config, tys: ~[TypeRef], rv: TypeRef) -> ValueRef { let mut arg_tys: ~[TypeRef] = ~[]; - for tys.each |t| { vec::push(arg_tys, *t); } + for tys.each |t| { arg_tys.push(*t); } let fn_ty = T_fn(arg_tys, rv); return base::decl_cdecl_fn(llmod, prefix + name, fn_ty); } diff --git a/src/rustc/driver/driver.rs b/src/rustc/driver/driver.rs index f890fa85eb3..3acacd3c0a5 100644 --- a/src/rustc/driver/driver.rs +++ b/src/rustc/driver/driver.rs @@ -94,7 +94,7 @@ fn parse_cfgspecs(cfgspecs: ~[~str]) -> ast::crate_cfg { // meta_word variant. let mut words = ~[]; for cfgspecs.each |s| { - vec::push(words, attr::mk_word_item(*s)); + words.push(attr::mk_word_item(*s)); } return words; } @@ -466,7 +466,7 @@ fn build_session_options(binary: ~str, level_name, lint_name)); } Some(lint) => { - vec::push(lint_opts, (lint.lint, *level)); + lint_opts.push((lint.lint, *level)); } } } diff --git a/src/rustc/front/test.rs b/src/rustc/front/test.rs index e1441d9ee5e..55d71ab6950 100644 --- a/src/rustc/front/test.rs +++ b/src/rustc/front/test.rs @@ -99,7 +99,7 @@ fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) -> fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) -> Option<@ast::item> { - vec::push(cx.path, i.ident); + cx.path.push(i.ident); debug!("current path: %s", ast_util::path_name_i(cx.path, cx.sess.parse_sess.interner)); @@ -286,7 +286,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr { debug!("building test vector from %u tests", cx.testfns.len()); let mut descs = ~[]; for cx.testfns.each |test| { - vec::push(descs, mk_test_desc_rec(cx, *test)); + descs.push(mk_test_desc_rec(cx, *test)); } let inner_expr = @{id: cx.sess.next_node_id(), diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index 8a982eaf497..edf6a9612c7 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -115,7 +115,7 @@ fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) { fn add_used_crate_file(cstore: cstore, lib: &Path) { if !vec::contains(p(cstore).used_crate_files, copy *lib) { - vec::push(p(cstore).used_crate_files, copy *lib); + p(cstore).used_crate_files.push(copy *lib); } } @@ -127,7 +127,7 @@ fn add_used_library(cstore: cstore, lib: ~str) -> bool { assert lib != ~""; if vec::contains(p(cstore).used_libraries, lib) { return false; } - vec::push(p(cstore).used_libraries, lib); + p(cstore).used_libraries.push(lib); return true; } @@ -136,7 +136,7 @@ fn get_used_libraries(cstore: cstore) -> ~[~str] { } fn add_used_link_args(cstore: cstore, args: ~str) { - vec::push_all(p(cstore).used_link_args, str::split_char(args, ' ')); + p(cstore).used_link_args.push_all(str::split_char(args, ' ')); } fn get_used_link_args(cstore: cstore) -> ~[~str] { @@ -163,7 +163,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[~str] { let cdata = cstore::get_crate_data(cstore, cnum); let hash = decoder::get_crate_hash(cdata.data); debug!("Add hash[%s]: %s", cdata.name, hash); - vec::push(result, {name: cdata.name, hash: hash}); + result.push({name: cdata.name, hash: hash}); }; pure fn lteq(a: &crate_hash, b: &crate_hash) -> bool {a.name <= b.name} let sorted = std::sort::merge_sort(lteq, result); diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index 4a72867eb85..a6bb681bc16 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -227,7 +227,7 @@ fn item_type(item_id: ast::def_id, item: ebml::Doc, fn item_impl_traits(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ~[ty::t] { let mut results = ~[]; for ebml::tagged_docs(item, tag_impl_trait) |ity| { - vec::push(results, doc_type(ity, tcx, cdata)); + results.push(doc_type(ity, tcx, cdata)); }; results } @@ -239,7 +239,7 @@ fn item_ty_param_bounds(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd) let bd = parse_bounds_data(p.data, p.start, cdata.cnum, tcx, |did| { translate_def_id(cdata, did) }); - vec::push(bounds, bd); + bounds.push(bd); } @bounds } @@ -263,7 +263,7 @@ fn enum_variant_ids(item: ebml::Doc, cdata: cmd) -> ~[ast::def_id] { let v = tag_items_data_item_variant; for ebml::tagged_docs(item, v) |p| { let ext = ebml::with_doc_data(p, |d| parse_def_id(d)); - vec::push(ids, {crate: cdata.cnum, node: ext.node}); + ids.push({crate: cdata.cnum, node: ext.node}); }; return ids; } @@ -278,10 +278,10 @@ fn item_path(intr: @ident_interner, item_doc: ebml::Doc) -> ast_map::path { for ebml::docs(path_doc) |tag, elt_doc| { if tag == tag_path_elt_mod { let str = ebml::doc_as_str(elt_doc); - vec::push(result, ast_map::path_mod(intr.intern(@str))); + result.push(ast_map::path_mod(intr.intern(@str))); } else if tag == tag_path_elt_name { let str = ebml::doc_as_str(elt_doc); - vec::push(result, ast_map::path_name(intr.intern(@str))); + result.push(ast_map::path_name(intr.intern(@str))); } else { // ignore tag_path_len element } @@ -584,7 +584,7 @@ fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id, let mut arg_tys: ~[ty::t] = ~[]; match ty::get(ctor_ty).sty { ty::ty_fn(f) => { - for f.sig.inputs.each |a| { vec::push(arg_tys, a.ty); } + for f.sig.inputs.each |a| { arg_tys.push(a.ty); } } _ => { /* Nullary enum variant. */ } } @@ -592,7 +592,7 @@ fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id, Some(val) => { disr_val = val; } _ => { /* empty */ } } - vec::push(infos, @{args: arg_tys, ctor_ty: ctor_ty, name: name, + infos.push(@{args: arg_tys, ctor_ty: ctor_ty, name: name, id: *did, disr_val: disr_val}); disr_val += 1; } @@ -645,7 +645,7 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc, let m_did = ebml::with_doc_data(doc, |d| parse_def_id(d)); let mth_item = lookup_item(m_did.node, cdata.data); let self_ty = get_self_ty(mth_item); - vec::push(rslt, @{did: translate_def_id(cdata, m_did), + rslt.push(@{did: translate_def_id(cdata, m_did), /* FIXME (maybe #2323) tjc: take a look at this. */ n_tps: item_ty_param_count(mth_item) - base_tps, ident: item_name(intr, mth_item), @@ -675,7 +675,7 @@ fn get_impls_for_mod(intr: @ident_interner, cdata: cmd, let nm = item_name(intr, item); if match name { Some(n) => { n == nm } None => { true } } { let base_tps = item_ty_param_count(item); - vec::push(result, @{ + result.push(@{ did: local_did, ident: nm, methods: item_impl_methods(intr, impl_cdata, item, base_tps) }); @@ -701,7 +701,7 @@ fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id, ~"get_trait_methods: id has non-function type"); } }; let self_ty = get_self_ty(mth); - vec::push(result, {ident: name, tps: bounds, fty: fty, + result.push({ident: name, tps: bounds, fty: fty, self_ty: self_ty, vis: ast::public}); } @@ -753,7 +753,7 @@ fn get_class_members(intr: @ident_interner, cdata: cmd, id: ast::node_id, let name = item_name(intr, an_item); let did = item_def_id(an_item, cdata); let mt = field_mutability(an_item); - vec::push(result, {ident: name, id: did, vis: + result.push({ident: name, id: did, vis: family_to_visibility(f), mutability: mt}); } } @@ -835,7 +835,7 @@ fn get_meta_items(md: ebml::Doc) -> ~[@ast::meta_item] { for ebml::tagged_docs(md, tag_meta_item_word) |meta_item_doc| { let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name); let n = str::from_bytes(ebml::doc_data(nd)); - vec::push(items, attr::mk_word_item(n)); + items.push(attr::mk_word_item(n)); }; for ebml::tagged_docs(md, tag_meta_item_name_value) |meta_item_doc| { let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name); @@ -844,13 +844,13 @@ fn get_meta_items(md: ebml::Doc) -> ~[@ast::meta_item] { let v = str::from_bytes(ebml::doc_data(vd)); // FIXME (#623): Should be able to decode meta_name_value variants, // but currently the encoder just drops them - vec::push(items, attr::mk_name_value_item_str(n, v)); + items.push(attr::mk_name_value_item_str(n, v)); }; for ebml::tagged_docs(md, tag_meta_item_list) |meta_item_doc| { let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name); let n = str::from_bytes(ebml::doc_data(nd)); let subitems = get_meta_items(meta_item_doc); - vec::push(items, attr::mk_list_item(n, subitems)); + items.push(attr::mk_list_item(n, subitems)); }; return items; } @@ -865,10 +865,10 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] { // an attribute assert (vec::len(meta_items) == 1u); let meta_item = meta_items[0]; - vec::push(attrs, - {node: {style: ast::attr_outer, value: *meta_item, - is_sugared_doc: false}, - span: ast_util::dummy_sp()}); + attrs.push( + {node: {style: ast::attr_outer, value: *meta_item, + is_sugared_doc: false}, + span: ast_util::dummy_sp()}); }; } option::None => () @@ -910,7 +910,7 @@ fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] { str::from_bytes(ebml::doc_data(ebml::get_doc(doc, tag_))) } for ebml::tagged_docs(depsdoc, tag_crate_dep) |depdoc| { - vec::push(deps, {cnum: crate_num, + deps.push({cnum: crate_num, name: intr.intern(@docstr(depdoc, tag_crate_dep_name)), vers: docstr(depdoc, tag_crate_dep_vers), hash: docstr(depdoc, tag_crate_dep_hash)}); @@ -977,7 +977,7 @@ fn get_crate_module_paths(intr: @ident_interner, cdata: cmd) // Collect everything by now. There might be multiple // paths pointing to the same did. Those will be // unified later by using the mods map - vec::push(res, (did, path)); + res.push((did, path)); } return do vec::filter(res) |x| { let (_, xp) = x; diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 3424ea8dd57..81ad9dfc3a5 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -118,12 +118,12 @@ type entry = {val: T, pos: uint}; fn add_to_index(ecx: @encode_ctxt, ebml_w: ebml::Writer, path: &[ident], &index: ~[entry<~str>], name: ident) { let mut full_path = ~[]; - vec::push_all(full_path, path); - vec::push(full_path, name); - vec::push(index, - {val: ast_util::path_name_i(full_path, - ecx.tcx.sess.parse_sess.interner), - pos: ebml_w.writer.tell()}); + full_path.push_all(path); + full_path.push(name); + index.push( + {val: ast_util::path_name_i(full_path, + ecx.tcx.sess.parse_sess.interner), + pos: ebml_w.writer.tell()}); } fn encode_trait_ref(ebml_w: ebml::Writer, ecx: @encode_ctxt, t: @trait_ref) { @@ -225,7 +225,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::Writer, let mut i = 0; let vi = ty::enum_variants(ecx.tcx, {crate: local_crate, node: id}); for variants.each |variant| { - vec::push(*index, {val: variant.node.id, pos: ebml_w.writer.tell()}); + index.push({val: variant.node.id, pos: ebml_w.writer.tell()}); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(variant.node.id)); encode_family(ebml_w, 'v'); @@ -390,9 +390,9 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::Writer, match field.node.kind { named_field(nm, mt, vis) => { let id = field.node.id; - vec::push(*index, {val: id, pos: ebml_w.writer.tell()}); - vec::push(*global_index, {val: id, - pos: ebml_w.writer.tell()}); + index.push({val: id, pos: ebml_w.writer.tell()}); + global_index.push({val: id, + pos: ebml_w.writer.tell()}); ebml_w.start_tag(tag_items_data_item); debug!("encode_info_for_class: doing %s %d", tcx.sess.str_of(nm), id); @@ -411,9 +411,9 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::Writer, for methods.each |m| { match m.vis { public | inherited => { - vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()}); - vec::push(*global_index, - {val: m.id, pos: ebml_w.writer.tell()}); + index.push({val: m.id, pos: ebml_w.writer.tell()}); + global_index.push( + {val: m.id, pos: ebml_w.writer.tell()}); let impl_path = vec::append_one(path, ast_map::path_name(m.ident)); debug!("encode_info_for_class: doing %s %d", @@ -519,7 +519,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item, fn add_to_index_(item: @item, ebml_w: ebml::Writer, index: @mut ~[entry]) { - vec::push(*index, {val: item.id, pos: ebml_w.writer.tell()}); + index.push({val: item.id, pos: ebml_w.writer.tell()}); } let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index); @@ -603,7 +603,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item, index); /* Encode the dtor */ do struct_def.dtor.iter |dtor| { - vec::push(*index, {val: dtor.node.id, pos: ebml_w.writer.tell()}); + index.push({val: dtor.node.id, pos: ebml_w.writer.tell()}); encode_info_for_ctor(ecx, ebml_w, dtor.node.id, ecx.tcx.sess.ident_of( ecx.tcx.sess.str_of(item.ident) + @@ -688,7 +688,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item, for struct_def.ctor.each |ctor| { debug!("encoding info for ctor %s %d", ecx.tcx.sess.str_of(item.ident), ctor.node.id); - vec::push(*index, { + index.push({ val: ctor.node.id, pos: ebml_w.writer.tell() }); @@ -723,7 +723,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item, let impl_path = vec::append_one(path, ast_map::path_name(item.ident)); for methods.each |m| { - vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()}); + index.push({val: m.id, pos: ebml_w.writer.tell()}); encode_info_for_method(ecx, ebml_w, impl_path, should_inline(m.attrs), item.id, *m, vec::append(tps, m.tps)); @@ -774,7 +774,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, item: @item, let ty_m = ast_util::trait_method_to_ty_method(*m); if ty_m.self_ty.node != ast::sty_static { loop; } - vec::push(*index, {val: ty_m.id, pos: ebml_w.writer.tell()}); + index.push({val: ty_m.id, pos: ebml_w.writer.tell()}); ebml_w.start_tag(tag_items_data_item); encode_def_id(ebml_w, local_def(ty_m.id)); @@ -799,7 +799,7 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: ebml::Writer, index: @mut ~[entry], path: ast_map::path, abi: foreign_abi) { if !reachable(ecx, nitem.id) { return; } - vec::push(*index, {val: nitem.id, pos: ebml_w.writer.tell()}); + index.push({val: nitem.id, pos: ebml_w.writer.tell()}); ebml_w.start_tag(tag_items_data_item); match nitem.node { @@ -831,7 +831,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::Writer, crate: @crate) -> ~[entry] { let index = @mut ~[]; ebml_w.start_tag(tag_items_data); - vec::push(*index, {val: crate_node_id, pos: ebml_w.writer.tell()}); + index.push({val: crate_node_id, pos: ebml_w.writer.tell()}); encode_info_for_mod(ecx, ebml_w, crate.node.module, crate_node_id, ~[], syntax::parse::token::special_idents::invalid); @@ -869,15 +869,15 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::Writer, fn create_index(index: ~[entry]) -> ~[@~[entry]] { let mut buckets: ~[@mut ~[entry]] = ~[]; - for uint::range(0u, 256u) |_i| { vec::push(buckets, @mut ~[]); }; + for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); }; for index.each |elt| { let h = elt.val.hash() as uint; - vec::push(*buckets[h % 256], *elt); + buckets[h % 256].push(*elt); } let mut buckets_frozen = ~[]; for buckets.each |bucket| { - vec::push(buckets_frozen, @**bucket); + buckets_frozen.push(@**bucket); } return buckets_frozen; } @@ -889,7 +889,7 @@ fn encode_index(ebml_w: ebml::Writer, buckets: ~[@~[entry]], let mut bucket_locs: ~[uint] = ~[]; ebml_w.start_tag(tag_index_buckets); for buckets.each |bucket| { - vec::push(bucket_locs, ebml_w.writer.tell()); + bucket_locs.push(ebml_w.writer.tell()); ebml_w.start_tag(tag_index_buckets_bucket); for vec::each(**bucket) |elt| { ebml_w.start_tag(tag_index_buckets_bucket_elt); @@ -996,8 +996,7 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] { let mut attrs: ~[attribute] = ~[]; let mut found_link_attr = false; for crate.node.attrs.each |attr| { - vec::push( - attrs, + attrs.push( if attr::get_attr_name(*attr) != ~"link" { *attr } else { @@ -1011,7 +1010,7 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] { }); } - if !found_link_attr { vec::push(attrs, synthesize_link_attr(ecx, ~[])); } + if !found_link_attr { attrs.push(synthesize_link_attr(ecx, ~[])); } return attrs; } @@ -1031,7 +1030,7 @@ fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: ebml::Writer, let dep = {cnum: key, name: ecx.tcx.sess.ident_of(val.name), vers: decoder::get_crate_vers(val.data), hash: decoder::get_crate_hash(val.data)}; - vec::push(deps, dep); + deps.push(dep); }; // Sort by cnum diff --git a/src/rustc/metadata/filesearch.rs b/src/rustc/metadata/filesearch.rs index 77d06bd2d29..63370b09321 100644 --- a/src/rustc/metadata/filesearch.rs +++ b/src/rustc/metadata/filesearch.rs @@ -39,15 +39,15 @@ fn mk_filesearch(maybe_sysroot: Option, fn lib_search_paths() -> ~[Path] { let mut paths = self.addl_lib_search_paths; - vec::push(paths, - make_target_lib_path(&self.sysroot, - self.target_triple)); + paths.push( + make_target_lib_path(&self.sysroot, + self.target_triple)); match get_cargo_lib_path_nearest() { - result::Ok(p) => vec::push(paths, p), + result::Ok(p) => paths.push(p), result::Err(_) => () } match get_cargo_lib_path() { - result::Ok(p) => vec::push(paths, p), + result::Ok(p) => paths.push(p), result::Err(_) => () } paths diff --git a/src/rustc/metadata/loader.rs b/src/rustc/metadata/loader.rs index b2c28fafd4c..2ccaccf17a5 100644 --- a/src/rustc/metadata/loader.rs +++ b/src/rustc/metadata/loader.rs @@ -90,7 +90,7 @@ fn find_library_crate_aux(cx: ctxt, option::None::<()> } else { debug!("found %s with matching metadata", path.to_str()); - vec::push(matches, {ident: path.to_str(), data: cvec}); + matches.push({ident: path.to_str(), data: cvec}); option::None::<()> } } diff --git a/src/rustc/metadata/tydecode.rs b/src/rustc/metadata/tydecode.rs index 5cf24aef558..f3fa0e3f350 100644 --- a/src/rustc/metadata/tydecode.rs +++ b/src/rustc/metadata/tydecode.rs @@ -84,7 +84,7 @@ fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) { fn parse_path(st: @pstate) -> @ast::path { let mut idents: ~[ast::ident] = ~[]; fn is_last(c: char) -> bool { return c == '(' || c == ':'; } - vec::push(idents, parse_ident_(st, is_last)); + idents.push(parse_ident_(st, is_last)); loop { match peek(st) { ':' => { next(st); next(st); } @@ -93,7 +93,7 @@ fn parse_path(st: @pstate) -> @ast::path { return @{span: ast_util::dummy_sp(), global: false, idents: idents, rp: None, types: ~[]}; - } else { vec::push(idents, parse_ident_(st, is_last)); } + } else { idents.push(parse_ident_(st, is_last)); } } } }; @@ -136,7 +136,7 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs { assert next(st) == '['; let mut params: ~[ty::t] = ~[]; - while peek(st) != ']' { vec::push(params, parse_ty(st, conv)); } + while peek(st) != ']' { params.push(parse_ty(st, conv)); } st.pos = st.pos + 1u; return {self_r: self_r, @@ -273,7 +273,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { let mut fields: ~[ty::field] = ~[]; while peek(st) != ']' { let name = st.tcx.sess.ident_of(parse_str(st, '=')); - vec::push(fields, {ident: name, mt: parse_mt(st, conv)}); + fields.push({ident: name, mt: parse_mt(st, conv)}); } st.pos = st.pos + 1u; return ty::mk_rec(st.tcx, fields); @@ -281,7 +281,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t { 'T' => { assert (next(st) == '['); let mut params = ~[]; - while peek(st) != ']' { vec::push(params, parse_ty(st, conv)); } + while peek(st) != ']' { params.push(parse_ty(st, conv)); } st.pos = st.pos + 1u; return ty::mk_tup(st.tcx, params); } @@ -348,7 +348,7 @@ fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt { fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id { let mut def = ~[]; - while peek(st) != '|' { vec::push(def, next_byte(st)); } + while peek(st) != '|' { def.push(next_byte(st)); } st.pos = st.pos + 1u; return conv(parse_def_id(def)); } @@ -412,7 +412,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy { let mut inputs: ~[ty::arg] = ~[]; while peek(st) != ']' { let mode = parse_mode(st); - vec::push(inputs, {mode: mode, ty: parse_ty(st, conv)}); + inputs.push({mode: mode, ty: parse_ty(st, conv)}); } st.pos += 1u; // eat the ']' let (ret_style, ret_ty) = parse_ret_ty(st, conv); @@ -464,7 +464,7 @@ fn parse_bounds_data(data: @~[u8], start: uint, fn parse_bounds(st: @pstate, conv: conv_did) -> @~[ty::param_bound] { let mut bounds = ~[]; loop { - vec::push(bounds, match next(st) { + bounds.push(match next(st) { 'S' => ty::bound_send, 'C' => ty::bound_copy, 'K' => ty::bound_const, diff --git a/src/rustc/middle/capture.rs b/src/rustc/middle/capture.rs index 1e885605171..618d43e121a 100644 --- a/src/rustc/middle/capture.rs +++ b/src/rustc/middle/capture.rs @@ -122,6 +122,6 @@ fn compute_capture_vars(tcx: ty::ctxt, } let mut result = ~[]; - for cap_map.each_value |cap_var| { vec::push(result, cap_var); } + for cap_map.each_value |cap_var| { result.push(cap_var); } return result; } diff --git a/src/rustc/middle/check_alt.rs b/src/rustc/middle/check_alt.rs index 32801ed760c..54f415857ba 100644 --- a/src/rustc/middle/check_alt.rs +++ b/src/rustc/middle/check_alt.rs @@ -67,7 +67,7 @@ fn check_arms(tcx: ty::ctxt, arms: ~[arm]) { } _ => () } - if arm.guard.is_none() { vec::push(seen, v); } + if arm.guard.is_none() { seen.push(v); } } } } @@ -269,7 +269,7 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> Option { let mut found = ~[]; for m.each |r| { do option::iter(&pat_ctor_id(tcx, r[0])) |id| { - if !vec::contains(found, id) { vec::push(found, id); } + if !vec::contains(found, id) { found.push(id); } } } let variants = ty::enum_variants(tcx, eid); diff --git a/src/rustc/middle/freevars.rs b/src/rustc/middle/freevars.rs index 251ef2c89b7..7e925d7d8d8 100644 --- a/src/rustc/middle/freevars.rs +++ b/src/rustc/middle/freevars.rs @@ -63,7 +63,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk) if i == depth { // Made it to end of loop let dnum = ast_util::def_id_of_def(def).node; if !seen.contains_key(dnum) { - vec::push(*refs, @{def:def, span:expr.span}); + refs.push(@{def:def, span:expr.span}); seen.insert(dnum, ()); } } diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index 4f9045ec77e..7d911f7d05a 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -42,17 +42,17 @@ fn kind_to_str(k: kind) -> ~str { let mut kinds = ~[]; if ty::kind_lteq(kind_const(), k) { - vec::push(kinds, ~"const"); + kinds.push(~"const"); } if ty::kind_can_be_copied(k) { - vec::push(kinds, ~"copy"); + kinds.push(~"copy"); } if ty::kind_can_be_sent(k) { - vec::push(kinds, ~"send"); + kinds.push(~"send"); } else if ty::kind_is_owned(k) { - vec::push(kinds, ~"owned"); + kinds.push(~"owned"); } str::connect(kinds, ~" ") diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs index ff77a598d27..b92f8e8441f 100644 --- a/src/rustc/middle/lint.rs +++ b/src/rustc/middle/lint.rs @@ -288,7 +288,7 @@ impl ctxt { for metas.each |meta| { match meta.node { ast::meta_word(lintname) => { - vec::push(triples, (*meta, *level, lintname)); + triples.push((*meta, *level, lintname)); } _ => { self.sess.span_err( diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index a4c9b5f4b35..b39b7914905 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -302,7 +302,7 @@ fn IrMaps(tcx: ty::ctxt, method_map: typeck::method_map, impl IrMaps { fn add_live_node(lnk: LiveNodeKind) -> LiveNode { let ln = LiveNode(self.num_live_nodes); - vec::push(self.lnks, lnk); + self.lnks.push(lnk); self.num_live_nodes += 1u; debug!("%s is of kind %?", ln.to_str(), lnk); @@ -319,7 +319,7 @@ impl IrMaps { fn add_variable(vk: VarKind) -> Variable { let v = Variable(self.num_vars); - vec::push(self.var_kinds, vk); + self.var_kinds.push(vk); self.num_vars += 1u; match vk { @@ -540,7 +540,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) { cap_move | cap_drop => true, // var must be dead afterwards cap_copy | cap_ref => false // var can still be used }; - vec::push(call_caps, {ln: cv_ln, is_move: is_move, rv: rv}); + call_caps.push({ln: cv_ln, is_move: is_move, rv: rv}); } None => {} } diff --git a/src/rustc/middle/pat_util.rs b/src/rustc/middle/pat_util.rs index e67b85b869c..006065988b9 100644 --- a/src/rustc/middle/pat_util.rs +++ b/src/rustc/middle/pat_util.rs @@ -54,6 +54,6 @@ fn pat_bindings(dm: resolve::DefMap, pat: @pat, fn pat_binding_ids(dm: resolve::DefMap, pat: @pat) -> ~[node_id] { let mut found = ~[]; - pat_bindings(dm, pat, |_bm, b_id, _sp, _pt| vec::push(found, b_id) ); + pat_bindings(dm, pat, |_bm, b_id, _sp, _pt| found.push(b_id) ); return found; } diff --git a/src/rustc/middle/region.rs b/src/rustc/middle/region.rs index ae1c739b26b..ff708b7f4ef 100644 --- a/src/rustc/middle/region.rs +++ b/src/rustc/middle/region.rs @@ -141,7 +141,7 @@ fn nearest_common_ancestor(region_map: region_map, scope_a: ast::node_id, match region_map.find(scope) { None => return result, Some(superscope) => { - vec::push(result, superscope); + result.push(superscope); scope = superscope; } } diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 7380a217ebe..99d98c52f95 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -2897,7 +2897,7 @@ impl Resolver { if reexport { ~"reexport" } else { ~"export"}, self.session.str_of(ident), def_id_of_def(d.def)); - vec::push(*exports2, Export2 { + exports2.push(Export2 { reexport: reexport, name: self.session.str_of(ident), def_id: def_id_of_def(d.def) @@ -2949,7 +2949,7 @@ impl Resolver { for %?", self.session.str_of(name), module_.def_id); - vec::push(*exports2, Export2 { + exports2.push(Export2 { reexport: false, name: self.session.str_of(name), def_id: def_id_of_def(target_def) @@ -2960,7 +2960,7 @@ impl Resolver { %?", self.session.str_of(name), module_.def_id); - vec::push(*exports2, Export2 { + exports2.push(Export2 { reexport: true, name: self.session.str_of(name), def_id: def_id_of_def(target_def) diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 11b694bcb1d..165ca8e2fc4 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -305,7 +305,7 @@ fn enter_match(bcx: block, dm: DefMap, m: &[@Match/&r], _ => {} } - vec::push(result, @Match {pats: pats, data: br.data}); + result.push(@Match {pats: pats, data: br.data}); } None => () } @@ -398,8 +398,8 @@ fn enter_rec_or_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint, let mut pats = ~[]; for vec::each(fields) |fname| { match fpats.find(|p| p.ident == *fname) { - None => vec::push(pats, dummy), - Some(pat) => vec::push(pats, pat.pat) + None => pats.push(dummy), + Some(pat) => pats.push(pat.pat) } } Some(pats) @@ -582,7 +582,7 @@ fn collect_record_or_struct_fields(m: &[@Match], col: uint) -> ~[ast::ident] { for field_pats.each |field_pat| { let field_ident = field_pat.ident; if !vec::any(*idents, |x| x == field_ident) { - vec::push(*idents, field_ident); + idents.push(field_ident); } } } @@ -1162,9 +1162,9 @@ fn trans_alt_inner(scope_cx: block, let arm_data = @ArmData {bodycx: body, arm: arm, bindings_map: bindings_map}; - vec::push(arm_datas, arm_data); + arm_datas.push(arm_data); for vec::each(arm.pats) |p| { - vec::push(matches, @Match {pats: ~[*p], data: arm_data}); + matches.push(@Match {pats: ~[*p], data: arm_data}); } } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index b29fac0fa2f..94b09a30e4b 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -76,7 +76,7 @@ impl @crate_ctxt: get_insn_ctxt { fn insn_ctxt(s: &str) -> icx_popper { debug!("new insn_ctxt: %s", s); if self.sess.count_llvm_insns() { - vec::push(*self.stats.llvm_insn_ctxt, str::from_slice(s)); + self.stats.llvm_insn_ctxt.push(str::from_slice(s)); } icx_popper(self) } @@ -98,7 +98,7 @@ fn log_fn_time(ccx: @crate_ctxt, name: ~str, start: time::Timespec, end: time::Timespec) { let elapsed = 1000 * ((end.sec - start.sec) as int) + ((end.nsec as int) - (start.nsec as int)) / 1000000; - vec::push(*ccx.stats.fn_times, {ident: name, time: elapsed}); + ccx.stats.fn_times.push({ident: name, time: elapsed}); } fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv, @@ -1153,7 +1153,7 @@ fn cleanup_and_leave(bcx: block, upto: Option, } let sub_cx = sub_block(bcx, ~"cleanup"); Br(bcx, sub_cx.llbb); - vec::push(inf.cleanup_paths, {target: leave, dest: sub_cx.llbb}); + inf.cleanup_paths.push({target: leave, dest: sub_cx.llbb}); bcx = trans_block_cleanups_(sub_cx, block_cleanups(cur), is_lpad); } _ => () @@ -2001,7 +2001,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint); let mut args = ~[lloutputarg, llenvarg]; if takes_argv { - vec::push(args, llvm::LLVMGetParam(llfdecl, 2 as c_uint)); + args.push(llvm::LLVMGetParam(llfdecl, 2 as c_uint)); } Call(bcx, main_llfn, args); @@ -2451,10 +2451,10 @@ fn create_module_map(ccx: @crate_ctxt) -> ValueRef { for ccx.module_data.each |key, val| { let elt = C_struct(~[p2i(ccx, C_cstr(ccx, key)), p2i(ccx, val)]); - vec::push(elts, elt); + elts.push(elt); } let term = C_struct(~[C_int(ccx, 0), C_int(ccx, 0)]); - vec::push(elts, term); + elts.push(term); llvm::LLVMSetInitializer(map, C_array(elttype, elts)); return map; } @@ -2492,10 +2492,10 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) { let cr = str::as_c_str(nm, |buf| { llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf) }); - vec::push(subcrates, p2i(ccx, cr)); + subcrates.push(p2i(ccx, cr)); i += 1; } - vec::push(subcrates, C_int(ccx, 0)); + subcrates.push(C_int(ccx, 0)); let llannihilatefn; let annihilate_def_id = ccx.tcx.lang_items.annihilate_fn.get(); diff --git a/src/rustc/middle/trans/build.rs b/src/rustc/middle/trans/build.rs index 865374054e6..070132b4b18 100644 --- a/src/rustc/middle/trans/build.rs +++ b/src/rustc/middle/trans/build.rs @@ -435,7 +435,7 @@ fn GEP(cx: block, Pointer: ValueRef, Indices: ~[ValueRef]) -> ValueRef { // XXX: Use a small-vector optimization to avoid allocations here. fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef { let mut v: ~[ValueRef] = ~[]; - for vec::each(ixs) |i| { vec::push(v, C_i32(*i as i32)); } + for vec::each(ixs) |i| { v.push(C_i32(*i as i32)); } count_insn(cx, "gepi"); return InBoundsGEP(cx, base, v); } diff --git a/src/rustc/middle/trans/callee.rs b/src/rustc/middle/trans/callee.rs index 3050297b360..470d4dbb4ab 100644 --- a/src/rustc/middle/trans/callee.rs +++ b/src/rustc/middle/trans/callee.rs @@ -478,10 +478,10 @@ fn trans_args(cx: block, llenv: ValueRef, args: CallArgs, fn_ty: ty::t, } } }; - vec::push(llargs, llretslot); + llargs.push(llretslot); // Arg 1: Env (closure-bindings / self value) - vec::push(llargs, llenv); + llargs.push(llenv); // ... then explicit args. @@ -497,11 +497,11 @@ fn trans_args(cx: block, llenv: ValueRef, args: CallArgs, fn_ty: ty::t, if i == last { ret_flag } else { None }, autoref_arg) }); - vec::push(llargs, arg_val); + llargs.push(arg_val); } } ArgVals(vs) => { - vec::push_all(llargs, vs); + llargs.push_all(vs); } } @@ -622,7 +622,7 @@ fn trans_arg_expr(bcx: block, // However, we must cleanup should we fail before the // callee is actually invoked. scratch.add_clean(bcx); - vec::push(*temp_cleanups, scratch.val); + temp_cleanups.push(scratch.val); match arg_datum.appropriate_mode() { ByValue => { diff --git a/src/rustc/middle/trans/closure.rs b/src/rustc/middle/trans/closure.rs index 38526c223a1..7b071866136 100644 --- a/src/rustc/middle/trans/closure.rs +++ b/src/rustc/middle/trans/closure.rs @@ -259,16 +259,16 @@ fn build_closure(bcx0: block, match cap_var.mode { capture::cap_ref => { assert ck == ty::ck_block; - vec::push(env_vals, EnvValue {action: EnvRef, - datum: datum}); + env_vals.push(EnvValue {action: EnvRef, + datum: datum}); } capture::cap_copy => { - vec::push(env_vals, EnvValue {action: EnvStore, - datum: datum}); + env_vals.push(EnvValue {action: EnvStore, + datum: datum}); } capture::cap_move => { - vec::push(env_vals, EnvValue {action: EnvMove, - datum: datum}); + env_vals.push(EnvValue {action: EnvMove, + datum: datum}); } capture::cap_drop => { bcx = datum.drop_val(bcx); @@ -283,8 +283,8 @@ fn build_closure(bcx0: block, // Flag indicating we have returned (a by-ref bool): let flag_datum = Datum {val: flagptr, ty: ty::mk_bool(tcx), mode: ByRef, source: FromLvalue}; - vec::push(env_vals, EnvValue {action: EnvRef, - datum: flag_datum}); + env_vals.push(EnvValue {action: EnvRef, + datum: flag_datum}); // Return value (we just pass a by-ref () and cast it later to // the right thing): @@ -295,8 +295,8 @@ fn build_closure(bcx0: block, let ret_casted = PointerCast(bcx, ret_true, T_ptr(T_nil())); let ret_datum = Datum {val: ret_casted, ty: ty::mk_nil(tcx), mode: ByRef, source: FromLvalue}; - vec::push(env_vals, EnvValue {action: EnvRef, - datum: ret_datum}); + env_vals.push(EnvValue {action: EnvRef, + datum: ret_datum}); } return store_environment(bcx, env_vals, ck); diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index fc74e5e0e4d..0df63e40acf 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -348,9 +348,9 @@ fn add_clean(bcx: block, val: ValueRef, t: ty::t) { let {root, rooted} = root_for_cleanup(bcx, val, t); let cleanup_type = cleanup_type(bcx.tcx(), t); do in_scope_cx(bcx) |info| { - vec::push(info.cleanups, - clean(|a| glue::drop_ty_root(a, root, rooted, t), - cleanup_type)); + info.cleanups.push( + clean(|a| glue::drop_ty_root(a, root, rooted, t), + cleanup_type)); scope_clean_changed(info); } } @@ -362,9 +362,9 @@ fn add_clean_temp_immediate(cx: block, val: ValueRef, ty: ty::t) { ty_to_str(cx.ccx().tcx, ty)); let cleanup_type = cleanup_type(cx.tcx(), ty); do in_scope_cx(cx) |info| { - vec::push(info.cleanups, - clean_temp(val, |a| glue::drop_ty_immediate(a, val, ty), - cleanup_type)); + info.cleanups.push( + clean_temp(val, |a| glue::drop_ty_immediate(a, val, ty), + cleanup_type)); scope_clean_changed(info); } } @@ -376,9 +376,9 @@ fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) { let {root, rooted} = root_for_cleanup(bcx, val, t); let cleanup_type = cleanup_type(bcx.tcx(), t); do in_scope_cx(bcx) |info| { - vec::push(info.cleanups, - clean_temp(val, |a| glue::drop_ty_root(a, root, rooted, t), - cleanup_type)); + info.cleanups.push( + clean_temp(val, |a| glue::drop_ty_root(a, root, rooted, t), + cleanup_type)); scope_clean_changed(info); } } @@ -388,8 +388,8 @@ fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) { heap_exchange => |a| glue::trans_unique_free(a, ptr) }; do in_scope_cx(cx) |info| { - vec::push(info.cleanups, clean_temp(ptr, free_fn, - normal_exit_and_unwind)); + info.cleanups.push(clean_temp(ptr, free_fn, + normal_exit_and_unwind)); scope_clean_changed(info); } } @@ -1050,7 +1050,7 @@ fn C_postr(s: ~str) -> ValueRef { fn C_zero_byte_arr(size: uint) -> ValueRef unsafe { let mut i = 0u; let mut elts: ~[ValueRef] = ~[]; - while i < size { vec::push(elts, C_u8(0u)); i += 1u; } + while i < size { elts.push(C_u8(0u)); i += 1u; } return llvm::LLVMConstArray(T_i8(), vec::raw::to_ptr(elts), elts.len() as c_uint); } diff --git a/src/rustc/middle/trans/debuginfo.rs b/src/rustc/middle/trans/debuginfo.rs index 26a83951c01..6cd4b49fa3b 100644 --- a/src/rustc/middle/trans/debuginfo.rs +++ b/src/rustc/middle/trans/debuginfo.rs @@ -383,7 +383,7 @@ fn create_derived_type(type_tag: int, file: ValueRef, name: ~str, line: int, fn add_member(cx: @struct_ctxt, name: ~str, line: int, size: int, align: int, ty: ValueRef) { - vec::push(cx.members, create_derived_type(MemberTag, cx.file, name, line, + cx.members.push(create_derived_type(MemberTag, cx.file, name, line, size * 8, align * 8, cx.total_size, ty)); cx.total_size += size * 8; @@ -529,7 +529,7 @@ fn create_ty(_cx: @crate_ctxt, _t: ty::t, _ty: @ast::ty) ty::ty_rec(fields) { let fs = ~[]; for field in fields { - vec::push(fs, {node: {ident: field.ident, + fs.push({node: {ident: field.ident, mt: {ty: t_to_ty(cx, field.mt.ty, span), mutbl: field.mt.mutbl}}, span: span}); diff --git a/src/rustc/middle/trans/expr.rs b/src/rustc/middle/trans/expr.rs index 17a1ff112cd..dafaebef9e0 100644 --- a/src/rustc/middle/trans/expr.rs +++ b/src/rustc/middle/trans/expr.rs @@ -993,7 +993,7 @@ fn trans_rec_or_struct(bcx: block, let dest = GEPi(bcx, addr, struct_field(ix)); bcx = trans_into(bcx, field.node.expr, SaveIn(dest)); add_clean_temp_mem(bcx, dest, field_tys[ix].mt.ty); - vec::push(temp_cleanups, dest); + temp_cleanups.push(dest); } // copy over any remaining fields from the base (for @@ -1046,7 +1046,7 @@ fn trans_tup(bcx: block, elts: ~[@ast::expr], dest: Dest) -> block { let e_ty = expr_ty(bcx, *e); bcx = trans_into(bcx, *e, SaveIn(dest)); add_clean_temp_mem(bcx, dest, e_ty); - vec::push(temp_cleanups, dest); + temp_cleanups.push(dest); } for vec::each(temp_cleanups) |cleanup| { revoke_clean(bcx, *cleanup); diff --git a/src/rustc/middle/trans/foreign.rs b/src/rustc/middle/trans/foreign.rs index e775b3fd746..f1077912fec 100644 --- a/src/rustc/middle/trans/foreign.rs +++ b/src/rustc/middle/trans/foreign.rs @@ -297,21 +297,21 @@ fn llreg_ty(cls: ~[x86_64_reg_class]) -> TypeRef { while i < e { match cls[i] { integer_class => { - vec::push(tys, T_i64()); + tys.push(T_i64()); } sse_fv_class => { let vec_len = llvec_len(vec::tailn(cls, i + 1u)) * 2u; let vec_ty = llvm::LLVMVectorType(T_f32(), vec_len as c_uint); - vec::push(tys, vec_ty); + tys.push(vec_ty); i += vec_len; loop; } sse_fs_class => { - vec::push(tys, T_f32()); + tys.push(T_f32()); } sse_ds_class => { - vec::push(tys, T_f64()); + tys.push(T_f64()); } _ => fail ~"llregtype: unhandled class" } @@ -378,8 +378,8 @@ fn x86_64_tys(atys: ~[TypeRef], let mut attrs = ~[]; for vec::each(atys) |t| { let (ty, attr) = x86_64_ty(*t, is_pass_byval, ByValAttribute); - vec::push(arg_tys, ty); - vec::push(attrs, attr); + arg_tys.push(ty); + attrs.push(attr); } let mut (ret_ty, ret_attr) = x86_64_ty(rty, is_ret_bysret, StructRetAttribute); @@ -619,7 +619,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt, } else { load_inbounds(bcx, llargbundle, [0u, i]) }; - vec::push(llargvals, llargval); + llargvals.push(llargval); i += 1u; } } @@ -627,7 +627,7 @@ fn trans_foreign_mod(ccx: @crate_ctxt, while i < n { let llargval = load_inbounds(bcx, llargbundle, [0u, i]); - vec::push(llargvals, llargval); + llargvals.push(llargval); i += 1u; } } @@ -1041,12 +1041,12 @@ fn trans_foreign_fn(ccx: @crate_ctxt, path: ast_map::path, decl: ast::fn_decl, let mut i = 0u; let n = vec::len(tys.arg_tys); let llretptr = load_inbounds(bcx, llargbundle, ~[0u, n]); - vec::push(llargvals, llretptr); + llargvals.push(llretptr); let llenvptr = C_null(T_opaque_box_ptr(bcx.ccx())); - vec::push(llargvals, llenvptr); + llargvals.push(llenvptr); while i < n { let llargval = load_inbounds(bcx, llargbundle, ~[0u, i]); - vec::push(llargvals, llargval); + llargvals.push(llargval); i += 1u; } return llargvals; diff --git a/src/rustc/middle/trans/monomorphize.rs b/src/rustc/middle/trans/monomorphize.rs index 8a68ef4823b..40558e72c80 100644 --- a/src/rustc/middle/trans/monomorphize.rs +++ b/src/rustc/middle/trans/monomorphize.rs @@ -246,7 +246,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], for vec::each(*bounds) |bound| { match *bound { ty::bound_trait(_) => { - vec::push(v, meth::vtable_id(ccx, vts[i])); + v.push(meth::vtable_id(ccx, vts[i])); i += 1u; } _ => () diff --git a/src/rustc/middle/trans/tvec.rs b/src/rustc/middle/trans/tvec.rs index 10f93626280..e1eae115694 100644 --- a/src/rustc/middle/trans/tvec.rs +++ b/src/rustc/middle/trans/tvec.rs @@ -332,7 +332,7 @@ fn write_content(bcx: block, bcx = expr::trans_into(bcx, *element, SaveIn(lleltptr)); add_clean_temp_mem(bcx, lleltptr, vt.unit_ty); - vec::push(temp_cleanups, lleltptr); + temp_cleanups.push(lleltptr); } for vec::each(temp_cleanups) |cleanup| { revoke_clean(bcx, *cleanup); @@ -369,7 +369,7 @@ fn write_content(bcx: block, bcx = tmpdatum.move_to(bcx, INIT, lleltptr); } add_clean_temp_mem(bcx, lleltptr, vt.unit_ty); - vec::push(temp_cleanups, lleltptr); + temp_cleanups.push(lleltptr); } for vec::each(temp_cleanups) |cleanup| { diff --git a/src/rustc/middle/trans/type_of.rs b/src/rustc/middle/trans/type_of.rs index d9032f8ce90..99555d5b294 100644 --- a/src/rustc/middle/trans/type_of.rs +++ b/src/rustc/middle/trans/type_of.rs @@ -39,13 +39,13 @@ fn type_of_fn(cx: @crate_ctxt, inputs: ~[ty::arg], let mut atys: ~[TypeRef] = ~[]; // Arg 0: Output pointer. - vec::push(atys, T_ptr(type_of(cx, output))); + atys.push(T_ptr(type_of(cx, output))); // Arg 1: Environment - vec::push(atys, T_opaque_box_ptr(cx)); + atys.push(T_opaque_box_ptr(cx)); // ... then explicit args. - vec::push_all(atys, type_of_explicit_args(cx, inputs)); + atys.push_all(type_of_explicit_args(cx, inputs)); return T_fn(atys, llvm::LLVMVoidType()); } @@ -151,7 +151,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { let mut tys: ~[TypeRef] = ~[]; for vec::each(fields) |f| { let mt_ty = f.mt.ty; - vec::push(tys, type_of(cx, mt_ty)); + tys.push(type_of(cx, mt_ty)); } // n.b.: introduce an extra layer of indirection to match @@ -164,7 +164,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef { ty::ty_tup(elts) => { let mut tys = ~[]; for vec::each(elts) |elt| { - vec::push(tys, type_of(cx, *elt)); + tys.push(type_of(cx, *elt)); } T_struct(tys) } diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index f256b4b76cd..ed71d27451c 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -2243,10 +2243,10 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { } ty_class(did, ref substs) => { - vec::push(*seen, did); - let r = vec::any(class_items_as_fields(cx, did, substs), - |f| type_requires(cx, seen, r_ty, f.mt.ty)); - vec::pop(*seen); + seen.push(did); + let r = vec::any(class_items_as_fields(cx, did, substs), + |f| type_requires(cx, seen, r_ty, f.mt.ty)); + vec::pop(*seen); r } @@ -2258,18 +2258,18 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { false } - ty_enum(did, ref substs) => { - vec::push(*seen, did); - let vs = enum_variants(cx, did); - let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| { - vec::any(variant.args, |aty| { - let sty = subst(cx, substs, aty); - type_requires(cx, seen, r_ty, sty) - }) - }); - vec::pop(*seen); - r - } + ty_enum(did, ref substs) => { + seen.push(did); + let vs = enum_variants(cx, did); + let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| { + vec::any(variant.args, |aty| { + let sty = subst(cx, substs, aty); + type_requires(cx, seen, r_ty, sty) + }) + }); + vec::pop(*seen); + r + } }; debug!("subtypes_require(%s, %s)? %b", @@ -3036,7 +3036,7 @@ fn param_tys_in_type(ty: t) -> ~[param_ty] { do walk_ty(ty) |ty| { match get(ty).sty { ty_param(p) => { - vec::push(rslt, p); + rslt.push(p); } _ => () } @@ -3052,7 +3052,7 @@ fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { let mut rslt = ~[]; do walk_ty(ty) |ty| { match get(ty).sty { - ty_infer(TyVar(v)) => vec::push(rslt, v), + ty_infer(TyVar(v)) => rslt.push(v), _ => () } } @@ -3704,10 +3704,10 @@ fn class_field_tys(fields: ~[@struct_field]) -> ~[field_ty] { for fields.each |field| { match field.node.kind { named_field(ident, mutability, visibility) => { - vec::push(rslt, {ident: ident, - id: ast_util::local_def(field.node.id), - vis: visibility, - mutability: mutability}); + rslt.push({ident: ident, + id: ast_util::local_def(field.node.id), + vis: visibility, + mutability: mutability}); } unnamed_field => {} } @@ -3747,7 +3747,7 @@ fn class_item_fields(cx:ctxt, for lookup_class_fields(cx, did).each |f| { // consider all instance vars mut, because the // constructor may mutate all vars - vec::push(rslt, {ident: f.ident, mt: + rslt.push({ident: f.ident, mt: {ty: lookup_field_type(cx, did, f.id, substs), mutbl: frob_mutability(f.mutability)}}); } diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 8d2384cd530..bc7711c059b 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -818,7 +818,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) { if vec::contains(enum_dids, did) { return (t1, autoderefs); } - vec::push(enum_dids, did); + enum_dids.push(did); } _ => { /*ok*/ } } @@ -2029,8 +2029,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let name = class_field.ident; let (_, seen) = class_field_map.get(name); if !seen { - vec::push(missing_fields, - ~"`" + tcx.sess.str_of(name) + ~"`"); + missing_fields.push( + ~"`" + tcx.sess.str_of(name) + ~"`"); } } @@ -2298,7 +2298,7 @@ fn check_enum_variants(ccx: @crate_ctxt, ccx.tcx.sess.span_err(v.span, ~"discriminator value already exists"); } - vec::push(*disr_vals, *disr_val); + disr_vals.push(*disr_val); let ctor_ty = ty::node_id_to_type(ccx.tcx, v.node.id); let arg_tys; @@ -2321,7 +2321,8 @@ fn check_enum_variants(ccx: @crate_ctxt, match arg_tys { None => {} Some(arg_tys) => { - vec::push(*variants, @{args: arg_tys, ctor_ty: ctor_ty, + variants.push( + @{args: arg_tys, ctor_ty: ctor_ty, name: v.node.name, id: local_def(v.node.id), disr_val: this_disr_val}); } diff --git a/src/rustc/middle/typeck/check/regionmanip.rs b/src/rustc/middle/typeck/check/regionmanip.rs index d969ce908f0..aec42f77048 100644 --- a/src/rustc/middle/typeck/check/regionmanip.rs +++ b/src/rustc/middle/typeck/check/regionmanip.rs @@ -27,13 +27,13 @@ fn replace_bound_regions_in_fn_ty( let region = ty::re_bound(ty::br_self); let ty = ty::mk_rptr(tcx, region, { ty: ty::mk_self(tcx), mutbl: m }); - vec::push(all_tys, ty); + all_tys.push(ty); } _ => {} } - for self_ty.each |t| { vec::push(all_tys, *t) } + for self_ty.each |t| { all_tys.push(*t) } debug!("replace_bound_regions_in_fn_ty(self_info.self_ty=%?, fn_ty=%s, \ all_tys=%?)", diff --git a/src/rustc/middle/typeck/check/vtable.rs b/src/rustc/middle/typeck/check/vtable.rs index d48f5b9c070..453559e5e42 100644 --- a/src/rustc/middle/typeck/check/vtable.rs +++ b/src/rustc/middle/typeck/check/vtable.rs @@ -51,8 +51,8 @@ fn lookup_vtables(fcx: @fn_ctxt, match *bound { ty::bound_trait(i_ty) => { let i_ty = ty::subst(tcx, substs, i_ty); - vec::push(result, lookup_vtable(fcx, expr, *ty, i_ty, - allow_unsafe, is_early)); + result.push(lookup_vtable(fcx, expr, *ty, i_ty, + allow_unsafe, is_early)); } _ => () } @@ -331,9 +331,9 @@ fn lookup_vtable(fcx: @fn_ctxt, // the impl as well as the resolved list // of type substitutions for the target // trait. - vec::push(found, - vtable_static(im.did, substs_f.tps, - subres)); + found.push( + vtable_static(im.did, substs_f.tps, + subres)); } } } diff --git a/src/rustc/middle/typeck/check/writeback.rs b/src/rustc/middle/typeck/check/writeback.rs index a70e5f600d3..33a26c8daf4 100644 --- a/src/rustc/middle/typeck/check/writeback.rs +++ b/src/rustc/middle/typeck/check/writeback.rs @@ -94,7 +94,7 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id) let mut new_tps = ~[]; for substs.tps.each |subst| { match resolve_type_vars_in_type(fcx, sp, *subst) { - Some(t) => vec::push(new_tps, t), + Some(t) => new_tps.push(t), None => { wbcx.success = false; return None; } } } diff --git a/src/rustc/middle/typeck/coherence.rs b/src/rustc/middle/typeck/coherence.rs index 77c665755c3..907cdb4f5ec 100644 --- a/src/rustc/middle/typeck/coherence.rs +++ b/src/rustc/middle/typeck/coherence.rs @@ -198,7 +198,7 @@ impl CoherenceChecker { existing trait", sess.str_of(mi.ident)); let mut method_infos = mis; - push(method_infos, mi); + method_infos.push(mi); pmm.insert(item.id, method_infos); } None => { @@ -547,7 +547,7 @@ impl CoherenceChecker { debug!( "(creating impl) adding provided method `%s` to impl", sess.str_of(provided_method.ident)); - push(methods, *provided_method); + methods.push(*provided_method); } } @@ -559,8 +559,7 @@ impl CoherenceChecker { let mut methods = ~[]; for ast_methods.each |ast_method| { - push(methods, - method_to_MethodInfo(*ast_method)); + methods.push(method_to_MethodInfo(*ast_method)); } // For each trait that the impl implements, see what @@ -619,7 +618,7 @@ impl CoherenceChecker { -> @Impl { let mut methods = ~[]; for struct_def.methods.each |ast_method| { - push(methods, @{ + methods.push(@{ did: local_def(ast_method.id), n_tps: ast_method.tps.len(), ident: ast_method.ident, diff --git a/src/rustc/middle/typeck/infer/region_var_bindings.rs b/src/rustc/middle/typeck/infer/region_var_bindings.rs index c0312872488..8eabb2c0787 100644 --- a/src/rustc/middle/typeck/infer/region_var_bindings.rs +++ b/src/rustc/middle/typeck/infer/region_var_bindings.rs @@ -830,7 +830,7 @@ impl RegionVarBindings { // It would be nice to write this using map(): let mut edges = vec::with_capacity(num_edges); for self.constraints.each_ref |constraint, span| { - vec::push(edges, GraphEdge { + edges.push(GraphEdge { next_edge: [mut uint::max_value, uint::max_value], constraint: *constraint, span: *span @@ -1201,13 +1201,13 @@ impl RegionVarBindings { Outgoing => to_vid }; if set.insert(*vid, ()) { - vec::push(stack, vid); + stack.push(vid); } } ConstrainRegSubVar(region, _) => { assert dir == Incoming; - vec::push(result, SpannedRegion { + result.push(SpannedRegion { region: region, span: edge.span }); @@ -1215,7 +1215,7 @@ impl RegionVarBindings { ConstrainVarSubReg(_, region) => { assert dir == Outgoing; - vec::push(result, SpannedRegion { + result.push(SpannedRegion { region: region, span: edge.span }); diff --git a/src/rustc/middle/typeck/infer/resolve.rs b/src/rustc/middle/typeck/infer/resolve.rs index 5d748efc332..a366a2ef1c7 100644 --- a/src/rustc/middle/typeck/infer/resolve.rs +++ b/src/rustc/middle/typeck/infer/resolve.rs @@ -174,7 +174,7 @@ impl resolve_state { self.err = Some(cyclic_ty(vid)); return ty::mk_var(self.infcx.tcx, vid); } else { - vec::push(self.v_seen, vid); + self.v_seen.push(vid); let tcx = self.infcx.tcx; // Nonobvious: prefer the most specific type diff --git a/src/rustc/middle/typeck/infer/unify.rs b/src/rustc/middle/typeck/infer/unify.rs index 500a4d5b419..7ccbaa40ada 100644 --- a/src/rustc/middle/typeck/infer/unify.rs +++ b/src/rustc/middle/typeck/infer/unify.rs @@ -51,7 +51,7 @@ impl infer_ctxt { +new_v: var_value) { let old_v = vb.vals.get(vid.to_uint()); - vec::push(vb.bindings, (vid, old_v)); + vb.bindings.push((vid, old_v)); vb.vals.insert(vid.to_uint(), new_v); debug!("Updating variable %s from %s to %s", diff --git a/src/rustc/util/common.rs b/src/rustc/util/common.rs index 4c033515b9a..37cc016e8ea 100644 --- a/src/rustc/util/common.rs +++ b/src/rustc/util/common.rs @@ -36,7 +36,7 @@ fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; } fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] { let mut es = ~[]; - for fields.each |f| { vec::push(es, f.node.expr); } + for fields.each |f| { es.push(f.node.expr); } return es; } diff --git a/src/rustc/util/ppaux.rs b/src/rustc/util/ppaux.rs index 0498a0f9541..0df5827ed3d 100644 --- a/src/rustc/util/ppaux.rs +++ b/src/rustc/util/ppaux.rs @@ -286,7 +286,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { } s += ~"("; let mut strs = ~[]; - for inputs.each |a| { vec::push(strs, fn_input_to_str(cx, *a)); } + for inputs.each |a| { strs.push(fn_input_to_str(cx, *a)); } s += str::connect(strs, ~", "); s += ~")"; if ty::get(output).sty != ty_nil { @@ -342,12 +342,12 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str { ty_type => ~"type", ty_rec(elems) => { let mut strs: ~[~str] = ~[]; - for elems.each |fld| { vec::push(strs, field_to_str(cx, *fld)); } + for elems.each |fld| { strs.push(field_to_str(cx, *fld)); } ~"{" + str::connect(strs, ~",") + ~"}" } ty_tup(elems) => { let mut strs = ~[]; - for elems.each |elem| { vec::push(strs, ty_to_str(cx, *elem)); } + for elems.each |elem| { strs.push(ty_to_str(cx, *elem)); } ~"(" + str::connect(strs, ~",") + ~")" } ty_fn(ref f) => { diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index 448e699fc8d..7b34a327bee 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -140,7 +140,7 @@ fn nmoddoc_from_mod( let ItemDoc = mk_itemdoc(item.id, to_str(item.ident)); match item.node { ast::foreign_item_fn(*) => { - vec::push(fns, fndoc_from_fn(ItemDoc)); + fns.push(fndoc_from_fn(ItemDoc)); } ast::foreign_item_const(*) => {} // XXX: Not implemented. } diff --git a/src/rustdoc/path_pass.rs b/src/rustdoc/path_pass.rs index 84b542f6bf0..96ed269a7e9 100644 --- a/src/rustdoc/path_pass.rs +++ b/src/rustdoc/path_pass.rs @@ -43,7 +43,7 @@ fn fold_item(fold: fold::Fold, doc: doc::ItemDoc) -> doc::ItemDoc { fn fold_mod(fold: fold::Fold, doc: doc::ModDoc) -> doc::ModDoc { let is_topmod = doc.id() == ast::crate_node_id; - if !is_topmod { vec::push(fold.ctxt.path, doc.name()); } + if !is_topmod { fold.ctxt.path.push(doc.name()); } let doc = fold::default_any_fold_mod(fold, doc); if !is_topmod { vec::pop(fold.ctxt.path); } @@ -54,7 +54,7 @@ fn fold_mod(fold: fold::Fold, doc: doc::ModDoc) -> doc::ModDoc { } fn fold_nmod(fold: fold::Fold, doc: doc::NmodDoc) -> doc::NmodDoc { - vec::push(fold.ctxt.path, doc.name()); + fold.ctxt.path.push(doc.name()); let doc = fold::default_seq_fold_nmod(fold, doc); vec::pop(fold.ctxt.path); diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index a7312cc8320..9454ef7aec7 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -47,7 +47,7 @@ fn shift_push() { let mut v2 = ~[]; while v1.len() > 0 { - vec::push(v2, vec::shift(v1)); + v2.push(vec::shift(v1)); } } @@ -122,11 +122,11 @@ fn vec_push_all() { for uint::range(0, 1500) |i| { let mut rv = vec::from_elem(r.gen_uint_range(0, i + 1), i); if r.gen_bool() { - vec::push_all(v, rv); + v.push_all(rv); } else { v <-> rv; - vec::push_all(v, rv); + v.push_all(rv); } } } diff --git a/src/test/bench/core-vec-append.rs b/src/test/bench/core-vec-append.rs index d708ac9eaa7..2b9216876b4 100644 --- a/src/test/bench/core-vec-append.rs +++ b/src/test/bench/core-vec-append.rs @@ -7,7 +7,7 @@ use io::WriterUtil; fn collect_raw(num: uint) -> ~[uint] { let mut result = ~[]; for uint::range(0u, num) |i| { - vec::push(result, i); + result.push(i); } return result; } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 61d556b4613..ef2fa8dfa9e 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -318,7 +318,7 @@ fn validate(edges: ~[(node_id, node_id)], status = false; } - vec::push(path, parent); + path.push(parent); parent = tree[parent]; } diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 89d339b7a76..392f67d6714 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -60,7 +60,7 @@ fn run(args: &[~str]) { for uint::range(0u, workers) |i| { let to_child = to_child.clone(); do task::task().future_result(|+r| { - vec::push(worker_results, r); + worker_results.push(r); }).spawn { for uint::range(0u, size / workers) |_i| { //error!("worker %?: sending %? bytes", i, num_bytes); diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index babc97694a5..6ba8b71d8c4 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -57,7 +57,7 @@ fn run(args: &[~str]) { let (to_child, from_parent_) = pipes::stream(); from_parent.add(from_parent_); do task::task().future_result(|+r| { - vec::push(worker_results, r); + worker_results.push(r); }).spawn { for uint::range(0u, size / workers) |_i| { //error!("worker %?: sending %? bytes", i, num_bytes); diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index e3d8afce1bf..2931cab248f 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -18,7 +18,7 @@ type pipe = arc::MutexARC<~[uint]>; fn send(p: &pipe, msg: uint) { do p.access_cond |state, cond| { - vec::push(*state, msg); + state.push(msg); cond.signal(); } } @@ -91,7 +91,7 @@ fn main(++args: ~[~str]) { option::unwrap(num_chan), option::unwrap(num_port1)) }); - vec::push(futures, new_future); + futures.push(new_future); num_chan = Some(new_chan); }; diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 645aa654700..3c888fd0c8d 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -88,7 +88,7 @@ fn main(++args: ~[~str]) { option::unwrap(num_chan), option::unwrap(num_port1)) }; - vec::push(futures, new_future); + futures.push(new_future); num_chan = Some(new_chan); }; diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index b4b75adc3b5..525cf8f1c50 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -18,7 +18,7 @@ type pipe = arc::RWARC<~[uint]>; fn send(p: &pipe, msg: uint) { do p.write_cond |state, cond| { - vec::push(*state, msg); + state.push(msg); cond.signal(); } } @@ -92,7 +92,7 @@ fn main(++args: ~[~str]) { option::unwrap(num_chan), option::unwrap(num_port1)) }; - vec::push(futures, new_future); + futures.push(new_future); num_chan = Some(new_chan); }; diff --git a/src/test/bench/msgsend-ring.rs b/src/test/bench/msgsend-ring.rs index 47ce0d2b91f..5533aeeeb41 100644 --- a/src/test/bench/msgsend-ring.rs +++ b/src/test/bench/msgsend-ring.rs @@ -51,7 +51,7 @@ fn main(++args: ~[~str]) { get_chan_chan.send(Chan(p)); thread_ring(i, msg_per_task, num_chan, p) }; - vec::push(futures, new_future); + futures.push(new_future); num_chan = get_chan.recv(); }; diff --git a/src/test/bench/msgsend.rs b/src/test/bench/msgsend.rs index 2790f00d40d..fb1e3ae9226 100644 --- a/src/test/bench/msgsend.rs +++ b/src/test/bench/msgsend.rs @@ -37,7 +37,7 @@ fn run(args: ~[~str]) { let mut worker_results = ~[]; for uint::range(0u, workers) |_i| { do task::task().future_result(|+r| { - vec::push(worker_results, r); + worker_results.push(r); }).spawn { for uint::range(0u, size / workers) |_i| { comm::send(to_child, bytes(100u)); diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index bdfe4b7b727..5c7827f5106 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -163,7 +163,7 @@ fn rendezvous(nn: uint, set: ~[color]) { // save each creature's meeting stats let mut report = ~[]; for vec::each(to_creature) |_to_one| { - vec::push(report, comm::recv(from_creatures_log)); + report.push(comm::recv(from_creatures_log)); } // print each color in the set diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index b5dcacd76d3..4f821a534ab 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -41,7 +41,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str { // map -> [(k,%)] mm.each(fn&(key: ~[u8], val: uint) -> bool { - vec::push(pairs, (key, pct(val, total))); + pairs.push((key, pct(val, total))); return true; }); @@ -152,7 +152,7 @@ fn main(++args: ~[~str]) { stream <-> streams[ii]; let (to_parent_, from_child_) = option::unwrap(stream); - vec::push(from_child, from_child_); + from_child.push(from_child_); let (to_child, from_parent) = pipes::stream(); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 5f7036ed82a..3b00fd99a55 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -38,7 +38,7 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str { // map -> [(k,%)] mm.each(fn&(key: ~[u8], val: uint) -> bool { - vec::push(pairs, (key, pct(val, total))); + pairs.push((key, pct(val, total))); return true; }); diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 0cf0f0da5e5..d9859d54648 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -85,7 +85,7 @@ fn chanmb(i: uint, size: uint, ch: comm::Chan) -> () let xincr = 8f64*incr; for uint::range(0_u, size/8_u) |j| { let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y}; - vec::push(crv, fillbyte(x, incr)); + crv.push(fillbyte(x, incr)); }; comm::send(ch, {i:i, b:crv}); } diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 705679bd403..90224645f84 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -73,7 +73,7 @@ fn stress(num_tasks: int) { let mut results = ~[]; for range(0, num_tasks) |i| { do task::task().future_result(|+r| { - vec::push(results, r); + results.push(r); }).spawn { stress_task(i); } diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index da8b1932f65..c9d4fb6b4d8 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -21,7 +21,7 @@ fn calc(children: uint, parent_ch: comm::Chan) { for iter::repeat (children) { match comm::recv(port) { ready(child_ch) => { - vec::push(child_chs, child_ch); + child_chs.push(child_ch); } _ => fail ~"task-perf-one-million failed (port not ready)" } diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index 73c5dab16d8..efb795a76af 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -155,8 +155,8 @@ mod map_reduce { let (ctrl, ctrl_server) = ctrl_proto::init(); let ctrl = box(ctrl); let i = copy *i; - vec::push(tasks, spawn_joinable(|move i| map_task(map, ctrl, i))); - vec::push(ctrls, ctrl_server); + tasks.push(spawn_joinable(|move i| map_task(map, ctrl, i))); + ctrls.push(ctrl_server); } return tasks; } @@ -270,8 +270,7 @@ mod map_reduce { let p = Port(); let ch = Chan(p); let r = reduce, kk = k; - vec::push(tasks, - spawn_joinable(|| reduce_task(r, kk, ch) )); + tasks.push(spawn_joinable(|| reduce_task(r, kk, ch) )); c = recv(p); reducers.insert(k, c); } diff --git a/src/test/compile-fail/purity-infer-fail.rs b/src/test/compile-fail/purity-infer-fail.rs index 691829edf59..b7666fa8650 100644 --- a/src/test/compile-fail/purity-infer-fail.rs +++ b/src/test/compile-fail/purity-infer-fail.rs @@ -2,5 +2,5 @@ fn something(f: pure fn()) { f(); } fn main() { let mut x = ~[]; - something(|| vec::push(x, 0) ); //~ ERROR access to impure function prohibited in pure context + something(|| x.push(0) ); //~ ERROR access to impure function prohibited in pure context } diff --git a/src/test/run-fail/zip-different-lengths.rs b/src/test/run-fail/zip-different-lengths.rs index 4e97d2f903f..c6239c1f657 100644 --- a/src/test/run-fail/zip-different-lengths.rs +++ b/src/test/run-fail/zip-different-lengths.rs @@ -8,7 +8,7 @@ fn enum_chars(start: u8, end: u8) -> ~[char] { assert start < end; let mut i = start; let mut r = ~[]; - while i <= end { vec::push(r, i as char); i += 1u as u8; } + while i <= end { r.push(i as char); i += 1u as u8; } return r; } @@ -16,7 +16,7 @@ fn enum_uints(start: uint, end: uint) -> ~[uint] { assert start < end; let mut i = start; let mut r = ~[]; - while i <= end { vec::push(r, i); i += 1u; } + while i <= end { r.push(i); i += 1u; } return r; } diff --git a/src/test/run-pass/auto-ref-sliceable.rs b/src/test/run-pass/auto-ref-sliceable.rs index 43d9fa5b14b..48d83da74ad 100644 --- a/src/test/run-pass/auto-ref-sliceable.rs +++ b/src/test/run-pass/auto-ref-sliceable.rs @@ -4,7 +4,7 @@ trait Pushable { impl ~[T]: Pushable { fn push_val(&mut self, +t: T) { - vec::push(*self, t); + self.push(t); } } diff --git a/src/test/run-pass/autoref-vec-push.rs b/src/test/run-pass/autoref-vec-push.rs deleted file mode 100644 index cb70a1810b7..00000000000 --- a/src/test/run-pass/autoref-vec-push.rs +++ /dev/null @@ -1,17 +0,0 @@ -trait VecPush { - fn push(&mut self, +t: T); -} - -impl ~[T]: VecPush { - fn push(&mut self, +t: T) { - vec::push(*self, t); - } -} - -fn main() { - let mut x = ~[]; - x.push(1); - x.push(2); - x.push(3); - assert x == ~[1, 2, 3]; -} \ No newline at end of file diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs index 6db380735cb..2d1833c0736 100644 --- a/src/test/run-pass/borrowck-mut-uniq.rs +++ b/src/test/run-pass/borrowck-mut-uniq.rs @@ -4,7 +4,7 @@ fn add_int(x: &mut ints, v: int) { *x.sum += v; let mut values = ~[]; x.values <-> values; - vec::push(values, v); + values.push(v); x.values <- values; } diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 3eb6561eb96..fc637429cd0 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -52,10 +52,15 @@ fn read_board_grid(+in: rdr) -> ~[~[square]] { let mut grid = ~[]; for in.each_line |line| { let mut row = ~[]; +<<<<<<< HEAD for str::each_char(line) |c| { vec::push(row, square_from_char(c)) +======= + for line.each_char |c| { + row.push(square_from_char(c)) +>>>>>>> Demode vec::push (and convert to method) } - vec::push(grid, row) + grid.push(row) } let width = grid[0].len(); for grid.each |row| { assert row.len() == width } diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index dd2dd5e54d4..4faac4fdac1 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -34,7 +34,7 @@ fn test00() { while i < number_of_tasks { let ch = po.chan(); do task::task().future_result(|+r| { - vec::push(results, r); + results.push(r); }).spawn |copy i| { test00_start(ch, i, number_of_messages) } diff --git a/src/test/run-pass/task-comm.rs b/src/test/run-pass/task-comm.rs index a3a6b6efd7f..8d144b1a399 100644 --- a/src/test/run-pass/task-comm.rs +++ b/src/test/run-pass/task-comm.rs @@ -40,7 +40,7 @@ fn test00() { while i < number_of_tasks { i = i + 1; do task::task().future_result(|+r| { - vec::push(results, r); + results.push(r); }).spawn |copy i| { test00_start(ch, i, number_of_messages); } @@ -127,7 +127,7 @@ fn test06() { while i < number_of_tasks { i = i + 1; do task::task().future_result(|+r| { - vec::push(results, r); + results.push(r); }).spawn |copy i| { test06_start(i); }; diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index 3e47f7e0a3b..d4190d41386 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -1 +1 @@ -fn main() { let mut v = ~[1, 2, 3]; vec::push(v, 1); } +fn main() { let mut v = ~[1, 2, 3]; v.push(1); } diff --git a/src/test/run-pass/zip-same-length.rs b/src/test/run-pass/zip-same-length.rs index 61e359129fe..9b8304792fa 100644 --- a/src/test/run-pass/zip-same-length.rs +++ b/src/test/run-pass/zip-same-length.rs @@ -7,7 +7,7 @@ fn enum_chars(start: u8, end: u8) -> ~[char] { assert start < end; let mut i = start; let mut r = ~[]; - while i <= end { vec::push(r, i as char); i += 1u as u8; } + while i <= end { r.push(i as char); i += 1u as u8; } return r; } @@ -15,7 +15,7 @@ fn enum_uints(start: uint, end: uint) -> ~[uint] { assert start < end; let mut i = start; let mut r = ~[]; - while i <= end { vec::push(r, i); i += 1u; } + while i <= end { r.push(i); i += 1u; } return r; } -- cgit 1.4.1-3-g733a5 From dd80cb22e3591267882136d8d5529dc92f049952 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 26 Sep 2012 18:10:24 -0700 Subject: Fix test/run-fail/issue-2156 --- src/test/run-fail/issue-2156.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/run-fail/issue-2156.rs b/src/test/run-fail/issue-2156.rs index 6b39e323c6e..57d33c965b0 100644 --- a/src/test/run-fail/issue-2156.rs +++ b/src/test/run-fail/issue-2156.rs @@ -1,7 +1,7 @@ // error-pattern:explicit failure // Don't double free the string extern mod std; -use io::Reader; +use io::ReaderUtil; fn main() { do io::with_str_reader(~"") |rdr| { -- cgit 1.4.1-3-g733a5 From 87a72567f05cdae035007e761f7bd08f049af216 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 26 Sep 2012 18:41:02 -0700 Subject: Unbreak run-pass/issue-2904 more --- src/test/run-pass/issue-2904.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/test') diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index fc637429cd0..6d771dc7386 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -52,13 +52,8 @@ fn read_board_grid(+in: rdr) -> ~[~[square]] { let mut grid = ~[]; for in.each_line |line| { let mut row = ~[]; -<<<<<<< HEAD for str::each_char(line) |c| { - vec::push(row, square_from_char(c)) -======= - for line.each_char |c| { row.push(square_from_char(c)) ->>>>>>> Demode vec::push (and convert to method) } grid.push(row) } -- cgit 1.4.1-3-g733a5 From 010f805a7b88733c1215bcd62f854363c748c71d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 26 Sep 2012 19:30:09 -0700 Subject: Unbreak test/bench/task-perf-word-count-generic --- src/test/bench/task-perf-word-count-generic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index efb795a76af..3add41792f3 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -20,7 +20,7 @@ use option::None; use std::map; use std::map::HashMap; use hash::Hash; -use io::WriterUtil; +use io::{ReaderUtil, WriterUtil}; use std::time; -- cgit 1.4.1-3-g733a5 From 7e7411e6209b10d99bc37c084c8ac45fbb706431 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 27 Sep 2012 11:14:59 -0700 Subject: Demode rand --- src/libcore/rand.rs | 20 ++++++++++++-------- src/test/bench/core-map.rs | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/test') diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index d68bd97ae5d..c04c46d02e5 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -1,5 +1,9 @@ //! Random number generation +// NB: transitional, de-mode-ing. +#[warn(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + #[allow(non_camel_case_types)] // runtime type enum rctx {} @@ -120,7 +124,7 @@ impl Rng { /** * Return a char randomly chosen from chars, failing if chars is empty */ - fn gen_char_from(chars: ~str) -> char { + fn gen_char_from(chars: &str) -> char { assert !chars.is_empty(); self.choose(str::chars(chars)) } @@ -272,8 +276,8 @@ pub fn Rng() -> Rng { * all other generators constructed with the same seed. The seed may be any * length. */ -pub fn seeded_rng(seed: ~[u8]) -> Rng { - @RandRes(rustrt::rand_new_seeded(seed)) as Rng +pub fn seeded_rng(seed: &~[u8]) -> Rng { + @RandRes(rustrt::rand_new_seeded(*seed)) as Rng } type XorShiftState = { @@ -310,8 +314,8 @@ pub mod tests { #[test] pub fn rng_seeded() { let seed = rand::seed(); - let ra = rand::seeded_rng(seed); - let rb = rand::seeded_rng(seed); + let ra = rand::seeded_rng(&seed); + let rb = rand::seeded_rng(&seed); assert ra.gen_str(100u) == rb.gen_str(100u); } @@ -319,15 +323,15 @@ pub mod tests { pub fn rng_seeded_custom_seed() { // much shorter than generated seeds which are 1024 bytes let seed = ~[2u8, 32u8, 4u8, 32u8, 51u8]; - let ra = rand::seeded_rng(seed); - let rb = rand::seeded_rng(seed); + let ra = rand::seeded_rng(&seed); + let rb = rand::seeded_rng(&seed); assert ra.gen_str(100u) == rb.gen_str(100u); } #[test] pub fn rng_seeded_custom_seed2() { let seed = ~[2u8, 32u8, 4u8, 32u8, 51u8]; - let ra = rand::seeded_rng(seed); + let ra = rand::seeded_rng(&seed); // Regression test that isaac is actually using the above vector let r = ra.next(); error!("%?", r); diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 279905fe3f1..afd9b2ccc9c 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -154,7 +154,7 @@ fn main(++args: ~[~str]) { let seed = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; { - let rng = rand::seeded_rng(copy seed); + let rng = rand::seeded_rng(&seed); let mut results = empty_results(); int_benchmarks::>( map::HashMap, rng, num_keys, &mut results); @@ -164,7 +164,7 @@ fn main(++args: ~[~str]) { } { - let rng = rand::seeded_rng(copy seed); + let rng = rand::seeded_rng(&seed); let mut results = empty_results(); int_benchmarks::<@Mut>>( || @Mut(LinearMap()), -- cgit 1.4.1-3-g733a5 From 7b0ed94bdc6f42f0abed2ee2e293e3800725eaeb Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 27 Sep 2012 17:42:25 -0700 Subject: rustc: Make enum export visibility inherit properly --- src/rustc/middle/resolve.rs | 15 ++++++++++----- src/test/run-pass/enum-export-inheritance.rs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/test/run-pass/enum-export-inheritance.rs (limited to 'src/test') diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 99d98c52f95..def21ae03e0 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -1063,6 +1063,7 @@ impl Resolver { for enum_definition.variants.each |variant| { self.build_reduced_graph_for_variant(*variant, local_def(item.id), + privacy, new_parent, visitor); } @@ -1156,17 +1157,20 @@ impl Resolver { // type and/or value namespaces. fn build_reduced_graph_for_variant(variant: variant, item_id: def_id, + +parent_privacy: Privacy, parent: ReducedGraphParent, &&visitor: vt) { - let legacy = match parent { - ModuleReducedGraphParent(m) => m.legacy_exports - }; - let ident = variant.node.name; let (child, _) = self.add_child(ident, parent, ~[ValueNS], variant.span); - let privacy = self.visibility_to_privacy(variant.node.vis, legacy); + + let privacy; + match variant.node.vis { + public => privacy = Public, + private => privacy = Private, + inherited => privacy = parent_privacy + } match variant.node.kind { tuple_variant_kind(_) => { @@ -1188,6 +1192,7 @@ impl Resolver { variant.span); for enum_definition.variants.each |variant| { self.build_reduced_graph_for_variant(*variant, item_id, + parent_privacy, parent, visitor); } } diff --git a/src/test/run-pass/enum-export-inheritance.rs b/src/test/run-pass/enum-export-inheritance.rs new file mode 100644 index 00000000000..1fddddba331 --- /dev/null +++ b/src/test/run-pass/enum-export-inheritance.rs @@ -0,0 +1,12 @@ +mod a { + pub enum Foo { + Bar, + Baz, + Boo + } +} + +fn main() { + let x = a::Bar; +} + -- cgit 1.4.1-3-g733a5 From 21519bc7e0a32e388e8b12be5d36d4440129f417 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 27 Sep 2012 22:20:47 -0700 Subject: demode vec --- src/cargo/cargo.rs | 2 +- src/compiletest/runtest.rs | 5 +- src/fuzzer/fuzzer.rs | 2 +- src/libcore/dlist.rs | 2 +- src/libcore/dvec.rs | 8 +- src/libcore/float.rs | 2 +- src/libcore/io.rs | 6 +- src/libcore/os.rs | 6 +- src/libcore/path.rs | 6 +- src/libcore/pipes.rs | 4 +- src/libcore/ptr.rs | 6 +- src/libcore/str.rs | 8 +- src/libcore/tuple.rs | 43 +- src/libcore/vec.rs | 530 ++++++++++++--------- src/libstd/ebml.rs | 2 +- src/libstd/ebml2.rs | 2 +- src/libstd/getopts.rs | 5 +- src/libstd/json.rs | 2 +- src/libstd/list.rs | 2 +- src/libstd/net_ip.rs | 2 +- src/libstd/net_tcp.rs | 2 +- src/libstd/par.rs | 8 +- src/libstd/smallintmap.rs | 2 +- src/libstd/test.rs | 4 +- src/libsyntax/ast_map.rs | 2 +- src/libsyntax/ast_util.rs | 4 +- src/libsyntax/attr.rs | 16 +- src/libsyntax/ext/auto_serialize.rs | 10 +- src/libsyntax/ext/auto_serialize2.rs | 12 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/ext/pipes/pipec.rs | 4 +- src/libsyntax/ext/simplext.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 6 +- src/libsyntax/ext/tt/transcribe.rs | 11 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- src/rustc/driver/rustc.rs | 2 +- src/rustc/front/config.rs | 23 +- src/rustc/front/test.rs | 8 +- src/rustc/metadata/cstore.rs | 4 +- src/rustc/metadata/decoder.rs | 2 +- src/rustc/middle/borrowck/check_loans.rs | 2 +- src/rustc/middle/borrowck/gather_loans.rs | 4 +- src/rustc/middle/check_alt.rs | 8 +- src/rustc/middle/const_eval.rs | 4 +- src/rustc/middle/kind.rs | 4 +- src/rustc/middle/liveness.rs | 8 +- src/rustc/middle/resolve.rs | 2 +- src/rustc/middle/trans/alt.rs | 2 +- src/rustc/middle/trans/base.rs | 2 +- src/rustc/middle/trans/common.rs | 2 +- src/rustc/middle/trans/controlflow.rs | 2 +- src/rustc/middle/trans/foreign.rs | 4 +- src/rustc/middle/trans/monomorphize.rs | 12 +- src/rustc/middle/trans/type_use.rs | 4 +- src/rustc/middle/ty.rs | 14 +- src/rustc/middle/typeck/check.rs | 10 +- src/rustc/middle/typeck/check/alt.rs | 2 +- src/rustc/middle/typeck/check/vtable.rs | 4 +- src/rustc/middle/typeck/collect.rs | 2 +- src/rustc/middle/typeck/infer.rs | 2 +- .../middle/typeck/infer/region_var_bindings.rs | 2 +- src/rustc/middle/typeck/infer/resolve.rs | 4 +- src/rustdoc/attr_pass.rs | 2 +- src/rustdoc/config.rs | 4 +- src/rustdoc/desc_to_brief_pass.rs | 6 +- src/rustdoc/doc.rs | 36 +- src/rustdoc/page_pass.rs | 2 +- src/rustdoc/path_pass.rs | 4 +- src/rustdoc/tystr_pass.rs | 2 +- src/rustdoc/unindent_pass.rs | 6 +- src/test/bench/core-std.rs | 2 +- src/test/bench/graph500-bfs.rs | 14 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 2 +- src/test/bench/msgsend-ring-rw-arcs.rs | 2 +- .../compile-fail/block-arg-as-stmt-with-value.rs | 2 +- .../compile-fail/regions-escape-loop-via-vec.rs | 2 +- .../run-pass/block-arg-can-be-followed-by-binop.rs | 2 +- src/test/run-pass/block-arg-in-parentheses.rs | 8 +- src/test/run-pass/block-arg.rs | 22 +- src/test/run-pass/block-vec-map2.rs | 2 +- src/test/run-pass/ret-break-cont-in-block.rs | 8 +- 83 files changed, 541 insertions(+), 464 deletions(-) (limited to 'src/test') diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index dd0e53143f5..6136652c873 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -527,7 +527,7 @@ fn load_one_source_package(src: @Source, p: &json::Object) { Some(json::List(js)) => { for js.each |j| { match *j { - json::String(j) => vec::grow(tags, 1u, j), + json::String(ref j) => tags.grow(1u, j), _ => () } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index dae5105ce71..ff695f64088 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -503,10 +503,7 @@ fn make_run_args(config: config, _props: test_props, testfile: &Path) -> fn split_maybe_args(argstr: Option<~str>) -> ~[~str] { fn rm_whitespace(v: ~[~str]) -> ~[~str] { - fn flt(&&s: ~str) -> Option<~str> { - if !str::is_whitespace(s) { option::Some(s) } else { option::None } - } - vec::filter_map(v, flt) + vec::filter(v, |s| !str::is_whitespace(*s)) } match argstr { diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index ab3c2c7c2ca..ace96c389ef 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -229,7 +229,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap, filename: &Path, cx: context) { let stolen = steal(crate, cx.mode); let extra_exprs = vec::filter(common_exprs(), - |a| safe_to_use_expr(a, cx.mode) ); + |a| safe_to_use_expr(*a, cx.mode) ); check_variants_T(crate, codemap, filename, ~"expr", extra_exprs + stolen.exprs, pprust::expr_to_str, replace_expr_in_crate, cx); diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index fcf8146200d..0bdf5caec0c 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -99,7 +99,7 @@ pub pure fn from_elem(+data: T) -> DList { pub fn from_vec(+vec: &[T]) -> DList { do vec::foldl(DList(), vec) |list,data| { - list.push(data); // Iterating left-to-right -- add newly to the tail. + list.push(*data); // Iterating left-to-right -- add newly to the tail. list } } diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index eb221926fc1..d360eab3c8a 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -157,7 +157,7 @@ impl DVec { fn pop() -> A { do self.check_out |v| { let mut v <- v; - let result = vec::pop(v); + let result = v.pop(); self.give_back(move v); move result } @@ -187,7 +187,7 @@ impl DVec { fn shift() -> A { do self.check_out |v| { let mut v = move v; - let result = vec::shift(v); + let result = v.shift(); self.give_back(move v); move result } @@ -305,10 +305,10 @@ impl DVec { * growing the vector if necessary. New elements will be initialized * with `initval` */ - fn grow_set_elt(idx: uint, initval: A, +val: A) { + fn grow_set_elt(idx: uint, initval: &A, +val: A) { do self.swap |v| { let mut v = move v; - vec::grow_set(v, idx, initval, val); + v.grow_set(idx, initval, val); move v } } diff --git a/src/libcore/float.rs b/src/libcore/float.rs index aff6db3c10f..098e82f5fad 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -140,7 +140,7 @@ pub fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { // turn digits into string // using stack of digits while fractionalParts.is_not_empty() { - let mut adjusted_digit = carry + vec::pop(fractionalParts); + let mut adjusted_digit = carry + fractionalParts.pop(); if adjusted_digit == 10 { carry = 1; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 47ea01af677..667aaaf7b0e 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -64,11 +64,11 @@ trait ReaderUtil { impl T : ReaderUtil { fn read_bytes(len: uint) -> ~[u8] { let mut buf = vec::with_capacity(len); - unsafe { vec::raw::set_len(buf, len); } + unsafe { vec::raw::set_len(&mut buf, len); } let count = self.read(buf, len); - unsafe { vec::raw::set_len(buf, count); } + unsafe { vec::raw::set_len(&mut buf, count); } move buf } fn read_line() -> ~str { @@ -695,7 +695,7 @@ impl BytesWriter: Writer { let count = uint::max(buf_len, self.pos + v_len); vec::reserve(&mut buf, count); - unsafe { vec::raw::set_len(buf, count); } + unsafe { vec::raw::set_len(&mut buf, count); } { let view = vec::mut_view(buf, self.pos, count); diff --git a/src/libcore/os.rs b/src/libcore/os.rs index c1ea71c181b..644cef42b41 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -582,7 +582,7 @@ pub fn list_dir(p: &Path) -> ~[~str] { fn star(p: &Path) -> Path { p.push("*") } do rustrt::rust_list_files(star(p).to_str()).filter |filename| { - filename != ~"." && filename != ~".." + *filename != ~"." && *filename != ~".." } } @@ -857,10 +857,10 @@ mod tests { let mut e = env(); setenv(n, ~"VALUE"); - assert !vec::contains(e, (copy n, ~"VALUE")); + assert !vec::contains(e, &(copy n, ~"VALUE")); e = env(); - assert vec::contains(e, (n, ~"VALUE")); + assert vec::contains(e, &(n, ~"VALUE")); } #[test] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index c384745bb5e..1afcc7ba09d 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -221,7 +221,7 @@ impl PosixPath : GenericPath { pure fn pop() -> PosixPath { let mut cs = copy self.components; if cs.len() != 0 { - unsafe { vec::pop(cs); } + unsafe { cs.pop(); } } return PosixPath { components: move cs, ..self } } @@ -415,7 +415,7 @@ impl WindowsPath : GenericPath { pure fn pop() -> WindowsPath { let mut cs = copy self.components; if cs.len() != 0 { - unsafe { vec::pop(cs); } + unsafe { cs.pop(); } } return WindowsPath { components: move cs, ..self } } @@ -437,7 +437,7 @@ pub pure fn normalize(components: &[~str]) -> ~[~str] { if *c == ~"." && components.len() > 1 { loop; } if *c == ~"" { loop; } if *c == ~".." && cs.len() != 0 { - vec::pop(cs); + cs.pop(); loop; } cs.push(copy *c); diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 3559753410f..7a4d15ac4fe 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -704,7 +704,7 @@ pub fn select(+endpoints: ~[RecvPacketBuffered]) { let ready = wait_many(endpoints.map(|p| p.header())); let mut remaining <- endpoints; - let port = vec::swap_remove(remaining, ready); + let port = remaining.swap_remove(ready); let result = try_recv(move port); (ready, move result, move remaining) } @@ -1067,7 +1067,7 @@ impl PortSet : Recv { } None => { // Remove this port. - let _ = vec::swap_remove(ports, i); + let _ = ports.swap_remove(i); } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 72fa2cda1a7..7f1f1e4b345 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -127,7 +127,7 @@ pub unsafe fn memset(dst: *mut T, c: int, count: uint) { reinterpret_cast. */ #[inline(always)] -pub fn to_unsafe_ptr(thing: &T) -> *T { +pub pure fn to_unsafe_ptr(thing: &T) -> *T { unsafe { cast::reinterpret_cast(&thing) } } @@ -137,7 +137,7 @@ pub fn to_unsafe_ptr(thing: &T) -> *T { reinterpret_cast. */ #[inline(always)] -pub fn to_const_unsafe_ptr(thing: &const T) -> *const T { +pub pure fn to_const_unsafe_ptr(thing: &const T) -> *const T { unsafe { cast::reinterpret_cast(&thing) } } @@ -147,7 +147,7 @@ pub fn to_const_unsafe_ptr(thing: &const T) -> *const T { reinterpret_cast. */ #[inline(always)] -pub fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { +pub pure fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { unsafe { cast::reinterpret_cast(&thing) } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index d7e90c1a42d..a932a6133c5 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -450,7 +450,7 @@ Section: Transforming strings */ pure fn to_bytes(s: &str) -> ~[u8] unsafe { let mut v: ~[u8] = ::cast::transmute(from_slice(s)); - vec::raw::set_len(v, len(s)); + vec::raw::set_len(&mut v, len(s)); move v } @@ -1945,7 +1945,7 @@ fn reserve_at_least(s: &const ~str, n: uint) { */ pure fn capacity(s: &const ~str) -> uint { do as_bytes(s) |buf| { - let vcap = vec::capacity(*buf); + let vcap = vec::capacity(buf); assert vcap > 0u; vcap - 1u } @@ -2008,7 +2008,7 @@ mod raw { vec::as_mut_buf(v, |vbuf, _len| { ptr::memcpy(vbuf, buf as *u8, len) }); - vec::raw::set_len(v, len); + vec::raw::set_len(&mut v, len); v.push(0u8); assert is_utf8(v); @@ -2065,7 +2065,7 @@ mod raw { let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); } - vec::raw::set_len(v, end - begin); + vec::raw::set_len(&mut v, end - begin); v.push(0u8); ::cast::transmute(move v) } diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index a89661c3291..50f55383167 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -35,35 +35,44 @@ impl (T, U): TupleOps { } trait ExtendedTupleOps { - fn zip() -> ~[(A, B)]; - fn map(f: &fn(A, B) -> C) -> ~[C]; + fn zip(&self) -> ~[(A, B)]; + fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C]; } impl (&[A], &[B]): ExtendedTupleOps { - - fn zip() -> ~[(A, B)] { - let (a, b) = self; - vec::zip_slice(a, b) + fn zip(&self) -> ~[(A, B)] { + match *self { + (ref a, ref b) => { + vec::zip_slice(*a, *b) + } + } } - fn map(f: &fn(A, B) -> C) -> ~[C] { - let (a, b) = self; - vec::map2(a, b, f) + fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { + match *self { + (ref a, ref b) => { + vec::map2(*a, *b, f) + } + } } } impl (~[A], ~[B]): ExtendedTupleOps { - fn zip() -> ~[(A, B)] { - // FIXME #2543: Bad copy - let (a, b) = copy self; - vec::zip(move a, move b) + fn zip(&self) -> ~[(A, B)] { + match *self { + (ref a, ref b) => { + vec::zip_slice(*a, *b) + } + } } - fn map(f: &fn(A, B) -> C) -> ~[C] { - // FIXME #2543: Bad copy - let (a, b) = copy self; - vec::map2(a, b, f) + fn map(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] { + match *self { + (ref a, ref b) => { + vec::map2(*a, *b, f) + } + } } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 07ccb244ddd..914434c9d46 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1,5 +1,9 @@ //! Vectors +#[warn(deprecated_mode)]; +#[warn(deprecated_pattern)]; +#[warn(non_camel_case_types)]; + use cmp::{Eq, Ord}; use option::{Some, None}; use ptr::addr_of; @@ -140,7 +144,7 @@ pure fn same_length(xs: &[const T], ys: &[const U]) -> bool { */ fn reserve(+v: &mut ~[T], +n: uint) { // Only make the (slow) call into the runtime if we have to - if capacity(*v) < n { + if capacity(v) < n { unsafe { let ptr: **raw::VecRepr = cast::transmute(v); rustrt::vec_reserve_shared(sys::get_type_desc::(), @@ -170,16 +174,16 @@ fn reserve_at_least(v: &mut ~[T], n: uint) { /// Returns the number of elements the vector can hold without reallocating #[inline(always)] -pure fn capacity(&&v: ~[const T]) -> uint { +pure fn capacity(v: &const ~[T]) -> uint { unsafe { - let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::transmute(v); (**repr).unboxed.alloc / sys::size_of::() } } /// Returns the length of a vector #[inline(always)] -pure fn len(&&v: &[const T]) -> uint { +pure fn len(v: &[const T]) -> uint { as_const_buf(v, |_p, len| len) } @@ -190,11 +194,18 @@ pure fn len(&&v: &[const T]) -> uint { * to the value returned by the function `op`. */ pure fn from_fn(n_elts: uint, op: iter::InitOp) -> ~[T] { - let mut v = with_capacity(n_elts); - let mut i: uint = 0u; - while i < n_elts unsafe { raw::set(v, i, op(i)); i += 1u; } - unsafe { raw::set_len(v, n_elts); } - move v + unsafe { + let mut v = with_capacity(n_elts); + do as_mut_buf(v) |p, _len| { + let mut i: uint = 0u; + while i < n_elts { + rusti::move_val_init(*ptr::mut_offset(p, i), op(i)); + i += 1u; + } + } + raw::set_len(&mut v, n_elts); + return move v; + } } /** @@ -203,14 +214,8 @@ pure fn from_fn(n_elts: uint, op: iter::InitOp) -> ~[T] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value `t`. */ -pure fn from_elem(n_elts: uint, t: T) -> ~[T] { - let mut v = with_capacity(n_elts); - let mut i: uint = 0u; - unsafe { // because unsafe::set is unsafe - while i < n_elts { raw::set(v, i, t); i += 1u; } - unsafe { raw::set_len(v, n_elts); } - } - move v +pure fn from_elem(n_elts: uint, +t: T) -> ~[T] { + from_fn(n_elts, |_i| copy t) } /// Creates a new unique vector with the same contents as the slice @@ -378,7 +383,7 @@ pure fn const_view(v: &r/[const T], start: uint, } /// Split the vector `v` by applying each element against the predicate `f`. -fn split(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { +fn split(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -401,7 +406,7 @@ fn split(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { * Split the vector `v` by applying each element against the predicate `f` up * to `n` times. */ -fn splitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { +fn splitn(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -427,7 +432,7 @@ fn splitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { * Reverse split the vector `v` by applying each element against the predicate * `f`. */ -fn rsplit(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { +fn rsplit(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -451,7 +456,7 @@ fn rsplit(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { * Reverse split the vector `v` by applying each element against the predicate * `f` up to `n times. */ -fn rsplitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { +fn rsplitn(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -477,12 +482,12 @@ fn rsplitn(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { // Mutators /// Removes the first element from a vector and return it -fn shift(&v: ~[T]) -> T { - let ln = len::(v); +fn shift(v: &mut ~[T]) -> T { + let ln = v.len(); assert (ln > 0); let mut vv = ~[]; - v <-> vv; + *v <-> vv; unsafe { let mut rr; @@ -495,22 +500,22 @@ fn shift(&v: ~[T]) -> T { v.push(move r); } } - raw::set_len(vv, 0); + raw::set_len(&mut vv, 0); move rr } } /// Prepend an element to the vector -fn unshift(&v: ~[T], +x: T) { +fn unshift(v: &mut ~[T], +x: T) { let mut vv = ~[move x]; - v <-> vv; - while len(vv) > 0 { - v.push(shift(vv)); - } + *v <-> vv; + v.push_all_move(vv); } fn consume(+v: ~[T], f: fn(uint, +v: T)) unsafe { + let mut v = move v; // FIXME(#3488) + do as_imm_buf(v) |p, ln| { for uint::range(0, ln) |i| { let x <- *ptr::offset(p, i); @@ -518,29 +523,22 @@ fn consume(+v: ~[T], f: fn(uint, +v: T)) unsafe { } } - raw::set_len(v, 0); + raw::set_len(&mut v, 0); } -fn consume_mut(+v: ~[mut T], f: fn(uint, +v: T)) unsafe { - do as_imm_buf(v) |p, ln| { - for uint::range(0, ln) |i| { - let x <- *ptr::offset(p, i); - f(i, move x); - } - } - - raw::set_len(v, 0); +fn consume_mut(+v: ~[mut T], f: fn(uint, +v: T)) { + consume(vec::from_mut(v), f) } /// Remove the last element from a vector and return it -fn pop(&v: ~[const T]) -> T { - let ln = len(v); +fn pop(v: &mut ~[T]) -> T { + let ln = v.len(); if ln == 0 { fail ~"sorry, cannot vec::pop an empty vector" } - let valptr = ptr::mut_addr_of(v[ln - 1u]); + let valptr = ptr::to_mut_unsafe_ptr(&mut v[ln - 1u]); unsafe { - let val <- *valptr; + let val = move *valptr; raw::set_len(v, ln - 1u); move val } @@ -552,21 +550,15 @@ fn pop(&v: ~[const T]) -> T { * * Fails if index >= length. */ -fn swap_remove(&v: ~[const T], index: uint) -> T { - let ln = len(v); +fn swap_remove(v: &mut ~[T], index: uint) -> T { + let ln = v.len(); if index >= ln { fail fmt!("vec::swap_remove - index %u >= length %u", index, ln); } - let lastptr = ptr::mut_addr_of(v[ln - 1]); - unsafe { - let mut val <- *lastptr; - if index < ln - 1 { - let valptr = ptr::mut_addr_of(v[index]); - *valptr <-> val; - } - raw::set_len(v, ln - 1); - move val + if index < ln - 1 { + v[index] <-> v[ln - 1]; } + vec::pop(v) } /// Append an element to a vector @@ -611,7 +603,8 @@ fn push_all(+v: &mut ~[T], rhs: &[const T]) { } #[inline(always)] -fn push_all_move(v: &mut ~[T], -rhs: ~[const T]) { +fn push_all_move(v: &mut ~[T], +rhs: ~[T]) { + let mut rhs = move rhs; // FIXME(#3488) reserve(v, v.len() + rhs.len()); unsafe { do as_imm_buf(rhs) |p, len| { @@ -620,13 +613,13 @@ fn push_all_move(v: &mut ~[T], -rhs: ~[const T]) { push(v, move x); } } - raw::set_len(rhs, 0); + raw::set_len(&mut rhs, 0); } } /// Shorten a vector, dropping excess elements. -fn truncate(&v: ~[const T], newlen: uint) { - do as_imm_buf(v) |p, oldlen| { +fn truncate(v: &mut ~[T], newlen: uint) { + do as_imm_buf(*v) |p, oldlen| { assert(newlen <= oldlen); unsafe { // This loop is optimized out for non-drop types. @@ -642,10 +635,10 @@ fn truncate(&v: ~[const T], newlen: uint) { * Remove consecutive repeated elements from a vector; if the vector is * sorted, this removes all duplicates. */ -fn dedup(&v: ~[const T]) unsafe { +fn dedup(v: &mut ~[T]) unsafe { if v.len() < 1 { return; } let mut last_written = 0, next_to_read = 1; - do as_const_buf(v) |p, ln| { + do as_const_buf(*v) |p, ln| { // We have a mutable reference to v, so we can make arbitrary changes. // (cf. push and pop) let p = p as *mut T; @@ -704,12 +697,12 @@ pure fn append_mut(+lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] { * * n - The number of elements to add * * initval - The value for the new elements */ -fn grow(&v: ~[T], n: uint, initval: T) { - reserve_at_least(&mut v, len(v) + n); +fn grow(v: &mut ~[T], n: uint, initval: &T) { + reserve_at_least(v, v.len() + n); let mut i: uint = 0u; while i < n { - v.push(initval); + v.push(*initval); i += 1u; } } @@ -727,8 +720,8 @@ fn grow(&v: ~[T], n: uint, initval: T) { * * init_op - A function to call to retreive each appended element's * value */ -fn grow_fn(&v: ~[T], n: uint, op: iter::InitOp) { - reserve_at_least(&mut v, len(v) + n); +fn grow_fn(v: &mut ~[T], n: uint, op: iter::InitOp) { + reserve_at_least(v, v.len() + n); let mut i: uint = 0u; while i < n { v.push(op(i)); @@ -744,15 +737,16 @@ fn grow_fn(&v: ~[T], n: uint, op: iter::InitOp) { * of the vector, expands the vector by replicating `initval` to fill the * intervening space. */ -fn grow_set(&v: ~[T], index: uint, initval: T, val: T) { - if index >= len(v) { grow(v, index - len(v) + 1u, initval); } - v[index] = val; +fn grow_set(v: &mut ~[T], index: uint, initval: &T, +val: T) { + let l = v.len(); + if index >= l { grow(v, index - l + 1u, initval); } + v[index] = move val; } // Functional utilities /// Apply a function to each element of a vector and return the results -pure fn map(v: &[T], f: fn(v: &T) -> U) -> ~[U] { +pure fn map(v: &[T], f: fn(t: &T) -> U) -> ~[U] { let mut result = with_capacity(len(v)); for each(v) |elem| { unsafe { @@ -771,7 +765,7 @@ fn map_consume(+v: ~[T], f: fn(+v: T) -> U) -> ~[U] { } /// Apply a function to each element of a vector and return the results -pure fn mapi(v: &[T], f: fn(uint, v: &T) -> U) -> ~[U] { +pure fn mapi(v: &[T], f: fn(uint, t: &T) -> U) -> ~[U] { let mut i = 0; do map(v) |e| { i += 1; @@ -783,21 +777,21 @@ pure fn mapi(v: &[T], f: fn(uint, v: &T) -> U) -> ~[U] { * Apply a function to each element of a vector and return a concatenation * of each result vector */ -pure fn flat_map(v: &[T], f: fn(T) -> ~[U]) -> ~[U] { +pure fn flat_map(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] { let mut result = ~[]; - for each(v) |elem| { unsafe{ result.push_all_move(f(*elem)); } } + for each(v) |elem| { unsafe{ result.push_all_move(f(elem)); } } move result } /// Apply a function to each pair of elements and return the results pure fn map2(v0: &[T], v1: &[U], - f: fn(T, U) -> V) -> ~[V] { + f: fn(t: &T, v: &U) -> V) -> ~[V] { let v0_len = len(v0); if v0_len != len(v1) { fail; } let mut u: ~[V] = ~[]; let mut i = 0u; while i < v0_len { - unsafe { u.push(f(copy v0[i], copy v1[i])) }; + unsafe { u.push(f(&v0[i], &v1[i])) }; i += 1u; } move u @@ -809,11 +803,11 @@ pure fn map2(v0: &[T], v1: &[U], * If function `f` returns `none` then that element is excluded from * the resulting vector. */ -pure fn filter_map(v: &[T], f: fn(T) -> Option) +pure fn filter_map(v: &[T], f: fn(t: &T) -> Option) -> ~[U] { let mut result = ~[]; for each(v) |elem| { - match f(*elem) { + match f(elem) { None => {/* no-op */ } Some(result_elem) => unsafe { result.push(result_elem); } } @@ -828,10 +822,10 @@ pure fn filter_map(v: &[T], f: fn(T) -> Option) * Apply function `f` to each element of `v` and return a vector containing * only those elements for which `f` returned true. */ -pure fn filter(v: &[T], f: fn(T) -> bool) -> ~[T] { +pure fn filter(v: &[T], f: fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; for each(v) |elem| { - if f(*elem) { unsafe { result.push(*elem); } } + if f(elem) { unsafe { result.push(*elem); } } } move result } @@ -848,30 +842,32 @@ pure fn concat(v: &[~[T]]) -> ~[T] { } /// Concatenate a vector of vectors, placing a given separator between each -pure fn connect(v: &[~[T]], sep: T) -> ~[T] { +pure fn connect(v: &[~[T]], sep: &T) -> ~[T] { let mut r: ~[T] = ~[]; let mut first = true; for each(v) |inner| { - if first { first = false; } else { unsafe { r.push(sep); } } + if first { first = false; } else { unsafe { r.push(*sep); } } unsafe { r.push_all(*inner) }; } move r } /// Reduce a vector from left to right -pure fn foldl(z: T, v: &[U], p: fn(T, U) -> T) -> T { +pure fn foldl(+z: T, v: &[U], p: fn(+t: T, u: &U) -> T) -> T { let mut accum = z; for each(v) |elt| { - accum = p(accum, *elt); + // it should be possible to move accum in, but the liveness analysis + // is not smart enough. + accum = p(accum, elt); } return accum; } /// Reduce a vector from right to left -pure fn foldr(v: &[T], z: U, p: fn(T, U) -> U) -> U { +pure fn foldr(v: &[T], +z: U, p: fn(t: &T, +u: U) -> U) -> U { let mut accum = z; for rev_each(v) |elt| { - accum = p(*elt, accum); + accum = p(elt, accum); } return accum; } @@ -881,8 +877,8 @@ pure fn foldr(v: &[T], z: U, p: fn(T, U) -> U) -> U { * * If the vector contains no elements then false is returned. */ -pure fn any(v: &[T], f: fn(T) -> bool) -> bool { - for each(v) |elem| { if f(*elem) { return true; } } +pure fn any(v: &[T], f: fn(t: &T) -> bool) -> bool { + for each(v) |elem| { if f(elem) { return true; } } return false; } @@ -892,12 +888,12 @@ pure fn any(v: &[T], f: fn(T) -> bool) -> bool { * If the vectors contains no elements then false is returned. */ pure fn any2(v0: &[T], v1: &[U], - f: fn(T, U) -> bool) -> bool { + f: fn(a: &T, b: &U) -> bool) -> bool { let v0_len = len(v0); let v1_len = len(v1); let mut i = 0u; while i < v0_len && i < v1_len { - if f(v0[i], v1[i]) { return true; }; + if f(&v0[i], &v1[i]) { return true; }; i += 1u; } return false; @@ -908,8 +904,8 @@ pure fn any2(v0: &[T], v1: &[U], * * If the vector contains no elements then true is returned. */ -pure fn all(v: &[T], f: fn(T) -> bool) -> bool { - for each(v) |elem| { if !f(*elem) { return false; } } +pure fn all(v: &[T], f: fn(t: &T) -> bool) -> bool { + for each(v) |elem| { if !f(elem) { return false; } } return true; } @@ -918,8 +914,8 @@ pure fn all(v: &[T], f: fn(T) -> bool) -> bool { * * If the vector contains no elements then true is returned. */ -pure fn alli(v: &[T], f: fn(uint, T) -> bool) -> bool { - for eachi(v) |i, elem| { if !f(i, *elem) { return false; } } +pure fn alli(v: &[T], f: fn(uint, t: &T) -> bool) -> bool { + for eachi(v) |i, elem| { if !f(i, elem) { return false; } } return true; } @@ -929,24 +925,24 @@ pure fn alli(v: &[T], f: fn(uint, T) -> bool) -> bool { * If the vectors are not the same size then false is returned. */ pure fn all2(v0: &[T], v1: &[U], - f: fn(T, U) -> bool) -> bool { + f: fn(t: &T, u: &U) -> bool) -> bool { let v0_len = len(v0); if v0_len != len(v1) { return false; } let mut i = 0u; - while i < v0_len { if !f(v0[i], v1[i]) { return false; }; i += 1u; } + while i < v0_len { if !f(&v0[i], &v1[i]) { return false; }; i += 1u; } return true; } /// Return true if a vector contains an element with the given value -pure fn contains(v: &[T], x: T) -> bool { - for each(v) |elt| { if x == *elt { return true; } } +pure fn contains(v: &[T], x: &T) -> bool { + for each(v) |elt| { if *x == *elt { return true; } } return false; } /// Returns the number of elements that are equal to a given value -pure fn count(v: &[T], x: T) -> uint { +pure fn count(v: &[T], x: &T) -> uint { let mut cnt = 0u; - for each(v) |elt| { if x == *elt { cnt += 1u; } } + for each(v) |elt| { if *x == *elt { cnt += 1u; } } return cnt; } @@ -957,7 +953,7 @@ pure fn count(v: &[T], x: T) -> uint { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -pure fn find(v: &[T], f: fn(T) -> bool) -> Option { +pure fn find(v: &[T], f: fn(t: &T) -> bool) -> Option { find_between(v, 0u, len(v), f) } @@ -969,7 +965,7 @@ pure fn find(v: &[T], f: fn(T) -> bool) -> Option { * the element is returned. If `f` matches no elements then none is returned. */ pure fn find_between(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option { + f: fn(t: &T) -> bool) -> Option { position_between(v, start, end, f).map(|i| v[*i]) } @@ -980,7 +976,7 @@ pure fn find_between(v: &[T], start: uint, end: uint, * `f` returns true then an option containing the element is returned. If `f` * matches no elements then none is returned. */ -pure fn rfind(v: &[T], f: fn(T) -> bool) -> Option { +pure fn rfind(v: &[T], f: fn(t: &T) -> bool) -> Option { rfind_between(v, 0u, len(v), f) } @@ -989,16 +985,16 @@ pure fn rfind(v: &[T], f: fn(T) -> bool) -> Option { * * Apply function `f` to each element of `v` in reverse order within the range * [`start`, `end`). When function `f` returns true then an option containing - * the element is returned. If `f` matches no elements then none is returned. + * the element is returned. If `f` matches no elements then none is return. */ pure fn rfind_between(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option { + f: fn(t: &T) -> bool) -> Option { rposition_between(v, start, end, f).map(|i| v[*i]) } /// Find the first index containing a matching value -pure fn position_elem(v: &[T], x: T) -> Option { - position(v, |y| x == y) +pure fn position_elem(v: &[T], x: &T) -> Option { + position(v, |y| *x == *y) } /** @@ -1008,7 +1004,7 @@ pure fn position_elem(v: &[T], x: T) -> Option { * then an option containing the index is returned. If `f` matches no elements * then none is returned. */ -pure fn position(v: &[T], f: fn(T) -> bool) -> Option { +pure fn position(v: &[T], f: fn(t: &T) -> bool) -> Option { position_between(v, 0u, len(v), f) } @@ -1020,17 +1016,17 @@ pure fn position(v: &[T], f: fn(T) -> bool) -> Option { * the index is returned. If `f` matches no elements then none is returned. */ pure fn position_between(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option { + f: fn(t: &T) -> bool) -> Option { assert start <= end; assert end <= len(v); let mut i = start; - while i < end { if f(v[i]) { return Some::(i); } i += 1u; } + while i < end { if f(&v[i]) { return Some::(i); } i += 1u; } return None; } /// Find the last index containing a matching value -pure fn rposition_elem(v: &[T], x: T) -> Option { - rposition(v, |y| x == y) +pure fn rposition_elem(v: &[T], x: &T) -> Option { + rposition(v, |y| *x == *y) } /** @@ -1040,7 +1036,7 @@ pure fn rposition_elem(v: &[T], x: T) -> Option { * `f` returns true then an option containing the index is returned. If `f` * matches no elements then none is returned. */ -pure fn rposition(v: &[T], f: fn(T) -> bool) -> Option { +pure fn rposition(v: &[T], f: fn(t: &T) -> bool) -> Option { rposition_between(v, 0u, len(v), f) } @@ -1053,12 +1049,12 @@ pure fn rposition(v: &[T], f: fn(T) -> bool) -> Option { * returned. */ pure fn rposition_between(v: &[T], start: uint, end: uint, - f: fn(T) -> bool) -> Option { + f: fn(t: &T) -> bool) -> Option { assert start <= end; assert end <= len(v); let mut i = end; while i > start { - if f(v[i - 1u]) { return Some::(i - 1u); } + if f(&v[i - 1u]) { return Some::(i - 1u); } i -= 1u; } return None; @@ -1122,12 +1118,13 @@ pure fn zip_slice(v: &[const T], u: &[const U]) * Returns a vector of tuples, where the i-th tuple contains contains the * i-th elements from each of the input vectors. */ -pure fn zip(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] { - let mut v = move v, u = move u, i = len(v); +pure fn zip(+v: ~[T], +u: ~[U]) -> ~[(T, U)] { + let mut v = move v, u = move u; // FIXME(#3488) + let mut i = len(v); assert i == len(u); let mut w = with_capacity(i); while i > 0 { - unsafe { w.push((pop(v),pop(u))); } + unsafe { w.push((v.pop(),u.pop())); } i -= 1; } unsafe { reverse(w); } @@ -1269,10 +1266,10 @@ pure fn rev_eachi(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) { * Both vectors must have the same length */ #[inline] -fn iter2(v1: &[U], v2: &[T], f: fn(U, T)) { +fn iter2(v1: &[U], v2: &[T], f: fn(u: &U, t: &T)) { assert len(v1) == len(v2); for uint::range(0u, len(v1)) |i| { - f(v1[i], v2[i]) + f(&v1[i], &v2[i]) } } @@ -1286,20 +1283,24 @@ fn iter2(v1: &[U], v2: &[T], f: fn(U, T)) { * The total number of permutations produced is `len(v)!`. If `v` contains * repeated elements, then some permutations are repeated. */ -pure fn permute(v: &[const T], put: fn(~[T])) { +pure fn each_permutation(+v: &[T], put: fn(ts: &[T]) -> bool) { let ln = len(v); - if ln == 0u { - put(~[]); + if ln <= 1 { + put(v); } else { + // This does not seem like the most efficient implementation. You + // could make far fewer copies if you put your mind to it. let mut i = 0u; while i < ln { let elt = v[i]; let mut rest = slice(v, 0u, i); unsafe { rest.push_all(const_view(v, i+1u, ln)); - permute(rest, |permutation| { - put(append(~[elt], permutation)) - }) + for each_permutation(rest) |permutation| { + if !put(append(~[elt], permutation)) { + return; + } + } } i += 1u; } @@ -1528,20 +1529,20 @@ impl &[const T]: CopyableVector { trait ImmutableVector { pure fn view(start: uint, end: uint) -> &self/[T]; - pure fn foldr(z: U, p: fn(T, U) -> U) -> U; - pure fn map(f: fn(v: &T) -> U) -> ~[U]; - pure fn mapi(f: fn(uint, v: &T) -> U) -> ~[U]; + pure fn foldr(z: U, p: fn(t: &T, +u: U) -> U) -> U; + pure fn map(f: fn(t: &T) -> U) -> ~[U]; + pure fn mapi(f: fn(uint, t: &T) -> U) -> ~[U]; fn map_r(f: fn(x: &T) -> U) -> ~[U]; - pure fn alli(f: fn(uint, T) -> bool) -> bool; - pure fn flat_map(f: fn(T) -> ~[U]) -> ~[U]; - pure fn filter_map(f: fn(T) -> Option) -> ~[U]; + pure fn alli(f: fn(uint, t: &T) -> bool) -> bool; + pure fn flat_map(f: fn(t: &T) -> ~[U]) -> ~[U]; + pure fn filter_map(f: fn(t: &T) -> Option) -> ~[U]; } trait ImmutableEqVector { - pure fn position(f: fn(T) -> bool) -> Option; - pure fn position_elem(x: T) -> Option; - pure fn rposition(f: fn(T) -> bool) -> Option; - pure fn rposition_elem(x: T) -> Option; + pure fn position(f: fn(t: &T) -> bool) -> Option; + pure fn position_elem(t: &T) -> Option; + pure fn rposition(f: fn(t: &T) -> bool) -> Option; + pure fn rposition_elem(t: &T) -> Option; } /// Extension methods for vectors @@ -1552,15 +1553,17 @@ impl &[T]: ImmutableVector { } /// Reduce a vector from right to left #[inline] - pure fn foldr(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) } + pure fn foldr(z: U, p: fn(t: &T, +u: U) -> U) -> U { + foldr(self, z, p) + } /// Apply a function to each element of a vector and return the results #[inline] - pure fn map(f: fn(v: &T) -> U) -> ~[U] { map(self, f) } + pure fn map(f: fn(t: &T) -> U) -> ~[U] { map(self, f) } /** * Apply a function to the index and value of each element in the vector * and return the results */ - pure fn mapi(f: fn(uint, v: &T) -> U) -> ~[U] { + pure fn mapi(f: fn(uint, t: &T) -> U) -> ~[U] { mapi(self, f) } @@ -1580,7 +1583,7 @@ impl &[T]: ImmutableVector { * * If the vector is empty, true is returned. */ - pure fn alli(f: fn(uint, T) -> bool) -> bool { + pure fn alli(f: fn(uint, t: &T) -> bool) -> bool { alli(self, f) } /** @@ -1588,7 +1591,9 @@ impl &[T]: ImmutableVector { * of each result vector */ #[inline] - pure fn flat_map(f: fn(T) -> ~[U]) -> ~[U] { flat_map(self, f) } + pure fn flat_map(f: fn(t: &T) -> ~[U]) -> ~[U] { + flat_map(self, f) + } /** * Apply a function to each element of a vector and return the results * @@ -1596,7 +1601,7 @@ impl &[T]: ImmutableVector { * the resulting vector. */ #[inline] - pure fn filter_map(f: fn(T) -> Option) -> ~[U] { + pure fn filter_map(f: fn(t: &T) -> Option) -> ~[U] { filter_map(self, f) } } @@ -1610,10 +1615,16 @@ impl &[T]: ImmutableEqVector { * elements then none is returned. */ #[inline] - pure fn position(f: fn(T) -> bool) -> Option { position(self, f) } + pure fn position(f: fn(t: &T) -> bool) -> Option { + position(self, f) + } + /// Find the first index containing a matching value #[inline] - pure fn position_elem(x: T) -> Option { position_elem(self, x) } + pure fn position_elem(x: &T) -> Option { + position_elem(self, x) + } + /** * Find the last index matching some predicate * @@ -1622,15 +1633,21 @@ impl &[T]: ImmutableEqVector { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rposition(f: fn(T) -> bool) -> Option { rposition(self, f) } + pure fn rposition(f: fn(t: &T) -> bool) -> Option { + rposition(self, f) + } + /// Find the last index containing a matching value #[inline] - pure fn rposition_elem(x: T) -> Option { rposition_elem(self, x) } + pure fn rposition_elem(t: &T) -> Option { + rposition_elem(self, t) + } } trait ImmutableCopyableVector { - pure fn filter(f: fn(T) -> bool) -> ~[T]; - pure fn rfind(f: fn(T) -> bool) -> Option; + pure fn filter(f: fn(t: &T) -> bool) -> ~[T]; + + pure fn rfind(f: fn(t: &T) -> bool) -> Option; } /// Extension methods for vectors @@ -1643,7 +1660,10 @@ impl &[T]: ImmutableCopyableVector { * containing only those elements for which `f` returned true. */ #[inline] - pure fn filter(f: fn(T) -> bool) -> ~[T] { filter(self, f) } + pure fn filter(f: fn(t: &T) -> bool) -> ~[T] { + filter(self, f) + } + /** * Search for the last element that matches a given predicate * @@ -1652,16 +1672,28 @@ impl &[T]: ImmutableCopyableVector { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rfind(f: fn(T) -> bool) -> Option { rfind(self, f) } + pure fn rfind(f: fn(t: &T) -> bool) -> Option { rfind(self, f) } } trait MutableVector { fn push(&mut self, +t: T); - fn push_all_move(&mut self, -rhs: ~[const T]); + fn push_all_move(&mut self, +rhs: ~[T]); + fn pop(&mut self) -> T; + fn shift(&mut self) -> T; + fn unshift(&mut self, +x: T); + fn swap_remove(&mut self, index: uint) -> T; + fn truncate(&mut self, newlen: uint); } trait MutableCopyableVector { fn push_all(&mut self, rhs: &[const T]); + fn grow(&mut self, n: uint, initval: &T); + fn grow_fn(&mut self, n: uint, op: iter::InitOp); + fn grow_set(&mut self, index: uint, initval: &T, +val: T); +} + +trait MutableEqVector { + fn dedup(&mut self); } impl ~[T]: MutableVector { @@ -1669,15 +1701,53 @@ impl ~[T]: MutableVector { push(self, move t); } - fn push_all_move(&mut self, -rhs: ~[const T]) { + fn push_all_move(&mut self, +rhs: ~[T]) { push_all_move(self, move rhs); } + + fn pop(&mut self) -> T { + pop(self) + } + + fn shift(&mut self) -> T { + shift(self) + } + + fn unshift(&mut self, +x: T) { + unshift(self, x) + } + + fn swap_remove(&mut self, index: uint) -> T { + swap_remove(self, index) + } + + fn truncate(&mut self, newlen: uint) { + truncate(self, newlen); + } } impl ~[T]: MutableCopyableVector { fn push_all(&mut self, rhs: &[const T]) { push_all(self, rhs); } + + fn grow(&mut self, n: uint, initval: &T) { + grow(self, n, initval); + } + + fn grow_fn(&mut self, n: uint, op: iter::InitOp) { + grow_fn(self, n, op); + } + + fn grow_set(&mut self, index: uint, initval: &T, +val: T) { + grow_set(self, index, initval, val); + } +} + +impl ~[T]: MutableEqVector { + fn dedup(&mut self) { + dedup(self) + } } /// Unsafe operations @@ -1714,7 +1784,7 @@ mod raw { #[inline(always)] unsafe fn from_buf(ptr: *T, elts: uint) -> ~[T] { let mut dst = with_capacity(elts); - set_len(dst, elts); + set_len(&mut dst, elts); as_mut_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts)); move dst } @@ -1727,8 +1797,8 @@ mod raw { * the vector is actually the specified size. */ #[inline(always)] - unsafe fn set_len(&&v: ~[const T], new_len: uint) { - let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn set_len(v: &mut ~[T], new_len: uint) { + let repr: **VecRepr = ::cast::transmute(v); (**repr).unboxed.fill = new_len * sys::size_of::(); } @@ -1742,22 +1812,22 @@ mod raw { * would also make any pointers to it invalid. */ #[inline(always)] - unsafe fn to_ptr(v: &[T]) -> *T { - let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn to_ptr(+v: &[T]) -> *T { + let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] - unsafe fn to_const_ptr(v: &[const T]) -> *const T { - let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn to_const_ptr(+v: &[const T]) -> *const T { + let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] - unsafe fn to_mut_ptr(v: &[mut T]) -> *mut T { - let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + unsafe fn to_mut_ptr(+v: &[mut T]) -> *mut T { + let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of((**repr).data)); } @@ -1782,10 +1852,12 @@ mod raw { } /** - * Unchecked vector index assignment. + * Unchecked vector index assignment. Does not drop the + * old value and hence is only suitable when the vector + * is newly allocated. */ #[inline(always)] - unsafe fn set(v: &[mut T], i: uint, +val: T) { + unsafe fn init_elem(v: &[mut T], i: uint, +val: T) { let mut box = Some(move val); do as_mut_buf(v) |p, _len| { let mut box2 = None; @@ -1963,17 +2035,17 @@ mod tests { fn square_ref(n: &uint) -> uint { return square(*n); } - pure fn is_three(&&n: uint) -> bool { return n == 3u; } + pure fn is_three(n: &uint) -> bool { return *n == 3u; } - pure fn is_odd(&&n: uint) -> bool { return n % 2u == 1u; } + pure fn is_odd(n: &uint) -> bool { return *n % 2u == 1u; } - pure fn is_equal(&&x: uint, &&y:uint) -> bool { return x == y; } + pure fn is_equal(x: &uint, y:&uint) -> bool { return *x == *y; } - fn square_if_odd(&&n: uint) -> Option { - return if n % 2u == 1u { Some(n * n) } else { None }; + fn square_if_odd(n: &uint) -> Option { + return if *n % 2u == 1u { Some(*n * *n) } else { None }; } - fn add(&&x: uint, &&y: uint) -> uint { return x + y; } + fn add(+x: uint, y: &uint) -> uint { return x + *y; } #[test] fn test_unsafe_ptrs() { @@ -2103,7 +2175,7 @@ mod tests { fn test_pop() { // Test on-stack pop. let mut v = ~[1, 2, 3]; - let mut e = pop(v); + let mut e = v.pop(); assert (len(v) == 2u); assert (v[0] == 1); assert (v[1] == 2); @@ -2111,7 +2183,7 @@ mod tests { // Test on-heap pop. v = ~[1, 2, 3, 4, 5]; - e = pop(v); + e = v.pop(); assert (len(v) == 4u); assert (v[0] == 1); assert (v[1] == 2); @@ -2123,11 +2195,11 @@ mod tests { #[test] fn test_swap_remove() { let mut v = ~[1, 2, 3, 4, 5]; - let mut e = swap_remove(v, 0); + let mut e = v.swap_remove(0); assert (len(v) == 4); assert e == 1; assert (v[0] == 5); - e = swap_remove(v, 3); + e = v.swap_remove(3); assert (len(v) == 3); assert e == 4; assert (v[0] == 5); @@ -2140,11 +2212,11 @@ mod tests { // Tests that we don't accidentally run destructors twice. let mut v = ~[::private::exclusive(()), ::private::exclusive(()), ::private::exclusive(())]; - let mut _e = swap_remove(v, 0); + let mut _e = v.swap_remove(0); assert (len(v) == 2); - _e = swap_remove(v, 1); + _e = v.swap_remove(1); assert (len(v) == 1); - _e = swap_remove(v, 0); + _e = v.swap_remove(0); assert (len(v) == 0); } @@ -2167,13 +2239,13 @@ mod tests { fn test_grow() { // Test on-stack grow(). let mut v = ~[]; - grow(v, 2u, 1); + v.grow(2u, &1); assert (len(v) == 2u); assert (v[0] == 1); assert (v[1] == 1); // Test on-heap grow(). - grow(v, 3u, 2); + v.grow(3u, &2); assert (len(v) == 5u); assert (v[0] == 1); assert (v[1] == 1); @@ -2185,7 +2257,7 @@ mod tests { #[test] fn test_grow_fn() { let mut v = ~[]; - grow_fn(v, 3u, square); + v.grow_fn(3u, square); assert (len(v) == 3u); assert (v[0] == 0u); assert (v[1] == 1u); @@ -2195,7 +2267,7 @@ mod tests { #[test] fn test_grow_set() { let mut v = ~[1, 2, 3]; - grow_set(v, 4u, 4, 5); + v.grow_set(4u, &4, 5); assert (len(v) == 5u); assert (v[0] == 1); assert (v[1] == 2); @@ -2207,7 +2279,7 @@ mod tests { #[test] fn test_truncate() { let mut v = ~[@6,@5,@4]; - truncate(v, 1); + v.truncate(1); assert(v.len() == 1); assert(*(v[0]) == 6); // If the unsafe block didn't drop things properly, we blow up here. @@ -2217,7 +2289,7 @@ mod tests { fn test_dedup() { fn case(-a: ~[uint], -b: ~[uint]) { let mut v = a; - dedup(v); + v.dedup(); assert(v == b); } case(~[], ~[]); @@ -2233,11 +2305,11 @@ mod tests { #[test] fn test_dedup_unique() { let mut v0 = ~[~1, ~1, ~2, ~3]; - dedup(v0); + v0.dedup(); let mut v1 = ~[~1, ~2, ~2, ~3]; - dedup(v1); + v1.dedup(); let mut v2 = ~[~1, ~2, ~3, ~3]; - dedup(v2); + v2.dedup(); /* * If the ~pointers were leaked or otherwise misused, valgrind and/or * rustrt should raise errors. @@ -2247,11 +2319,11 @@ mod tests { #[test] fn test_dedup_shared() { let mut v0 = ~[@1, @1, @2, @3]; - dedup(v0); + v0.dedup(); let mut v1 = ~[@1, @2, @2, @3]; - dedup(v1); + v1.dedup(); let mut v2 = ~[@1, @2, @3, @3]; - dedup(v2); + v2.dedup(); /* * If the @pointers were leaked or otherwise misused, valgrind and/or * rustrt should raise errors. @@ -2281,7 +2353,7 @@ mod tests { #[test] fn test_map2() { - fn times(&&x: int, &&y: int) -> int { return x * y; } + fn times(x: &int, y: &int) -> int { return *x * *y; } let f = times; let v0 = ~[1, 2, 3, 4, 5]; let v1 = ~[5, 4, 3, 2, 1]; @@ -2307,9 +2379,9 @@ mod tests { assert (w[1] == 9u); assert (w[2] == 25u); - fn halve(&&i: int) -> Option { - if i % 2 == 0 { - return option::Some::(i / 2); + fn halve(i: &int) -> Option { + if *i % 2 == 0 { + return option::Some::(*i / 2); } else { return option::None::; } } fn halve_for_sure(i: &int) -> int { return *i / 2; } @@ -2345,8 +2417,8 @@ mod tests { #[test] fn test_foldl2() { - fn sub(&&a: int, &&b: int) -> int { - a - b + fn sub(+a: int, b: &int) -> int { + a - *b } let mut v = ~[1, 2, 3, 4]; let sum = foldl(0, v, sub); @@ -2355,8 +2427,8 @@ mod tests { #[test] fn test_foldr() { - fn sub(&&a: int, &&b: int) -> int { - a - b + fn sub(a: &int, +b: int) -> int { + *a - b } let mut v = ~[1, 2, 3, 4]; let sum = foldr(v, 0, sub); @@ -2419,23 +2491,23 @@ mod tests { } #[test] - fn test_permute() { + fn test_each_permutation() { let mut results: ~[~[int]]; results = ~[]; - permute(~[], |v| results.push(copy v)); + for each_permutation(~[]) |v| { results.push(from_slice(v)); } assert results == ~[~[]]; results = ~[]; - permute(~[7], |v| results.push(copy v)); + for each_permutation(~[7]) |v| { results.push(from_slice(v)); } assert results == ~[~[7]]; results = ~[]; - permute(~[1,1], |v| results.push(copy v)); + for each_permutation(~[1,1]) |v| { results.push(from_slice(v)); } assert results == ~[~[1,1],~[1,1]]; results = ~[]; - permute(~[5,2,0], |v| results.push(copy v)); + for each_permutation(~[5,2,0]) |v| { results.push(from_slice(v)); } assert results == ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]; } @@ -2487,19 +2559,19 @@ mod tests { #[test] fn test_position_elem() { - assert position_elem(~[], 1).is_none(); + assert position_elem(~[], &1).is_none(); let v1 = ~[1, 2, 3, 3, 2, 5]; - assert position_elem(v1, 1) == Some(0u); - assert position_elem(v1, 2) == Some(1u); - assert position_elem(v1, 5) == Some(5u); - assert position_elem(v1, 4).is_none(); + assert position_elem(v1, &1) == Some(0u); + assert position_elem(v1, &2) == Some(1u); + assert position_elem(v1, &5) == Some(5u); + assert position_elem(v1, &4).is_none(); } #[test] fn test_position() { - fn less_than_three(&&i: int) -> bool { return i < 3; } - fn is_eighteen(&&i: int) -> bool { return i == 18; } + fn less_than_three(i: &int) -> bool { return *i < 3; } + fn is_eighteen(i: &int) -> bool { return *i == 18; } assert position(~[], less_than_three).is_none(); @@ -2512,7 +2584,7 @@ mod tests { fn test_position_between() { assert position_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert position_between(v, 0u, 0u, f).is_none(); @@ -2540,8 +2612,8 @@ mod tests { fn test_find() { assert find(~[], f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } + fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert find(v, f) == Some((1, 'b')); @@ -2552,7 +2624,7 @@ mod tests { fn test_find_between() { assert find_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert find_between(v, 0u, 0u, f).is_none(); @@ -2580,8 +2652,8 @@ mod tests { fn test_rposition() { assert find(~[], f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } + fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert position(v, f) == Some(1u); @@ -2592,7 +2664,7 @@ mod tests { fn test_rposition_between() { assert rposition_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert rposition_between(v, 0u, 0u, f).is_none(); @@ -2620,8 +2692,8 @@ mod tests { fn test_rfind() { assert rfind(~[], f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } + fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert rfind(v, f) == Some((3, 'b')); @@ -2632,7 +2704,7 @@ mod tests { fn test_rfind_between() { assert rfind_between(~[], 0u, 0u, f).is_none(); - fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } + fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } let mut v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; assert rfind_between(v, 0u, 0u, f).is_none(); @@ -2692,7 +2764,7 @@ mod tests { #[test] fn test_split() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert split(~[], f) == ~[]; assert split(~[1, 2], f) == ~[~[1, 2]]; @@ -2703,7 +2775,7 @@ mod tests { #[test] fn test_splitn() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert splitn(~[], 1u, f) == ~[]; assert splitn(~[1, 2], 1u, f) == ~[~[1, 2]]; @@ -2715,7 +2787,7 @@ mod tests { #[test] fn test_rsplit() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert rsplit(~[], f) == ~[]; assert rsplit(~[1, 2], f) == ~[~[1, 2]]; @@ -2725,7 +2797,7 @@ mod tests { #[test] fn test_rsplitn() { - fn f(&&x: int) -> bool { x == 3 } + fn f(x: &int) -> bool { *x == 3 } assert rsplitn(~[], 1u, f) == ~[]; assert rsplitn(~[1, 2], 1u, f) == ~[~[1, 2]]; @@ -2748,9 +2820,9 @@ mod tests { #[test] fn test_connect() { - assert connect(~[], 0) == ~[]; - assert connect(~[~[1], ~[2, 3]], 0) == ~[1, 0, 2, 3]; - assert connect(~[~[1], ~[2], ~[3]], 0) == ~[1, 0, 2, 0, 3]; + assert connect(~[], &0) == ~[]; + assert connect(~[~[1], ~[2, 3]], &0) == ~[1, 0, 2, 3]; + assert connect(~[~[1], ~[2], ~[3]], &0) == ~[1, 0, 2, 0, 3]; } #[test] @@ -2796,7 +2868,7 @@ mod tests { #[test] fn test_unshift() { let mut x = ~[1, 2, 3]; - unshift(x, 0); + x.unshift(0); assert x == ~[0, 1, 2, 3]; } @@ -2804,10 +2876,10 @@ mod tests { fn test_capacity() { let mut v = ~[0u64]; reserve(&mut v, 10u); - assert capacity(v) == 10u; + assert capacity(&v) == 10u; let mut v = ~[0u32]; reserve(&mut v, 10u); - assert capacity(v) == 10u; + assert capacity(&v) == 10u; } #[test] @@ -3012,7 +3084,7 @@ mod tests { #[should_fail] fn test_grow_fn_fail() { let mut v = ~[]; - do grow_fn(v, 100) |i| { + do v.grow_fn(100) |i| { if i == 50 { fail } @@ -3318,7 +3390,7 @@ mod tests { fn test_permute_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - do permute(v) |_elt| { + for each_permutation(v) |_elt| { if i == 2 { fail } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 3f6bcd31a73..59de3631118 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -217,7 +217,7 @@ impl Writer { } fn end_tag() { - let last_size_pos = vec::pop::(self.size_positions); + let last_size_pos = self.size_positions.pop(); let cur_pos = self.writer.tell(); self.writer.seek(last_size_pos as int, io::SeekSet); let size = (cur_pos - last_size_pos - 4u); diff --git a/src/libstd/ebml2.rs b/src/libstd/ebml2.rs index 496010d579e..21a7d7817c9 100644 --- a/src/libstd/ebml2.rs +++ b/src/libstd/ebml2.rs @@ -226,7 +226,7 @@ impl Serializer { } fn end_tag() { - let last_size_pos = vec::pop::(self.size_positions); + let last_size_pos = self.size_positions.pop(); let cur_pos = self.writer.tell(); self.writer.seek(last_size_pos as int, io::SeekSet); let size = (cur_pos - last_size_pos - 4u); diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 8d27ea5783b..a04eadb7732 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -428,9 +428,8 @@ fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::(vals) == 0u { return None::<~str>; } return match vals[0] { - Val(copy s) => - Some::<~str>(s), - _ => None::<~str> + Val(copy s) => Some(s), + _ => None }; } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 059b5c22545..247c13396d0 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -696,7 +696,7 @@ priv impl Deserializer { fn pop(&self) -> &self/Json { if self.stack.len() == 0 { self.stack.push(&self.json); } - vec::pop(self.stack) + self.stack.pop() } } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 1568c6c099f..2a7019f5a58 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -13,7 +13,7 @@ enum List { /// Cregate a list from a vector fn from_vec(v: &[T]) -> @List { - vec::foldr(v, @Nil::, |h, t| @Cons(h, t)) + vec::foldr(v, @Nil::, |h, t| @Cons(*h, t)) } /** diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 202ca548d6b..5b2ea0a84a6 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -163,7 +163,7 @@ mod v4 { if vec::len(parts) != 4u { result::Err(fmt!("'%s' doesn't have 4 parts", ip)) } - else if vec::contains(parts, 256u) { + else if vec::contains(parts, &256u) { result::Err(fmt!("invalid octal in addr '%s'", ip)) } else { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index f8347be3d08..699fec961c4 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -800,7 +800,7 @@ impl TcpSocketBuf: io::Reader { if self.read(bytes, 1u) == 0 { fail } else { bytes[0] as int } } fn unread_byte(amt: int) { - vec::unshift((*(self.data)).buf, amt as u8); + self.data.buf.unshift(amt as u8); } fn eof() -> bool { false // noop diff --git a/src/libstd/par.rs b/src/libstd/par.rs index a0c9a1b92fe..9cfcd8c2acb 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -123,17 +123,17 @@ pub fn alli(xs: ~[A], f: fn~(uint, A) -> bool) -> bool { do vec::all(map_slices(xs, || { fn~(base: uint, slice : &[A], copy f) -> bool { vec::alli(slice, |i, x| { - f(i + base, x) + f(i + base, *x) }) } - })) |x| { x } + })) |x| { *x } } /// Returns true if the function holds for any elements in the vector. pub fn any(xs: ~[A], f: fn~(A) -> bool) -> bool { do vec::any(map_slices(xs, || { fn~(_base : uint, slice: &[A], copy f) -> bool { - vec::any(slice, |x| f(x)) + vec::any(slice, |x| f(*x)) } - })) |x| { x } + })) |x| { *x } } diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index e3927ef188c..1100485e7f1 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -30,7 +30,7 @@ fn mk() -> SmallIntMap { #[inline(always)] fn insert(self: SmallIntMap, key: uint, +val: T) { //io::println(fmt!("%?", key)); - self.v.grow_set_elt(key, None, Some(val)); + self.v.grow_set_elt(key, &None, Some(val)); } /** diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 9ea43177cea..691f0e840e6 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -358,7 +358,7 @@ fn filter_tests(opts: &TestOpts, } else { return option::None; } } - vec::filter_map(filtered, |x| filter_fn(&x, filter_str)) + vec::filter_map(filtered, |x| filter_fn(x, filter_str)) }; // Maybe pull out the ignored test and unignore them @@ -374,7 +374,7 @@ fn filter_tests(opts: &TestOpts, } else { return option::None; } }; - vec::filter_map(filtered, |x| filter(&x)) + vec::filter_map(filtered, |x| filter(x)) }; // Sort the tests alphabetically diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index b6d4c2d0fe3..d05c6eadaf6 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -278,7 +278,7 @@ fn map_item(i: @item, cx: ctx, v: vt) { _ => cx.path.push(path_name(i.ident)) } visit::visit_item(i, cx, v); - vec::pop(cx.path); + cx.path.pop(); } fn map_struct_def(struct_def: @ast::struct_def, parent_node: ast_node, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index a2c935ea6f4..2431947184d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -275,14 +275,14 @@ fn ident_to_path(s: span, +i: ident) -> @path { rp: None, types: ~[]} } -pure fn is_unguarded(&&a: arm) -> bool { +pure fn is_unguarded(a: &arm) -> bool { match a.guard { None => true, _ => false } } -pure fn unguarded_pat(a: arm) -> Option<~[@pat]> { +pure fn unguarded_pat(a: &arm) -> Option<~[@pat]> { if is_unguarded(a) { Some(/* FIXME (#2543) */ copy a.pats) } else { None } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 7ef34d8eb0b..d08edd7af1d 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -163,9 +163,9 @@ fn get_name_value_str_pair(item: @ast::meta_item) -> Option<(~str, ~str)> { fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) -> ~[ast::attribute] { let filter = ( - fn@(a: ast::attribute) -> Option { - if get_attr_name(a) == name { - option::Some(a) + fn@(a: &ast::attribute) -> Option { + if get_attr_name(*a) == name { + option::Some(*a) } else { option::None } } ); @@ -175,9 +175,9 @@ fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) -> /// Searcha list of meta items and return only those with a specific name fn find_meta_items_by_name(metas: ~[@ast::meta_item], name: ~str) -> ~[@ast::meta_item] { - let filter = fn@(&&m: @ast::meta_item) -> Option<@ast::meta_item> { - if get_meta_item_name(m) == name { - option::Some(m) + let filter = fn@(m: &@ast::meta_item) -> Option<@ast::meta_item> { + if get_meta_item_name(*m) == name { + option::Some(*m) } else { option::None } }; return vec::filter_map(metas, filter); @@ -289,8 +289,8 @@ fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ~str) -> ~[@ast::meta_item] { return vec::filter_map(items, |item| { - if get_meta_item_name(item) != name { - option::Some(/* FIXME (#2543) */ copy item) + if get_meta_item_name(*item) != name { + option::Some(/* FIXME (#2543) */ copy *item) } else { option::None } diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 4ebb8501041..fa14d3b5e99 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -90,8 +90,8 @@ fn expand(cx: ext_ctxt, span: span, _mitem: ast::meta_item, in_items: ~[@ast::item]) -> ~[@ast::item] { - fn not_auto_serialize(a: ast::attribute) -> bool { - attr::get_attr_name(a) != ~"auto_serialize" + fn not_auto_serialize(a: &ast::attribute) -> bool { + attr::get_attr_name(*a) != ~"auto_serialize" } fn filter_attrs(item: @ast::item) -> @ast::item { @@ -102,12 +102,12 @@ fn expand(cx: ext_ctxt, do vec::flat_map(in_items) |in_item| { match in_item.node { ast::item_ty(ty, tps) => { - vec::append(~[filter_attrs(in_item)], + vec::append(~[filter_attrs(*in_item)], ty_fns(cx, in_item.ident, ty, tps)) } ast::item_enum(enum_definition, tps) => { - vec::append(~[filter_attrs(in_item)], + vec::append(~[filter_attrs(*in_item)], enum_fns(cx, in_item.ident, in_item.span, enum_definition.variants, tps)) } @@ -116,7 +116,7 @@ fn expand(cx: ext_ctxt, cx.span_err(span, ~"#[auto_serialize] can only be \ applied to type and enum \ definitions"); - ~[in_item] + ~[*in_item] } } } diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index b51184eefd8..099ba67713f 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -75,8 +75,8 @@ fn expand(cx: ext_ctxt, span: span, _mitem: ast::meta_item, in_items: ~[@ast::item]) -> ~[@ast::item] { - fn not_auto_serialize2(a: ast::attribute) -> bool { - attr::get_attr_name(a) != ~"auto_serialize2" + fn not_auto_serialize2(a: &ast::attribute) -> bool { + attr::get_attr_name(*a) != ~"auto_serialize2" } fn filter_attrs(item: @ast::item) -> @ast::item { @@ -88,19 +88,19 @@ fn expand(cx: ext_ctxt, match item.node { ast::item_ty(@{node: ast::ty_rec(fields), _}, tps) => { ~[ - filter_attrs(item), + filter_attrs(*item), mk_rec_impl(cx, item.span, item.ident, fields, tps), ] }, ast::item_class(@{ fields, _}, tps) => { ~[ - filter_attrs(item), + filter_attrs(*item), mk_struct_impl(cx, item.span, item.ident, fields, tps), ] }, ast::item_enum(enum_def, tps) => { ~[ - filter_attrs(item), + filter_attrs(*item), mk_enum_impl(cx, item.span, item.ident, enum_def, tps), ] }, @@ -108,7 +108,7 @@ fn expand(cx: ext_ctxt, cx.span_err(span, ~"#[auto_serialize2] can only be applied \ to structs, record types, and enum \ definitions"); - ~[item] + ~[*item] } } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 566cdc4fa21..5f4d86b9860 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -161,7 +161,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess, fn print_backtrace() { } fn backtrace() -> expn_info { self.backtrace } fn mod_push(i: ast::ident) { self.mod_path.push(i); } - fn mod_pop() { vec::pop(self.mod_path); } + fn mod_pop() { self.mod_path.pop(); } fn mod_path() -> ~[ast::ident] { return self.mod_path; } fn bt_push(ei: codemap::expn_info_) { match ei { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index dbe475c1b50..22e2cfcde6b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -144,7 +144,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, // decorated with "item decorators", then use that function to transform // the item into a new set of items. let new_items = do vec::flat_map(module_.items) |item| { - do vec::foldr(item.attrs, ~[item]) |attr, items| { + do vec::foldr(item.attrs, ~[*item]) |attr, items| { let mname = match attr.node.value.node { ast::meta_word(n) => n, ast::meta_name_value(n, _) => n, @@ -160,7 +160,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, } }; - return {items: new_items,.. module_}; + return {items: new_items, ..module_}; } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index f93fa830f92..b9b1484ce5a 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -47,7 +47,7 @@ impl message: gen_send { let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); let args_ast = (arg_names, tys).map( - |n, t| cx.arg_mode(n, t, ast::by_copy) + |n, t| cx.arg_mode(*n, *t, ast::by_copy) ); let pipe_ty = cx.ty_path_ast_builder( @@ -129,7 +129,7 @@ impl message: gen_send { let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str())); let args_ast = (arg_names, tys).map( - |n, t| cx.arg_mode(cx.ident_of(n), t, ast::by_copy) + |n, t| cx.arg_mode(cx.ident_of(*n), *t, ast::by_copy) ); let args_ast = vec::append( diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index 51239754635..e16e1c55349 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -307,7 +307,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint], while idx < rc { idx_path.push(idx); res.push(recur(repeat_me)); // whew! - vec::pop(*idx_path); + idx_path.pop(); idx += 1u; } } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 737694337e3..16e3454ca2c 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -219,7 +219,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) /* we append new items to this while we go */ while cur_eis.len() > 0u { /* for each Earley Item */ - let mut ei = vec::pop(cur_eis); + let mut ei = cur_eis.pop(); let idx = ei.idx; let len = ei.elts.len(); @@ -350,13 +350,13 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher]) } else if (next_eis.len() > 0u) { /* Now process the next token */ while(next_eis.len() > 0u) { - cur_eis.push(vec::pop(next_eis)); + cur_eis.push(next_eis.pop()); } rdr.next_token(); } else /* bb_eis.len() == 1 */ { let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE); - let ei = vec::pop(bb_eis); + let ei = bb_eis.pop(); match ei.elts[ei.idx].node { match_nonterminal(_, name, idx) => { ei.matches[idx].push(@matched_nonterminal( diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 558593579bf..a8a41cca6cb 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -82,13 +82,13 @@ pure fn dup_tt_reader(&&r: tt_reader) -> tt_reader { pure fn lookup_cur_matched_by_matched(r: tt_reader, start: @named_match) -> @named_match { - pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match { + pure fn red(+ad: @named_match, idx: &uint) -> @named_match { match *ad { matched_nonterminal(_) => { // end of the line; duplicate henceforth ad } - matched_seq(ads, _) => ads[idx] + matched_seq(ads, _) => ads[*idx] } } vec::foldl(start, r.repeat_idx, red) @@ -122,8 +122,8 @@ fn lockstep_iter_size(t: token_tree, r: tt_reader) -> lis { } match t { tt_delim(tts) | tt_seq(_, tts, _, _) => { - vec::foldl(lis_unconstrained, tts, {|lis, tt| - lis_merge(lis, lockstep_iter_size(tt, r), r) }) + vec::foldl(lis_unconstrained, tts, |lis, tt| + lis_merge(lis, lockstep_iter_size(*tt, r), r)) } tt_tok(*) => lis_unconstrained, tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { @@ -148,7 +148,8 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} { } tt_frame_up(Some(tt_f)) => { if r.cur.dotdotdoted { - vec::pop(r.repeat_idx); vec::pop(r.repeat_len); + r.repeat_idx.pop(); + r.repeat_len.pop(); } r.cur = tt_f; diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 4f3dafcb21b..088df01985e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -552,7 +552,7 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { // ...nor do modules fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod { return {view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)), - items: vec::filter_map(m.items, |x| fld.fold_item(x))}; + items: vec::filter_map(m.items, |x| fld.fold_item(*x))}; } fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5d1067da762..240c9f34c81 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1111,7 +1111,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { ast::expr_call(func, args, has_block) => { let mut base_args = args; let blk = if has_block { - let blk_arg = vec::pop(base_args); + let blk_arg = base_args.pop(); match blk_arg.node { ast::expr_loop_body(_) => { head(s, ~"for"); } ast::expr_do_body(_) => { head(s, ~"do"); } diff --git a/src/rustc/driver/rustc.rs b/src/rustc/driver/rustc.rs index 38ce7a4fbac..8b1202e632e 100644 --- a/src/rustc/driver/rustc.rs +++ b/src/rustc/driver/rustc.rs @@ -122,7 +122,7 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) { logging::console_off(); let mut args = args; - let binary = vec::shift(args); + let binary = args.shift(); if vec::len(args) == 0u { usage(binary); return; } diff --git a/src/rustc/front/config.rs b/src/rustc/front/config.rs index 7e0d9ec2e86..4577b54fb5c 100644 --- a/src/rustc/front/config.rs +++ b/src/rustc/front/config.rs @@ -50,13 +50,12 @@ fn filter_view_item(cx: ctxt, &&view_item: @ast::view_item fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { - let item_filter = |a| filter_item(cx, a); - let filtered_items = vec::filter_map(m.items, item_filter); - let view_item_filter = |a| filter_view_item(cx, a); - let filtered_view_items = vec::filter_map(m.view_items, view_item_filter); + let filtered_items = vec::filter_map(m.items, |a| filter_item(cx, *a)); + let filtered_view_items = vec::filter_map(m.view_items, + |a| filter_view_item(cx, *a)); return { view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)), - items: vec::filter_map(filtered_items, |x| fld.fold_item(x)) + items: vec::filter_map(filtered_items, |x| fld.fold_item(*x)) }; } @@ -69,11 +68,10 @@ fn filter_foreign_item(cx: ctxt, &&item: @ast::foreign_item) -> fn fold_foreign_mod(cx: ctxt, nm: ast::foreign_mod, fld: fold::ast_fold) -> ast::foreign_mod { - let item_filter = |a| filter_foreign_item(cx, a); - let filtered_items = vec::filter_map(nm.items, item_filter); - let view_item_filter = |a| filter_view_item(cx, a); - let filtered_view_items = vec::filter_map( - nm.view_items, view_item_filter); + let filtered_items = vec::filter_map(nm.items, + |a| filter_foreign_item(cx, *a)); + let filtered_view_items = vec::filter_map(nm.view_items, + |a| filter_view_item(cx, *a)); return { sort: nm.sort, view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)), @@ -100,8 +98,7 @@ fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) -> fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { - let filter = |a| filter_stmt(cx, a); - let filtered_stmts = vec::filter_map(b.stmts, filter); + let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a)); return {view_items: b.view_items, stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)), expr: option::map(&b.expr, |x| fld.fold_expr(*x)), @@ -136,7 +133,7 @@ fn metas_in_cfg(cfg: ast::crate_cfg, metas: ~[@ast::meta_item]) -> bool { // so we can match against them. This is the list of configurations for // which the item is valid let cfg_metas = vec::concat(vec::filter_map(cfg_metas, - |&&i| attr::get_meta_item_list(i) )); + |i| attr::get_meta_item_list(*i))); let has_cfg_metas = vec::len(cfg_metas) > 0u; if !has_cfg_metas { return true; } diff --git a/src/rustc/front/test.rs b/src/rustc/front/test.rs index 55d71ab6950..952d7b9ab79 100644 --- a/src/rustc/front/test.rs +++ b/src/rustc/front/test.rs @@ -81,8 +81,8 @@ fn fold_mod(cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { } let mod_nomain = - {view_items: m.view_items, items: vec::filter_map(m.items, - |i| nomain(cx, i))}; + {view_items: m.view_items, + items: vec::filter_map(m.items, |i| nomain(cx, *i))}; return fold::noop_fold_mod(mod_nomain, fld); } @@ -122,7 +122,7 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) -> } let res = fold::noop_fold_item(i, fld); - vec::pop(cx.path); + cx.path.pop(); return res; } @@ -152,7 +152,7 @@ fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool { let ignoreattrs = attr::find_attrs_by_name(i.attrs, ~"ignore"); let ignoreitems = attr::attr_metas(ignoreattrs); let cfg_metas = vec::concat(vec::filter_map(ignoreitems, - |&&i| attr::get_meta_item_list(i) )); + |i| attr::get_meta_item_list(*i))); return if vec::is_not_empty(ignoreitems) { config::metas_in_cfg(cx.crate.node.config, cfg_metas) } else { diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index 49e79e009da..483f7ea06a9 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -114,7 +114,7 @@ fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) { } fn add_used_crate_file(cstore: cstore, lib: &Path) { - if !vec::contains(p(cstore).used_crate_files, copy *lib) { + if !vec::contains(p(cstore).used_crate_files, lib) { p(cstore).used_crate_files.push(copy *lib); } } @@ -126,7 +126,7 @@ fn get_used_crate_files(cstore: cstore) -> ~[Path] { fn add_used_library(cstore: cstore, lib: ~str) -> bool { assert lib != ~""; - if vec::contains(p(cstore).used_libraries, lib) { return false; } + if vec::contains(p(cstore).used_libraries, &lib) { return false; } p(cstore).used_libraries.push(lib); return true; } diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index d7fd8036c46..0e6bc2aee15 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -980,7 +980,7 @@ fn get_crate_module_paths(intr: @ident_interner, cdata: cmd) res.push((did, path)); } return do vec::filter(res) |x| { - let (_, xp) = x; + let (_, xp) = *x; mods.contains_key(xp) } } diff --git a/src/rustc/middle/borrowck/check_loans.rs b/src/rustc/middle/borrowck/check_loans.rs index 841d54c6b0d..b2469718140 100644 --- a/src/rustc/middle/borrowck/check_loans.rs +++ b/src/rustc/middle/borrowck/check_loans.rs @@ -527,7 +527,7 @@ impl check_loan_ctxt { do vec::iter2(args, arg_tys) |arg, arg_ty| { match ty::resolved_mode(self.tcx(), arg_ty.mode) { ast::by_move => { - self.check_move_out(arg); + self.check_move_out(*arg); } ast::by_mutbl_ref | ast::by_ref | ast::by_copy | ast::by_val => { diff --git a/src/rustc/middle/borrowck/gather_loans.rs b/src/rustc/middle/borrowck/gather_loans.rs index b3f846d47fd..85eae29529f 100644 --- a/src/rustc/middle/borrowck/gather_loans.rs +++ b/src/rustc/middle/borrowck/gather_loans.rs @@ -116,11 +116,11 @@ fn req_loans_in_expr(ex: @ast::expr, do vec::iter2(args, arg_tys) |arg, arg_ty| { match ty::resolved_mode(self.tcx(), arg_ty.mode) { ast::by_mutbl_ref => { - let arg_cmt = self.bccx.cat_expr(arg); + let arg_cmt = self.bccx.cat_expr(*arg); self.guarantee_valid(arg_cmt, m_mutbl, scope_r); } ast::by_ref => { - let arg_cmt = self.bccx.cat_expr(arg); + let arg_cmt = self.bccx.cat_expr(*arg); self.guarantee_valid(arg_cmt, m_imm, scope_r); } ast::by_val => { diff --git a/src/rustc/middle/check_alt.rs b/src/rustc/middle/check_alt.rs index a3e85ac56c3..efbeb490db9 100644 --- a/src/rustc/middle/check_alt.rs +++ b/src/rustc/middle/check_alt.rs @@ -195,7 +195,7 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful { } } Some(ctor) => { - match is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ), + match is_useful(tcx, vec::filter_map(m, |r| default(tcx, *r) ), vec::tail(v)) { useful_ => useful(left_ty, ctor), u => u @@ -212,7 +212,7 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful { fn is_useful_specialized(tcx: ty::ctxt, m: matrix, v: ~[@pat], ctor: ctor, arity: uint, lty: ty::t) -> useful { - let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) ); + let ms = vec::filter_map(m, |r| specialize(tcx, *r, ctor, arity, lty) ); let could_be_useful = is_useful( tcx, ms, specialize(tcx, v, ctor, arity, lty).get()); match could_be_useful { @@ -269,7 +269,9 @@ fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> Option { let mut found = ~[]; for m.each |r| { do option::iter(&pat_ctor_id(tcx, r[0])) |id| { - if !vec::contains(found, *id) { found.push(*id); } + if !vec::contains(found, id) { + found.push(*id); + } } } let variants = ty::enum_variants(tcx, eid); diff --git a/src/rustc/middle/const_eval.rs b/src/rustc/middle/const_eval.rs index 463bf502036..5def18cacc3 100644 --- a/src/rustc/middle/const_eval.rs +++ b/src/rustc/middle/const_eval.rs @@ -41,7 +41,7 @@ enum constness { } fn join(a: constness, b: constness) -> constness { - match (a,b) { + match (a, b) { (integral_const, integral_const) => integral_const, (integral_const, general_const) | (general_const, integral_const) @@ -51,7 +51,7 @@ fn join(a: constness, b: constness) -> constness { } fn join_all(cs: &[constness]) -> constness { - vec::foldl(integral_const, cs, join) + vec::foldl(integral_const, cs, |a, b| join(a, *b)) } fn classify(e: @expr, diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index 15a7d8f52b1..b1323d7fc93 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -273,7 +273,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt) { *bounds, (*bounds).len()); } do vec::iter2(*ts, *bounds) |ty, bound| { - check_bounds(cx, id_to_use, e.span, ty, bound) + check_bounds(cx, id_to_use, e.span, *ty, *bound) } } @@ -377,7 +377,7 @@ fn check_ty(aty: @ty, cx: ctx, v: visit::vt) { let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id)); let bounds = ty::lookup_item_type(cx.tcx, did).bounds; do vec::iter2(*ts, *bounds) |ty, bound| { - check_bounds(cx, aty.id, aty.span, ty, bound) + check_bounds(cx, aty.id, aty.span, *ty, *bound) } } } diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index ce998378fe5..689f69f1ad0 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -955,7 +955,7 @@ impl Liveness { fn propagate_through_block(blk: blk, succ: LiveNode) -> LiveNode { let succ = self.propagate_through_opt_expr(blk.node.expr, succ); do blk.node.stmts.foldr(succ) |stmt, succ| { - self.propagate_through_stmt(stmt, succ) + self.propagate_through_stmt(*stmt, succ) } } @@ -975,7 +975,7 @@ impl Liveness { match decl.node { decl_local(locals) => { do locals.foldr(succ) |local, succ| { - self.propagate_through_local(local, succ) + self.propagate_through_local(*local, succ) } } decl_item(_) => { @@ -1007,7 +1007,7 @@ impl Liveness { fn propagate_through_exprs(exprs: ~[@expr], succ: LiveNode) -> LiveNode { do exprs.foldr(succ) |expr, succ| { - self.propagate_through_expr(expr, succ) + self.propagate_through_expr(*expr, succ) } } @@ -1575,7 +1575,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) { match ty::resolved_mode(self.tcx, arg_ty.mode) { by_val | by_copy | by_ref | by_mutbl_ref => {} by_move => { - self.check_move_from_expr(arg_expr, vt); + self.check_move_from_expr(*arg_expr, vt); } } } diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 03efd67a9d5..fc66b5dc7a1 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -1560,7 +1560,7 @@ impl Resolver { path_entry.def_like); let mut pieces = split_str(path_entry.path_string, ~"::"); - let final_ident_str = pop(pieces); + let final_ident_str = pieces.pop(); let final_ident = self.session.ident_of(final_ident_str); // Find the module we need, creating modules along the way if we diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 165ca8e2fc4..6450e48486c 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -581,7 +581,7 @@ fn collect_record_or_struct_fields(m: &[@Match], col: uint) -> ~[ast::ident] { fn extend(idents: &mut ~[ast::ident], field_pats: &[ast::field_pat]) { for field_pats.each |field_pat| { let field_ident = field_pat.ident; - if !vec::any(*idents, |x| x == field_ident) { + if !vec::any(*idents, |x| *x == field_ident) { idents.push(field_ident); } } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 7c70d83bd76..70231357003 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -57,7 +57,7 @@ struct icx_popper { ccx: @crate_ctxt, drop { if self.ccx.sess.count_llvm_insns() { - vec::pop(*(self.ccx.stats.llvm_insn_ctxt)); + self.ccx.stats.llvm_insn_ctxt.pop(); } } } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index e75d4db897f..907146be4fd 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -402,7 +402,7 @@ fn revoke_clean(cx: block, val: ValueRef) { do in_scope_cx(cx) |info| { let cleanup_pos = vec::position( info.cleanups, - |cu| match cu { + |cu| match *cu { clean_temp(v, _, _) if v == val => true, _ => false }); diff --git a/src/rustc/middle/trans/controlflow.rs b/src/rustc/middle/trans/controlflow.rs index 5d8b0fbbbe1..68ebf5fa189 100644 --- a/src/rustc/middle/trans/controlflow.rs +++ b/src/rustc/middle/trans/controlflow.rs @@ -158,7 +158,7 @@ fn trans_log(log_ex: @ast::expr, let modpath = vec::append( ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))], vec::filter(bcx.fcx.path, |e| - match e { path_mod(_) => true, _ => false } + match *e { path_mod(_) => true, _ => false } )); let modname = path_str(ccx.sess, modpath); diff --git a/src/rustc/middle/trans/foreign.rs b/src/rustc/middle/trans/foreign.rs index f1077912fec..74dadd2cab4 100644 --- a/src/rustc/middle/trans/foreign.rs +++ b/src/rustc/middle/trans/foreign.rs @@ -92,7 +92,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { Double => 8, Struct => { do vec::foldl(0, struct_tys(ty)) |a, t| { - uint::max(a, ty_align(t)) + uint::max(a, ty_align(*t)) } } Array => { @@ -113,7 +113,7 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] { Double => 8, Struct => { do vec::foldl(0, struct_tys(ty)) |s, t| { - s + ty_size(t) + s + ty_size(*t) } } Array => { diff --git a/src/rustc/middle/trans/monomorphize.rs b/src/rustc/middle/trans/monomorphize.rs index bbcacec052e..cd8cffa297a 100644 --- a/src/rustc/middle/trans/monomorphize.rs +++ b/src/rustc/middle/trans/monomorphize.rs @@ -33,7 +33,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len()); let hash_id = make_mono_id(ccx, fn_id, substs, vtables, Some(param_uses)); if vec::any(hash_id.params, - |p| match p { mono_precise(_, _) => false, _ => true }) { + |p| match *p { mono_precise(_, _) => false, _ => true }) { must_cast = true; } @@ -243,7 +243,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], let mut i = 0u; vec::map2(*bounds, substs, |bounds, subst| { let mut v = ~[]; - for vec::each(*bounds) |bound| { + for bounds.each |bound| { match *bound { ty::bound_trait(_) => { v.push(meth::vtable_id(ccx, vts[i])); @@ -252,7 +252,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], _ => () } } - (subst, if v.len() > 0u { Some(v) } else { None }) + (*subst, if v.len() > 0u { Some(v) } else { None }) }) } None => { @@ -262,12 +262,12 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t], let param_ids = match param_uses { Some(uses) => { vec::map2(precise_param_ids, uses, |id, uses| { - match id { + match *id { (a, b@Some(_)) => mono_precise(a, b), (subst, None) => { - if uses == 0u { + if *uses == 0u { mono_any - } else if uses == type_use::use_repr && + } else if *uses == type_use::use_repr && !ty::type_needs_drop(ccx.tcx, subst) { let llty = type_of::type_of(ccx, subst); diff --git a/src/rustc/middle/trans/type_use.rs b/src/rustc/middle/trans/type_use.rs index b29f40748ed..f0d67b92339 100644 --- a/src/rustc/middle/trans/type_use.rs +++ b/src/rustc/middle/trans/type_use.rs @@ -206,7 +206,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id)); vec::iter2(type_uses_for(cx.ccx, id, ts.len()), *ts, |uses, subst| { - type_needs(cx, uses, subst) + type_needs(cx, *uses, *subst) }) } } @@ -239,7 +239,7 @@ fn mark_for_expr(cx: ctx, e: @expr) { typeck::method_static(did) => { do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| { do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), *ts) - |uses, subst| { type_needs(cx, uses, subst)} + |uses, subst| { type_needs(cx, *uses, *subst)} } } typeck::method_param({param_num: param, _}) => { diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 63720eaad2e..397a1cd6aa1 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -2238,7 +2238,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { false } - ty_class(did, _) if vec::contains(*seen, did) => { + ty_class(ref did, _) if vec::contains(*seen, did) => { false } @@ -2246,15 +2246,15 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { seen.push(did); let r = vec::any(class_items_as_fields(cx, did, substs), |f| type_requires(cx, seen, r_ty, f.mt.ty)); - vec::pop(*seen); + seen.pop(); r } ty_tup(ts) => { - vec::any(ts, |t| type_requires(cx, seen, r_ty, t)) + vec::any(ts, |t| type_requires(cx, seen, r_ty, *t)) } - ty_enum(did, _) if vec::contains(*seen, did) => { + ty_enum(ref did, _) if vec::contains(*seen, did) => { false } @@ -2263,11 +2263,11 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool { let vs = enum_variants(cx, did); let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| { vec::any(variant.args, |aty| { - let sty = subst(cx, substs, aty); + let sty = subst(cx, substs, *aty); type_requires(cx, seen, r_ty, sty) }) }); - vec::pop(*seen); + seen.pop(); r } }; @@ -3063,7 +3063,7 @@ fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) { if !type_needs_infer(rt) { return; } // Occurs check! - if vec::contains(vars_in_type(rt), vid) { + if vec::contains(vars_in_type(rt), &vid) { // Maybe this should be span_err -- however, there's an // assertion later on that the type doesn't contain // variables, so in this case we have to be sure to die. diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index e1a0e8bc9ed..a1cfb91ebdc 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -309,7 +309,7 @@ fn check_fn(ccx: @crate_ctxt, fcx.write_ty(info.self_id, info.self_ty); } do vec::iter2(decl.inputs, arg_tys) |input, arg| { - fcx.write_ty(input.id, arg); + fcx.write_ty(input.id, *arg); } // If we don't have any enclosing function scope, it is time to @@ -352,7 +352,7 @@ fn check_fn(ccx: @crate_ctxt, // Add formal parameters. do vec::iter2(arg_tys, decl.inputs) |arg_ty, input| { - assign(input.ty.span, input.id, Some(arg_ty)); + assign(input.ty.span, input.id, Some(*arg_ty)); debug!("Argument %s is assigned to %s", tcx.sess.str_of(input.ident), fcx.inh.locals.get(input.id).to_str()); @@ -807,7 +807,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) { _ => () } } - ty::ty_enum(did, _) => { + ty::ty_enum(ref did, _) => { // Watch out for a type like `enum t = @t`. Such a // type would otherwise infinitely auto-deref. Only // autoderef loops during typeck (basically, this one @@ -818,7 +818,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> (ty::t, uint) { if vec::contains(enum_dids, did) { return (t1, autoderefs); } - enum_dids.push(did); + enum_dids.push(*did); } _ => { /*ok*/ } } @@ -2294,7 +2294,7 @@ fn check_enum_variants(ccx: @crate_ctxt, } _ => () } - if vec::contains(*disr_vals, *disr_val) { + if vec::contains(*disr_vals, &*disr_val) { ccx.tcx.sess.span_err(v.span, ~"discriminator value already exists"); } diff --git a/src/rustc/middle/typeck/check/alt.rs b/src/rustc/middle/typeck/check/alt.rs index 3b299caf872..ace045ec4a7 100644 --- a/src/rustc/middle/typeck/check/alt.rs +++ b/src/rustc/middle/typeck/check/alt.rs @@ -165,7 +165,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, do subpats.iter() |pats| { do vec::iter2(*pats, arg_types) |subpat, arg_ty| { - check_pat(pcx, subpat, arg_ty); + check_pat(pcx, *subpat, *arg_ty); } }; } else if subpats_len > 0u { diff --git a/src/rustc/middle/typeck/check/vtable.rs b/src/rustc/middle/typeck/check/vtable.rs index 38ca571dae5..06f466f74d5 100644 --- a/src/rustc/middle/typeck/check/vtable.rs +++ b/src/rustc/middle/typeck/check/vtable.rs @@ -23,7 +23,7 @@ use util::common::indenter; fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool { vec::any(tps, |bs| { - vec::any(*bs, |b| { + bs.any(|b| { match b { ty::bound_trait(_) => true, _ => false } }) }) @@ -393,7 +393,7 @@ fn connect_trait_tps(fcx: @fn_ctxt, expr: @ast::expr, impl_tys: ~[ty::t], match ty::get(trait_ty).sty { ty::ty_trait(_, substs, _) => { vec::iter2(substs.tps, trait_tys, - |a, b| demand::suptype(fcx, expr.span, a, b)); + |a, b| demand::suptype(fcx, expr.span, *a, *b)); } _ => tcx.sess.impossible_case(expr.span, "connect_trait_tps: \ don't know how to handle a non-trait ty") diff --git a/src/rustc/middle/typeck/collect.rs b/src/rustc/middle/typeck/collect.rs index 630ac8c13a1..18e29981af3 100644 --- a/src/rustc/middle/typeck/collect.rs +++ b/src/rustc/middle/typeck/collect.rs @@ -725,7 +725,7 @@ fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item) fn compute_bounds(ccx: @crate_ctxt, ast_bounds: @~[ast::ty_param_bound]) -> ty::param_bounds { @do vec::flat_map(*ast_bounds) |b| { - match b { + match *b { ast::bound_send => ~[ty::bound_send], ast::bound_copy => ~[ty::bound_copy], ast::bound_const => ~[ty::bound_const], diff --git a/src/rustc/middle/typeck/infer.rs b/src/rustc/middle/typeck/infer.rs index a0bb828e412..e5aa0debfe1 100644 --- a/src/rustc/middle/typeck/infer.rs +++ b/src/rustc/middle/typeck/infer.rs @@ -507,7 +507,7 @@ fn rollback_to( vb: &vals_and_bindings, len: uint) { while vb.bindings.len() != len { - let (vid, old_v) = vec::pop(vb.bindings); + let (vid, old_v) = vb.bindings.pop(); vb.vals.insert(vid.to_uint(), old_v); } } diff --git a/src/rustc/middle/typeck/infer/region_var_bindings.rs b/src/rustc/middle/typeck/infer/region_var_bindings.rs index 8eabb2c0787..c86850e19d2 100644 --- a/src/rustc/middle/typeck/infer/region_var_bindings.rs +++ b/src/rustc/middle/typeck/infer/region_var_bindings.rs @@ -1192,7 +1192,7 @@ impl RegionVarBindings { set.insert(*orig_node_idx, ()); let mut result = ~[]; while !vec::is_empty(stack) { - let node_idx = vec::pop(stack); + let node_idx = stack.pop(); for self.each_edge(graph, node_idx, dir) |edge| { match edge.constraint { ConstrainVarSubVar(from_vid, to_vid) => { diff --git a/src/rustc/middle/typeck/infer/resolve.rs b/src/rustc/middle/typeck/infer/resolve.rs index a366a2ef1c7..2a851a5f7bb 100644 --- a/src/rustc/middle/typeck/infer/resolve.rs +++ b/src/rustc/middle/typeck/infer/resolve.rs @@ -170,7 +170,7 @@ impl resolve_state { } fn resolve_ty_var(vid: TyVid) -> ty::t { - if vec::contains(self.v_seen, vid) { + if vec::contains(self.v_seen, &vid) { self.err = Some(cyclic_ty(vid)); return ty::mk_var(self.infcx.tcx, vid); } else { @@ -197,7 +197,7 @@ impl resolve_state { ty::mk_var(tcx, vid) } }; - vec::pop(self.v_seen); + self.v_seen.pop(); return t1; } } diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index b3ba7f14109..71a32dc112f 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -236,7 +236,7 @@ fn merge_method_attrs( { desc: desc, - .. doc + ..*doc } } } diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index c57e712c020..d601d6d92d1 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -228,8 +228,8 @@ fn maybe_find_pandoc( }; let pandoc = do vec::find(possible_pandocs) |pandoc| { - let output = program_output(pandoc, ~[~"--version"]); - debug!("testing pandoc cmd %s: %?", pandoc, output); + let output = program_output(*pandoc, ~[~"--version"]); + debug!("testing pandoc cmd %s: %?", *pandoc, output); output.status == 0 }; diff --git a/src/rustdoc/desc_to_brief_pass.rs b/src/rustdoc/desc_to_brief_pass.rs index b517c2f2409..3fcce7db6c4 100644 --- a/src/rustdoc/desc_to_brief_pass.rs +++ b/src/rustdoc/desc_to_brief_pass.rs @@ -165,7 +165,7 @@ fn paragraphs(s: ~str) -> ~[~str] { let paras = do vec::foldl(~[], lines) |paras, line| { let mut res = paras; - if str::is_whitespace(line) { + if str::is_whitespace(*line) { whitespace_lines += 1; } else { if whitespace_lines > 0 { @@ -178,9 +178,9 @@ fn paragraphs(s: ~str) -> ~[~str] { whitespace_lines = 0; accum = if str::is_empty(accum) { - line + *line } else { - accum + ~"\n" + line + accum + ~"\n" + *line } } diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index 82bddf11d16..0764d9e2432 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -378,7 +378,7 @@ impl IndexEntry : cmp::Eq { impl Doc { fn CrateDoc() -> CrateDoc { option::get(&vec::foldl(None, self.pages, |_m, page| { - match page { + match *page { doc::CratePage(doc) => Some(doc), _ => None } @@ -395,7 +395,7 @@ impl ModDoc { fn mods() -> ~[ModDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { ModTag(ModDoc) => Some(ModDoc), _ => None } @@ -404,7 +404,7 @@ impl ModDoc { fn nmods() -> ~[NmodDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { NmodTag(nModDoc) => Some(nModDoc), _ => None } @@ -413,7 +413,7 @@ impl ModDoc { fn fns() -> ~[FnDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { FnTag(FnDoc) => Some(FnDoc), _ => None } @@ -422,7 +422,7 @@ impl ModDoc { fn consts() -> ~[ConstDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { ConstTag(ConstDoc) => Some(ConstDoc), _ => None } @@ -431,7 +431,7 @@ impl ModDoc { fn enums() -> ~[EnumDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { EnumTag(EnumDoc) => Some(EnumDoc), _ => None } @@ -440,7 +440,7 @@ impl ModDoc { fn traits() -> ~[TraitDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { TraitTag(TraitDoc) => Some(TraitDoc), _ => None } @@ -449,7 +449,7 @@ impl ModDoc { fn impls() -> ~[ImplDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { ImplTag(ImplDoc) => Some(ImplDoc), _ => None } @@ -458,7 +458,7 @@ impl ModDoc { fn types() -> ~[TyDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { TyTag(TyDoc) => Some(TyDoc), _ => None } @@ -467,7 +467,7 @@ impl ModDoc { fn structs() -> ~[StructDoc] { do vec::filter_map(self.items) |itemtag| { - match itemtag { + match *itemtag { StructTag(StructDoc) => Some(StructDoc), _ => None } @@ -490,7 +490,7 @@ impl ~[Page]: PageUtils { fn mods() -> ~[ModDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(ModTag(ModDoc)) => Some(ModDoc), _ => None } @@ -499,7 +499,7 @@ impl ~[Page]: PageUtils { fn nmods() -> ~[NmodDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(NmodTag(nModDoc)) => Some(nModDoc), _ => None } @@ -508,7 +508,7 @@ impl ~[Page]: PageUtils { fn fns() -> ~[FnDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(FnTag(FnDoc)) => Some(FnDoc), _ => None } @@ -517,7 +517,7 @@ impl ~[Page]: PageUtils { fn consts() -> ~[ConstDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(ConstTag(ConstDoc)) => Some(ConstDoc), _ => None } @@ -526,7 +526,7 @@ impl ~[Page]: PageUtils { fn enums() -> ~[EnumDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(EnumTag(EnumDoc)) => Some(EnumDoc), _ => None } @@ -535,7 +535,7 @@ impl ~[Page]: PageUtils { fn traits() -> ~[TraitDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(TraitTag(TraitDoc)) => Some(TraitDoc), _ => None } @@ -544,7 +544,7 @@ impl ~[Page]: PageUtils { fn impls() -> ~[ImplDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(ImplTag(ImplDoc)) => Some(ImplDoc), _ => None } @@ -553,7 +553,7 @@ impl ~[Page]: PageUtils { fn types() -> ~[TyDoc] { do vec::filter_map(self) |page| { - match page { + match *page { ItemPage(TyTag(TyDoc)) => Some(TyDoc), _ => None } diff --git a/src/rustdoc/page_pass.rs b/src/rustdoc/page_pass.rs index 8710792f0e4..ad3f679a97c 100644 --- a/src/rustdoc/page_pass.rs +++ b/src/rustdoc/page_pass.rs @@ -105,7 +105,7 @@ fn fold_mod( fn strip_mod(doc: doc::ModDoc) -> doc::ModDoc { doc::ModDoc_({ items: do vec::filter(doc.items) |item| { - match item { + match *item { doc::ModTag(_) => false, doc::NmodTag(_) => false, _ => true diff --git a/src/rustdoc/path_pass.rs b/src/rustdoc/path_pass.rs index 96ed269a7e9..f6a241fdac8 100644 --- a/src/rustdoc/path_pass.rs +++ b/src/rustdoc/path_pass.rs @@ -45,7 +45,7 @@ fn fold_mod(fold: fold::Fold, doc: doc::ModDoc) -> doc::ModDoc { if !is_topmod { fold.ctxt.path.push(doc.name()); } let doc = fold::default_any_fold_mod(fold, doc); - if !is_topmod { vec::pop(fold.ctxt.path); } + if !is_topmod { fold.ctxt.path.pop(); } doc::ModDoc_({ item: fold.fold_item(fold, doc.item), @@ -56,7 +56,7 @@ fn fold_mod(fold: fold::Fold, doc: doc::ModDoc) -> doc::ModDoc { fn fold_nmod(fold: fold::Fold, doc: doc::NmodDoc) -> doc::NmodDoc { fold.ctxt.path.push(doc.name()); let doc = fold::default_seq_fold_nmod(fold, doc); - vec::pop(fold.ctxt.path); + fold.ctxt.path.pop(); { item: fold.fold_item(fold, doc.item), diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs index 62db53b7600..5e2d141318a 100644 --- a/src/rustdoc/tystr_pass.rs +++ b/src/rustdoc/tystr_pass.rs @@ -177,7 +177,7 @@ fn get_method_sig( node: ast::item_trait(_, _, methods), _ }, _) => { match vec::find(methods, |method| { - match method { + match *method { ast::required(ty_m) => to_str(ty_m.ident) == method_name, ast::provided(m) => to_str(m.ident) == method_name, } diff --git a/src/rustdoc/unindent_pass.rs b/src/rustdoc/unindent_pass.rs index 42c9e80ab7b..aa31892d466 100644 --- a/src/rustdoc/unindent_pass.rs +++ b/src/rustdoc/unindent_pass.rs @@ -29,7 +29,7 @@ fn unindent(s: ~str) -> ~str { let ignore_previous_indents = saw_first_line && !saw_second_line && - !str::is_whitespace(line); + !str::is_whitespace(*line); let min_indent = if ignore_previous_indents { uint::max_value @@ -41,12 +41,12 @@ fn unindent(s: ~str) -> ~str { saw_second_line = true; } - if str::is_whitespace(line) { + if str::is_whitespace(*line) { min_indent } else { saw_first_line = true; let mut spaces = 0; - do str::all(line) |char| { + do str::all(*line) |char| { // Only comparing against space because I wouldn't // know what to do with mixed whitespace chars if char == ' ' { diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 9454ef7aec7..cf44d478356 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -47,7 +47,7 @@ fn shift_push() { let mut v2 = ~[]; while v1.len() > 0 { - v2.push(vec::shift(v1)); + v2.push(v1.shift()); } } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index ef2fa8dfa9e..10b38f2572c 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -97,7 +97,7 @@ fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] { let k = r.gen_uint_range(0u, graph.len()); if graph[k].len() > 0u && vec::any(graph[k], |i| { - i != k as node_id + *i != k as node_id }) { map::set_add(keys, k as node_id); } @@ -160,8 +160,8 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { } }; - fn is_gray(c: color) -> bool { - match c { + fn is_gray(c: &color) -> bool { + match *c { gray(_) => { true } _ => { false } } @@ -183,7 +183,7 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result { let mut color = white; do neighbors.each() |k| { - if is_gray(colors[*k]) { + if is_gray(&colors[*k]) { color = gray(*k); false } @@ -314,7 +314,7 @@ fn validate(edges: ~[(node_id, node_id)], } else { while parent != root { - if vec::contains(path, parent) { + if vec::contains(path, &parent) { status = false; } @@ -336,8 +336,8 @@ fn validate(edges: ~[(node_id, node_id)], log(info, ~"Verifying tree edges..."); let status = do tree.alli() |k, parent| { - if parent != root && parent != -1i64 { - level[parent] == level[k] - 1 + if *parent != root && *parent != -1i64 { + level[*parent] == level[k] - 1 } else { true diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 2931cab248f..ec144b78a10 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -27,7 +27,7 @@ fn recv(p: &pipe) -> uint { while vec::is_empty(*state) { cond.wait(); } - vec::pop(*state) + state.pop() } } diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 525cf8f1c50..1b857b6caeb 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -27,7 +27,7 @@ fn recv(p: &pipe) -> uint { while vec::is_empty(*state) { cond.wait(); } - vec::pop(*state) + state.pop() } } diff --git a/src/test/compile-fail/block-arg-as-stmt-with-value.rs b/src/test/compile-fail/block-arg-as-stmt-with-value.rs index b8e34aefd6f..15154ab5a4e 100644 --- a/src/test/compile-fail/block-arg-as-stmt-with-value.rs +++ b/src/test/compile-fail/block-arg-as-stmt-with-value.rs @@ -2,7 +2,7 @@ fn compute1() -> float { let v = ~[0f, 1f, 2f, 3f]; - do vec::foldl(0f, v) |x, y| { x + y } - 10f + do vec::foldl(0f, v) |x, y| { x + *y } - 10f //~^ ERROR mismatched types: expected `()` } diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs index 638f14f8794..276862ce106 100644 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ b/src/test/compile-fail/regions-escape-loop-via-vec.rs @@ -7,7 +7,7 @@ fn broken() -> int { y += ~[&mut z]; //~ ERROR illegal borrow x += 1; } - vec::foldl(0, y, |v, p| v + *p ) + vec::foldl(0, y, |v, p| v + **p ) } fn main() { } \ No newline at end of file diff --git a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs index 53f158471e8..bab28a06934 100644 --- a/src/test/run-pass/block-arg-can-be-followed-by-binop.rs +++ b/src/test/run-pass/block-arg-can-be-followed-by-binop.rs @@ -2,7 +2,7 @@ fn main() { let v = ~[-1f, 0f, 1f, 2f, 3f]; // Trailing expressions don't require parentheses: - let y = do vec::foldl(0f, v) |x, y| { x + y } + 10f; + let y = do vec::foldl(0f, v) |x, y| { x + *y } + 10f; assert y == 15f; } diff --git a/src/test/run-pass/block-arg-in-parentheses.rs b/src/test/run-pass/block-arg-in-parentheses.rs index 14b05b29dc3..1121cc4dd2f 100644 --- a/src/test/run-pass/block-arg-in-parentheses.rs +++ b/src/test/run-pass/block-arg-in-parentheses.rs @@ -1,20 +1,20 @@ fn w_semi(v: ~[int]) -> int { // the semicolon causes compiler not to // complain about the ignored return value: - do vec::foldl(0, v) |x,y| { x+y }; + do vec::foldl(0, v) |x,y| { x+*y }; -10 } fn w_paren1(v: ~[int]) -> int { - (do vec::foldl(0, v) |x,y| { x+y }) - 10 + (do vec::foldl(0, v) |x,y| { x+*y }) - 10 } fn w_paren2(v: ~[int]) -> int { - (do vec::foldl(0, v) |x,y| { x+y} - 10) + (do vec::foldl(0, v) |x,y| { x+*y} - 10) } fn w_ret(v: ~[int]) -> int { - return do vec::foldl(0, v) |x,y| { x+y } - 10; + return do vec::foldl(0, v) |x,y| { x+*y } - 10; } fn main() { diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index 5953e0b85fb..0f77a0e0816 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -8,28 +8,28 @@ fn main() { } // Usable at all: - let mut any_negative = do vec::any(v) |e| { float::is_negative(e) }; + let mut any_negative = do vec::any(v) |e| { float::is_negative(*e) }; assert any_negative; // Higher precedence than assignments: - any_negative = do vec::any(v) |e| { float::is_negative(e) }; + any_negative = do vec::any(v) |e| { float::is_negative(*e) }; assert any_negative; // Higher precedence than unary operations: let abs_v = do vec::map(v) |e| { float::abs(*e) }; - assert do vec::all(abs_v) |e| { float::is_nonnegative(e) }; - assert !do vec::any(abs_v) |e| { float::is_negative(e) }; + assert do vec::all(abs_v) |e| { float::is_nonnegative(*e) }; + assert !do vec::any(abs_v) |e| { float::is_negative(*e) }; // Usable in funny statement-like forms: - if !do vec::any(v) |e| { float::is_positive(e) } { + if !do vec::any(v) |e| { float::is_positive(*e) } { assert false; } - match do vec::all(v) |e| { float::is_negative(e) } { + match do vec::all(v) |e| { float::is_negative(*e) } { true => { fail ~"incorrect answer."; } false => { } } match 3 { - _ if do vec::any(v) |e| { float::is_negative(e) } => { + _ if do vec::any(v) |e| { float::is_negative(*e) } => { } _ => { fail ~"wrong answer."; @@ -38,15 +38,15 @@ fn main() { // Lower precedence than binary operations: - let w = do vec::foldl(0f, v) |x, y| { x + y } + 10f; - let y = do vec::foldl(0f, v) |x, y| { x + y } + 10f; - let z = 10f + do vec::foldl(0f, v) |x, y| { x + y }; + let w = do vec::foldl(0f, v) |x, y| { x + *y } + 10f; + let y = do vec::foldl(0f, v) |x, y| { x + *y } + 10f; + let z = 10f + do vec::foldl(0f, v) |x, y| { x + *y }; assert w == y; assert y == z; // In the tail of a block let w = - if true { do vec::any(abs_v) |e| { float::is_nonnegative(e) } } + if true { do vec::any(abs_v) |e| { float::is_nonnegative(*e) } } else { false }; assert w; } diff --git a/src/test/run-pass/block-vec-map2.rs b/src/test/run-pass/block-vec-map2.rs index 332afc65f72..d270800de11 100644 --- a/src/test/run-pass/block-vec-map2.rs +++ b/src/test/run-pass/block-vec-map2.rs @@ -4,7 +4,7 @@ fn main() { let v = vec::map2(~[1, 2, 3, 4, 5], ~[true, false, false, true, true], - |i, b| if b { -i } else { i } ); + |i, b| if *b { -(*i) } else { *i } ); log(error, v); assert (v == ~[-1, 2, 3, -4, -5]); } diff --git a/src/test/run-pass/ret-break-cont-in-block.rs b/src/test/run-pass/ret-break-cont-in-block.rs index 9013842ba8b..4e7e978cf55 100644 --- a/src/test/run-pass/ret-break-cont-in-block.rs +++ b/src/test/run-pass/ret-break-cont-in-block.rs @@ -43,10 +43,10 @@ fn ret_deep() -> ~str { fn main() { let mut last = 0; for vec::all(~[1, 2, 3, 4, 5, 6, 7]) |e| { - last = e; - if e == 5 { break; } - if e % 2 == 1 { loop; } - assert e % 2 == 0; + last = *e; + if *e == 5 { break; } + if *e % 2 == 1 { loop; } + assert *e % 2 == 0; }; assert last == 5; -- cgit 1.4.1-3-g733a5 From fec96b2ae0f387488f718390eee4c67a043d9a9b Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 28 Sep 2012 17:04:39 -0700 Subject: Demoding in iter: any, all, map_to_vec, flat_map_to_vec, filter_to_vec --- src/libcore/iter-trait.rs | 20 ++++++++++---------- src/libcore/iter.rs | 26 +++++++++++++------------- src/libcore/vec.rs | 12 ++++++------ src/libsyntax/ext/pipes/proto.rs | 4 ++-- src/rustc/metadata/creader.rs | 4 ++-- src/rustc/middle/check_alt.rs | 6 +++--- src/rustc/middle/lint.rs | 2 +- src/rustc/middle/trans/alt.rs | 2 +- src/rustc/middle/typeck/check/vtable.rs | 2 +- src/test/bench/graph500-bfs.rs | 2 +- src/test/run-pass/issue-2611.rs | 6 +++--- src/test/run-pass/iter-all.rs | 2 +- src/test/run-pass/iter-any.rs | 6 +++--- src/test/run-pass/iter-filter-to-vec.rs | 10 +++++----- src/test/run-pass/iter-map-to-vec.rs | 10 +++++----- 15 files changed, 57 insertions(+), 57 deletions(-) (limited to 'src/test') diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index 4cf2002adaa..98fd0e27e97 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -14,8 +14,8 @@ impl IMPL_T: iter::BaseIter { impl IMPL_T: iter::ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } - pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } - pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } + pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } + pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { iter::foldl(self, move b0, blk) } @@ -30,18 +30,18 @@ impl IMPL_T: iter::EqIter { } impl IMPL_T: iter::CopyableIter { - pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] { - iter::filter_to_vec(self, pred) + pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A] { + iter::filter_to_vec(&self, pred) } - pure fn map_to_vec(op: fn(v: &A) -> B) -> ~[B] { - iter::map_to_vec(self, op) + pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B] { + iter::map_to_vec(&self, op) } pure fn to_vec() -> ~[A] { iter::to_vec(self) } - // FIXME--bug in resolve prevents this from working (#2611) - // fn flat_map_to_vec>(op: fn(A) -> IB) -> ~[B] { - // iter::flat_map_to_vec(self, op) - // } + pure fn flat_map_to_vec>(op: fn(+a: A) -> IB) + -> ~[B] { + iter::flat_map_to_vec(&self, op) + } pure fn find(p: fn(A) -> bool) -> Option { iter::find(self, p) } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index b03a0415145..2db68107fc3 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -16,8 +16,8 @@ trait BaseIter { trait ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool); - pure fn all(blk: fn(A) -> bool) -> bool; - pure fn any(blk: fn(A) -> bool) -> bool; + pure fn all(blk: fn(&A) -> bool) -> bool; + pure fn any(blk: fn(&A) -> bool) -> bool; pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B; pure fn position(f: fn(A) -> bool) -> Option; } @@ -35,8 +35,8 @@ trait TimesIx{ } trait CopyableIter { - pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A]; - pure fn map_to_vec(op: fn(v: &A) -> B) -> ~[B]; + pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A]; + pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B]; pure fn to_vec() -> ~[A]; pure fn find(p: fn(A) -> bool) -> Option; } @@ -74,22 +74,22 @@ pure fn eachi>(self: &IA, blk: fn(uint, v: &A) -> bool) { } } -pure fn all>(self: IA, blk: fn(A) -> bool) -> bool { +pure fn all>(self: &IA, blk: fn(&A) -> bool) -> bool { for self.each |a| { - if !blk(*a) { return false; } + if !blk(a) { return false; } } return true; } -pure fn any>(self: IA, blk: fn(A) -> bool) -> bool { +pure fn any>(self: &IA, blk: fn(&A) -> bool) -> bool { for self.each |a| { - if blk(*a) { return true; } + if blk(a) { return true; } } return false; } -pure fn filter_to_vec>(self: IA, - prd: fn(A) -> bool) -> ~[A] { +pure fn filter_to_vec>(self: &IA, + prd: fn(+a: A) -> bool) -> ~[A] { do vec::build_sized_opt(self.size_hint()) |push| { for self.each |a| { if prd(*a) { push(*a); } @@ -97,17 +97,17 @@ pure fn filter_to_vec>(self: IA, } } -pure fn map_to_vec>(self: IA, op: fn(v: &A) -> B) +pure fn map_to_vec>(self: &IA, op: fn(+v: A) -> B) -> ~[B] { do vec::build_sized_opt(self.size_hint()) |push| { for self.each |a| { - push(op(a)); + push(op(*a)); } } } pure fn flat_map_to_vec,IB:BaseIter>( - self: IA, op: fn(A) -> IB) -> ~[B] { + self: &IA, op: fn(+a: A) -> IB) -> ~[B] { do vec::build |push| { for self.each |a| { diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index aba511f0a7f..7c1c2f2d805 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1991,8 +1991,8 @@ impl &[A]: iter::BaseIter { impl &[A]: iter::ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } - pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } - pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } + pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } + pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { iter::foldl(self, move b0, blk) } @@ -2007,11 +2007,11 @@ impl &[A]: iter::EqIter { } impl &[A]: iter::CopyableIter { - pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] { - iter::filter_to_vec(self, pred) + pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A] { + iter::filter_to_vec(&self, pred) } - pure fn map_to_vec(op: fn(v: &A) -> B) -> ~[B] { - iter::map_to_vec(self, op) + pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B] { + iter::map_to_vec(&self, op) } pure fn to_vec() -> ~[A] { iter::to_vec(self) } diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 70b38e83ad5..6d58d209fcf 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -210,10 +210,10 @@ fn visit>( // the copy keywords prevent recursive use of dvec let states = do (copy proto.states).map_to_vec |s| { let messages = do (copy s.messages).map_to_vec |m| { - let message(name, span, tys, this, next) = *m; + let message(name, span, tys, this, next) = m; visitor.visit_message(name, span, tys, this, next) }; - visitor.visit_state(*s, messages) + visitor.visit_state(s, messages) }; visitor.visit_proto(proto, states) } diff --git a/src/rustc/metadata/creader.rs b/src/rustc/metadata/creader.rs index 0d19fe796e1..3ed56a1953e 100644 --- a/src/rustc/metadata/creader.rs +++ b/src/rustc/metadata/creader.rs @@ -63,9 +63,9 @@ fn warn_if_multiple_versions(e: env, diag: span_handler, partition(crate_cache.map_to_vec(|entry| { let othername = loader::crate_name_from_metas(*entry.metas); if name == othername { - Left(*entry) + Left(entry) } else { - Right(*entry) + Right(entry) } })); diff --git a/src/rustc/middle/check_alt.rs b/src/rustc/middle/check_alt.rs index efbeb490db9..f71b82a2be7 100644 --- a/src/rustc/middle/check_alt.rs +++ b/src/rustc/middle/check_alt.rs @@ -432,7 +432,7 @@ fn check_local(tcx: ty::ctxt, loc: @local, &&s: (), v: visit::vt<()>) { } } -fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool { +fn is_refutable(tcx: ty::ctxt, pat: &pat) -> bool { match tcx.def_map.find(pat.id) { Some(def_variant(enum_id, _)) => { if vec::len(*ty::enum_variants(tcx, enum_id)) != 1u { @@ -457,10 +457,10 @@ fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool { fields.any(|f| is_refutable(tcx, f.pat)) } pat_tup(elts) => { - elts.any(|elt| is_refutable(tcx, elt)) + elts.any(|elt| is_refutable(tcx, *elt)) } pat_enum(_, Some(args)) => { - args.any(|a| is_refutable(tcx, a)) + args.any(|a| is_refutable(tcx, *a)) } pat_enum(_,_) => { false } } diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs index 964e2359527..266ee056e2c 100644 --- a/src/rustc/middle/lint.rs +++ b/src/rustc/middle/lint.rs @@ -149,7 +149,7 @@ fn get_lint_dict() -> lint_dict { (~"deprecated_mode", @{lint: deprecated_mode, desc: ~"warn about deprecated uses of modes", - default: allow}), + default: warn}), (~"deprecated_pattern", @{lint: deprecated_pattern, diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 6450e48486c..73f1e9bd119 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -514,7 +514,7 @@ fn enter_region(bcx: block, dm: DefMap, m: &[@Match/&r], fn get_options(ccx: @crate_ctxt, m: &[@Match], col: uint) -> ~[Opt] { fn add_to_set(tcx: ty::ctxt, set: &DVec, val: Opt) { - if set.any(|l| opt_eq(tcx, &l, &val)) {return;} + if set.any(|l| opt_eq(tcx, l, &val)) {return;} set.push(val); } diff --git a/src/rustc/middle/typeck/check/vtable.rs b/src/rustc/middle/typeck/check/vtable.rs index 2d1455d04ce..0c9440f3ec2 100644 --- a/src/rustc/middle/typeck/check/vtable.rs +++ b/src/rustc/middle/typeck/check/vtable.rs @@ -24,7 +24,7 @@ use util::common::indenter; fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool { vec::any(tps, |bs| { bs.any(|b| { - match b { ty::bound_trait(_) => true, _ => false } + match b { &ty::bound_trait(_) => true, _ => false } }) }) } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 10b38f2572c..27e5c696e59 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -352,7 +352,7 @@ fn validate(edges: ~[(node_id, node_id)], log(info, ~"Verifying graph edges..."); let status = do edges.all() |e| { - let (u, v) = e; + let (u, v) = *e; abs(level[u] - level[v]) <= 1 }; diff --git a/src/test/run-pass/issue-2611.rs b/src/test/run-pass/issue-2611.rs index cc2e89c76ea..8fb5a0d6e04 100644 --- a/src/test/run-pass/issue-2611.rs +++ b/src/test/run-pass/issue-2611.rs @@ -4,12 +4,12 @@ use iter::BaseIter; trait FlatMapToVec { - fn flat_map_to_vec>(op: fn(A) -> IB) -> ~[B]; + fn flat_map_to_vec>(op: fn(+a: A) -> IB) -> ~[B]; } impl BaseIter: FlatMapToVec { - fn flat_map_to_vec>(op: fn(A) -> IB) -> ~[B] { - iter::flat_map_to_vec(self, op) + fn flat_map_to_vec>(op: fn(+a: A) -> IB) -> ~[B] { + iter::flat_map_to_vec(&self, op) } } diff --git a/src/test/run-pass/iter-all.rs b/src/test/run-pass/iter-all.rs index eb5dbd6aa5c..75334db86cc 100644 --- a/src/test/run-pass/iter-all.rs +++ b/src/test/run-pass/iter-all.rs @@ -1,4 +1,4 @@ -fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } +fn is_even(x: &uint) -> bool { (*x % 2) == 0 } fn main() { assert ![1u, 2u]/_.all(is_even); diff --git a/src/test/run-pass/iter-any.rs b/src/test/run-pass/iter-any.rs index d672df09c24..22057b74a41 100644 --- a/src/test/run-pass/iter-any.rs +++ b/src/test/run-pass/iter-any.rs @@ -1,11 +1,11 @@ -fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } +fn is_even(x: &uint) -> bool { (*x % 2) == 0 } fn main() { assert ![1u, 3u]/_.any(is_even); assert [1u, 2u]/_.any(is_even); assert ![]/_.any(is_even); - assert !Some(1u).any(is_even); - assert Some(2u).any(is_even); + assert !Some(1).any(is_even); + assert Some(2).any(is_even); assert !None.any(is_even); } diff --git a/src/test/run-pass/iter-filter-to-vec.rs b/src/test/run-pass/iter-filter-to-vec.rs index 8cb9e0e9d53..f96b18f140a 100644 --- a/src/test/run-pass/iter-filter-to-vec.rs +++ b/src/test/run-pass/iter-filter-to-vec.rs @@ -1,9 +1,9 @@ -fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } +fn is_even(+x: uint) -> bool { (x % 2) == 0 } fn main() { - assert [1u, 3u]/_.filter_to_vec(is_even) == ~[]; - assert [1u, 2u, 3u]/_.filter_to_vec(is_even) == ~[2u]; + assert [1, 3]/_.filter_to_vec(is_even) == ~[]; + assert [1, 2, 3]/_.filter_to_vec(is_even) == ~[2]; assert None.filter_to_vec(is_even) == ~[]; - assert Some(1u).filter_to_vec(is_even) == ~[]; - assert Some(2u).filter_to_vec(is_even) == ~[2u]; + assert Some(1).filter_to_vec(is_even) == ~[]; + assert Some(2).filter_to_vec(is_even) == ~[2]; } diff --git a/src/test/run-pass/iter-map-to-vec.rs b/src/test/run-pass/iter-map-to-vec.rs index 11f2cc1efb1..2f5359f197f 100644 --- a/src/test/run-pass/iter-map-to-vec.rs +++ b/src/test/run-pass/iter-map-to-vec.rs @@ -1,9 +1,9 @@ -fn inc(x: &uint) -> uint { *x + 1u } +fn inc(+x: uint) -> uint { x + 1 } fn main() { - assert [1u, 3u]/_.map_to_vec(inc) == ~[2u, 4u]; - assert [1u, 2u, 3u]/_.map_to_vec(inc) == ~[2u, 3u, 4u]; + assert [1, 3]/_.map_to_vec(inc) == ~[2, 4]; + assert [1, 2, 3]/_.map_to_vec(inc) == ~[2, 3, 4]; assert None.map_to_vec(inc) == ~[]; - assert Some(1u).map_to_vec(inc) == ~[2u]; - assert Some(2u).map_to_vec(inc) == ~[3u]; + assert Some(1).map_to_vec(inc) == ~[2]; + assert Some(2).map_to_vec(inc) == ~[3]; } -- cgit 1.4.1-3-g733a5 From a3a257cc3b29cb134b05a72adbfeff08f1e7a98c Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 28 Sep 2012 16:37:14 -0700 Subject: Demode iter::foldl and friends --- src/libcore/dlist.rs | 2 +- src/libcore/iter-trait.rs | 12 ++++---- src/libcore/iter.rs | 41 ++++++++++++---------------- src/libcore/vec.rs | 12 ++++---- src/rustc/middle/liveness.rs | 2 +- src/rustc/middle/trans/meth.rs | 4 +-- src/rustc/middle/ty.rs | 10 +++---- src/rustc/middle/typeck/check/regionmanip.rs | 4 +-- src/test/run-pass/iter-foldl.rs | 2 +- 9 files changed, 42 insertions(+), 47 deletions(-) (limited to 'src/test') diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 0bdf5caec0c..4e08dd4c2f3 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -675,7 +675,7 @@ mod tests { #[test] fn test_dlist_foldl() { let l = from_vec(vec::from_fn(101, |x|x)); - assert iter::foldl(l, 0, |accum,elem| accum+elem) == 5050; + assert iter::foldl(&l, 0, |accum,elem| *accum+*elem) == 5050; } #[test] fn test_dlist_break_early() { diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index 98fd0e27e97..a6acd1c040e 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -16,8 +16,8 @@ impl IMPL_T: iter::ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } - pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { - iter::foldl(self, move b0, blk) + pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B { + iter::foldl(&self, move b0, blk) } pure fn position(f: fn(A) -> bool) -> Option { iter::position(self, f) @@ -26,7 +26,7 @@ impl IMPL_T: iter::ExtendedIter { impl IMPL_T: iter::EqIter { pure fn contains(x: &A) -> bool { iter::contains(self, x) } - pure fn count(x: &A) -> uint { iter::count(self, x) } + pure fn count(x: &A) -> uint { iter::count(&self, x) } } impl IMPL_T: iter::CopyableIter { @@ -36,7 +36,7 @@ impl IMPL_T: iter::CopyableIter { pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B] { iter::map_to_vec(&self, op) } - pure fn to_vec() -> ~[A] { iter::to_vec(self) } + pure fn to_vec() -> ~[A] { iter::to_vec(&self) } pure fn flat_map_to_vec>(op: fn(+a: A) -> IB) -> ~[B] { @@ -47,7 +47,7 @@ impl IMPL_T: iter::CopyableIter { } impl IMPL_T: iter::CopyableOrderedIter { - pure fn min() -> A { iter::min(self) } - pure fn max() -> A { iter::max(self) } + pure fn min() -> A { iter::min(&self) } + pure fn max() -> A { iter::max(&self) } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 2db68107fc3..77f9abe8e0b 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -18,7 +18,7 @@ trait ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool); pure fn all(blk: fn(&A) -> bool) -> bool; pure fn any(blk: fn(&A) -> bool) -> bool; - pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B; + pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B; pure fn position(f: fn(A) -> bool) -> Option; } @@ -118,16 +118,17 @@ pure fn flat_map_to_vec,IB:BaseIter>( } } -pure fn foldl>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { +pure fn foldl>(self: &IA, +b0: B, blk: fn(&B, &A) -> B) + -> B { let mut b <- b0; for self.each |a| { - b = blk(b, *a); + b = blk(&b, a); } move b } -pure fn to_vec>(self: IA) -> ~[A] { - foldl::(self, ~[], |r, a| vec::append(copy r, ~[a])) +pure fn to_vec>(self: &IA) -> ~[A] { + foldl::(self, ~[], |r, a| vec::append(*r, ~[*a])) } pure fn contains>(self: IA, x: &A) -> bool { @@ -137,12 +138,12 @@ pure fn contains>(self: IA, x: &A) -> bool { return false; } -pure fn count>(self: IA, x: &A) -> uint { +pure fn count>(self: &IA, x: &A) -> uint { do foldl(self, 0) |count, value| { - if value == *x { - count + 1 + if *value == *x { + *count + 1 } else { - count + *count } } } @@ -170,16 +171,13 @@ pure fn repeat(times: uint, blk: fn() -> bool) { } } -// XXX bad copies -pure fn min>(self: IA) -> A { +pure fn min>(self: &IA) -> A { match do foldl::,IA>(self, None) |a, b| { match a { - Some(copy a_) if a_ < b => { - // FIXME (#2005): Not sure if this is successfully optimized to - // a move - a + &Some(a_) if a_ < *b => { + *(move a) } - _ => Some(b) + _ => Some(*b) } } { Some(move val) => val, @@ -187,16 +185,13 @@ pure fn min>(self: IA) -> A { } } -// XXX bad copies -pure fn max>(self: IA) -> A { +pure fn max>(self: &IA) -> A { match do foldl::,IA>(self, None) |a, b| { match a { - Some(copy a_) if a_ > b => { - // FIXME (#2005): Not sure if this is successfully optimized to - // a move. - a + &Some(a_) if a_ > *b => { + *(move a) } - _ => Some(b) + _ => Some(*b) } } { Some(move val) => val, diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 2044bbe42c9..66b1c0d95ec 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1993,8 +1993,8 @@ impl &[A]: iter::ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } - pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { - iter::foldl(self, move b0, blk) + pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B { + iter::foldl(&self, move b0, blk) } pure fn position(f: fn(A) -> bool) -> Option { iter::position(self, f) @@ -2003,7 +2003,7 @@ impl &[A]: iter::ExtendedIter { impl &[A]: iter::EqIter { pure fn contains(x: &A) -> bool { iter::contains(self, x) } - pure fn count(x: &A) -> uint { iter::count(self, x) } + pure fn count(x: &A) -> uint { iter::count(&self, x) } } impl &[A]: iter::CopyableIter { @@ -2013,7 +2013,7 @@ impl &[A]: iter::CopyableIter { pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B] { iter::map_to_vec(&self, op) } - pure fn to_vec() -> ~[A] { iter::to_vec(self) } + pure fn to_vec() -> ~[A] { iter::to_vec(&self) } // FIXME--bug in resolve prevents this from working (#2611) // fn flat_map_to_vec>(op: fn(A) -> IB) -> ~[B] { @@ -2024,8 +2024,8 @@ impl &[A]: iter::CopyableIter { } impl &[A]: iter::CopyableOrderedIter { - pure fn min() -> A { iter::min(self) } - pure fn max() -> A { iter::max(self) } + pure fn min() -> A { iter::min(&self) } + pure fn max() -> A { iter::max(&self) } } // ___________________________________________________________________________ diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index 90c1b6ba54e..90762c5b714 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -1014,7 +1014,7 @@ impl Liveness { fn propagate_through_opt_expr(opt_expr: Option<@expr>, succ: LiveNode) -> LiveNode { do opt_expr.foldl(succ) |succ, expr| { - self.propagate_through_expr(expr, succ) + self.propagate_through_expr(*expr, *succ) } } diff --git a/src/rustc/middle/trans/meth.rs b/src/rustc/middle/trans/meth.rs index 33df35cca52..ebc1645e3d8 100644 --- a/src/rustc/middle/trans/meth.rs +++ b/src/rustc/middle/trans/meth.rs @@ -364,8 +364,8 @@ fn combine_impl_and_methods_origins(bcx: block, // Flatten out to find the number of vtables the method expects. let m_vtables = m_boundss.foldl(0, |sum, m_bounds| { - m_bounds.foldl(sum, |sum, m_bound| { - sum + match m_bound { + m_bounds.foldl(*sum, |sum, m_bound| { + (*sum) + match (*m_bound) { ty::bound_copy | ty::bound_owned | ty::bound_send | ty::bound_const => 0, ty::bound_trait(_) => 1 diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 397a1cd6aa1..973db90ff66 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -2137,25 +2137,25 @@ fn type_size(cx: ctxt, ty: t) -> uint { } ty_rec(flds) => { - flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty)) + flds.foldl(0, |s, f| *s + type_size(cx, f.mt.ty)) } ty_class(did, ref substs) => { let flds = class_items_as_fields(cx, did, substs); - flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty)) + flds.foldl(0, |s, f| *s + type_size(cx, f.mt.ty)) } ty_tup(tys) => { - tys.foldl(0, |s, t| s + type_size(cx, t)) + tys.foldl(0, |s, t| *s + type_size(cx, *t)) } ty_enum(did, ref substs) => { let variants = substd_enum_variants(cx, did, substs); variants.foldl( // find max size of any variant 0, - |m, v| uint::max(m, + |m, v| uint::max(*m, // find size of this variant: - v.args.foldl(0, |s, a| s + type_size(cx, a)))) + v.args.foldl(0, |s, a| *s + type_size(cx, *a)))) } ty_param(_) | ty_self => { diff --git a/src/rustc/middle/typeck/check/regionmanip.rs b/src/rustc/middle/typeck/check/regionmanip.rs index 29d4e9927ff..4afb3ad78a6 100644 --- a/src/rustc/middle/typeck/check/regionmanip.rs +++ b/src/rustc/middle/typeck/check/regionmanip.rs @@ -111,14 +111,14 @@ fn replace_bound_regions_in_fn_ty( // For each type `ty` in `tys`... do tys.foldl(isr) |isr, ty| { - let mut isr = isr; + let mut isr = *isr; // Using fold_regions is inefficient, because it // constructs new types, but it avoids code duplication in // terms of locating all the regions within the various // kinds of types. This had already caused me several // bugs so I decided to switch over. - do ty::fold_regions(tcx, ty) |r, in_fn| { + do ty::fold_regions(tcx, *ty) |r, in_fn| { if !in_fn { isr = append_isr(isr, to_r, r); } r }; diff --git a/src/test/run-pass/iter-foldl.rs b/src/test/run-pass/iter-foldl.rs index 41bb6b82ddd..bbc1673f686 100644 --- a/src/test/run-pass/iter-foldl.rs +++ b/src/test/run-pass/iter-foldl.rs @@ -1,4 +1,4 @@ -fn add(&&x: float, &&y: uint) -> float { x + (y as float) } +fn add(x: &float, y: &uint) -> float { *x + ((*y) as float) } fn main() { assert [1u, 3u]/_.foldl(20f, add) == 24f; -- cgit 1.4.1-3-g733a5 From f311bb38cd24a8c0f730ae104b6bdea8fb2880c5 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 28 Sep 2012 18:26:21 -0700 Subject: Fix benchmarks. --- src/libcore/pipes.rs | 2 +- src/test/bench/graph500-bfs.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/test') diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 97328a9b348..7ab6e5e3909 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -1111,7 +1111,7 @@ impl SharedChan: Channel { } /// Converts a `chan` into a `shared_chan`. -fn SharedChan(+c: Chan) -> SharedChan { +pub fn SharedChan(+c: Chan) -> SharedChan { private::exclusive(move c) } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 27e5c696e59..d6a62363280 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -231,8 +231,8 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { }; #[inline(always)] - fn is_gray(c: color) -> bool { - match c { + fn is_gray(c: &color) -> bool { + match *c { gray(_) => { true } _ => { false } } @@ -282,7 +282,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { // Convert the results. do par::map(colors) |c| { - match c { + match *c { white => { -1i64 } black(parent) => { parent } _ => { fail ~"Found remaining gray nodes in BFS" } -- cgit 1.4.1-3-g733a5 From 90f959aad4a98aaa50dc258b96afd3db9ed0b1ba Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 28 Sep 2012 18:29:31 -0700 Subject: Fix graph500-bfs --- src/test/bench/graph500-bfs.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/test') diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index d6a62363280..f35a3ce735f 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -238,11 +238,11 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { } } - let mut i = 0u; + let mut i = 0; while par::any(colors, is_gray) { // Do the BFS. log(info, fmt!("PBFS iteration %?", i)); - i += 1u; + i += 1; let old_len = colors.len(); let color = arc::ARC(colors); @@ -264,7 +264,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { let mut color = white; do neighbors.each() |k| { - if is_gray(colors[*k]) { + if is_gray(&colors[*k]) { color = gray(*k); false } @@ -370,11 +370,11 @@ fn validate(edges: ~[(node_id, node_id)], let status = do par::alli(tree) |u, v| { let u = u as node_id; - if v == -1i64 || u == root { + if *v == -1i64 || u == root { true } else { - edges.contains(&(u, v)) || edges.contains(&(v, u)) + edges.contains(&(u, *v)) || edges.contains(&(*v, u)) } }; -- cgit 1.4.1-3-g733a5 From 3639d38d5c982193eab8304f2adfe0fcd2dd84bd Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 28 Sep 2012 21:51:14 -0700 Subject: Add a demoded version of ptr::addr_of Currently, the new version is ptr::p2::addr_of and the old one is ptr::addr_of. This is kind of cheesy, but I need a snapshot before I can ditch the old version, since the pipe compiler generates calls to addr_of. core is converted over to use the new version, std is not. --- src/libcore/at_vec.rs | 8 +++--- src/libcore/box.rs | 2 +- src/libcore/comm.rs | 15 +++++------ src/libcore/core.rc | 1 + src/libcore/gc.rs | 2 +- src/libcore/io.rs | 14 +++++----- src/libcore/iter-trait.rs | 8 +++--- src/libcore/iter.rs | 18 ++++++------- src/libcore/option.rs | 8 +++--- src/libcore/os.rs | 6 ++--- src/libcore/pipes.rs | 16 ++++++------ src/libcore/private.rs | 14 +++++----- src/libcore/ptr.rs | 31 +++++++++++++++-------- src/libcore/str.rs | 4 +-- src/libcore/task.rs | 4 +-- src/libcore/task/local_data_priv.rs | 2 +- src/libcore/task/spawn.rs | 11 ++++++-- src/libcore/vec.rs | 26 +++++++++---------- src/libsyntax/ext/pipes/pipec.rs | 6 ++--- src/test/compile-fail/issue-3096-2.rs | 2 +- src/test/compile-fail/mutable-huh-ptr-assign.rs | 2 +- src/test/compile-fail/mutable-huh-variance-ptr.rs | 2 +- src/test/compile-fail/non-copyable-void.rs | 2 +- 23 files changed, 110 insertions(+), 94 deletions(-) (limited to 'src/test') diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 2c54ed7aaf3..6377c25b8c4 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -5,7 +5,7 @@ #[forbid(deprecated_pattern)]; use cast::transmute; -use ptr::addr_of; +use ptr::p2::addr_of; /// Code for dealing with @-vectors. This is pretty incomplete, and /// contains a bunch of duplication from the code for ~-vectors. @@ -29,7 +29,7 @@ extern mod rusti { pub pure fn capacity(v: @[const T]) -> uint { unsafe { let repr: **raw::VecRepr = - ::cast::reinterpret_cast(&addr_of(v)); + ::cast::reinterpret_cast(&addr_of(&v)); (**repr).unboxed.alloc / sys::size_of::() } } @@ -161,7 +161,7 @@ pub mod raw { */ #[inline(always)] pub unsafe fn set_len(v: @[const T], new_len: uint) { - let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); + let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } @@ -182,7 +182,7 @@ pub mod raw { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); - let p = ptr::addr_of((**repr).unboxed.data); + let p = addr_of(&((**repr).unboxed.data)); let p = ptr::offset(p, fill) as *mut T; rusti::move_val_init(*p, move initval); } diff --git a/src/libcore/box.rs b/src/libcore/box.rs index 65a641d208f..43307b92664 100644 --- a/src/libcore/box.rs +++ b/src/libcore/box.rs @@ -24,7 +24,7 @@ pub mod raw { pub pure fn ptr_eq(a: @T, b: @T) -> bool { //! Determine if two shared boxes point to the same object - unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) } + unsafe { ptr::p2::addr_of(&(*a)) == ptr::p2::addr_of(&(*b)) } } impl @const T : Eq { diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index a32d7af2ac6..37468aaaab6 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -38,8 +38,7 @@ will once again be the preferred module for intertask communication. use either::Either; use libc::size_t; - - +// After snapshot, change p2::addr_of => addr_of /** * A communication endpoint that can receive messages @@ -104,7 +103,7 @@ struct PortPtr { // Once the port is detached it's guaranteed not to receive further // messages let yield = 0; - let yieldp = ptr::addr_of(yield); + let yieldp = ptr::p2::addr_of(&yield); rustrt::rust_port_begin_detach(self.po, yieldp); if yield != 0 { // Need to wait for the port to be detached @@ -177,7 +176,7 @@ pub fn Chan(p: Port) -> Chan { */ pub fn send(ch: Chan, +data: T) { let Chan_(p) = ch; - let data_ptr = ptr::addr_of(data) as *(); + let data_ptr = ptr::p2::addr_of(&data) as *(); let res = rustrt::rust_port_id_send(p, data_ptr); if res != 0 unsafe { // Data sent successfully @@ -207,10 +206,10 @@ fn peek_chan(ch: comm::Chan) -> bool { /// Receive on a raw port pointer fn recv_(p: *rust_port) -> T { let yield = 0; - let yieldp = ptr::addr_of(yield); + let yieldp = ptr::p2::addr_of(&yield); let mut res; res = rusti::init::(); - rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp); + rustrt::port_recv(ptr::p2::addr_of(&res) as *uint, p, yieldp); if yield != 0 { // Data isn't available yet, so res has not been initialized. @@ -234,12 +233,12 @@ fn peek_(p: *rust_port) -> bool { pub fn select2(p_a: Port, p_b: Port) -> Either { let ports = ~[(**p_a).po, (**p_b).po]; - let yield = 0, yieldp = ptr::addr_of(yield); + let yield = 0, yieldp = ptr::p2::addr_of(&yield); let mut resport: *rust_port; resport = rusti::init::<*rust_port>(); do vec::as_imm_buf(ports) |ports, n_ports| { - rustrt::rust_port_select(ptr::addr_of(resport), ports, + rustrt::rust_port_select(ptr::p2::addr_of(&resport), ports, n_ports as size_t, yieldp); } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 5a09c595bd6..5ea7004de6d 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -39,6 +39,7 @@ Implicitly, all crates behave as if they included the following prologue: #[legacy_modes]; #[legacy_exports]; +#[warn(deprecated_mode)]; #[warn(deprecated_pattern)]; #[warn(vecs_implicitly_copyable)]; diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index a60dbe5e03a..ace4156f5b4 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -316,7 +316,7 @@ pub fn cleanup_stack_for_failure() { // own stack roots on the stack anyway. let sentinel_box = ~0; let sentinel: **Word = if expect_sentinel() { - cast::reinterpret_cast(&ptr::addr_of(sentinel_box)) + cast::reinterpret_cast(&ptr::p2::addr_of(&sentinel_box)) } else { ptr::null() }; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 285f84b6bf6..642d20fa990 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -889,8 +889,8 @@ mod tests { #[test] fn test_readchars_empty() { do io::with_str_reader(~"") |inp| { - let res : ~[char] = inp.read_chars(128u); - assert(vec::len(res) == 0u); + let res : ~[char] = inp.read_chars(128); + assert(vec::len(res) == 0); } } @@ -903,7 +903,7 @@ mod tests { 104, 101, 108, 108, 111, 29983, 38152, 30340, 27748, 21273, 20999, 32905, 27748]; - fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) { + fn check_read_ln(len : uint, s: &str, ivals: &[int]) { do io::with_str_reader(s) |inp| { let res : ~[char] = inp.read_chars(len); if (len <= vec::len(ivals)) { @@ -913,13 +913,13 @@ mod tests { vec::map(res, |x| *x as int)); } } - let mut i = 0u; - while i < 8u { + let mut i = 0; + while i < 8 { check_read_ln(i, wide_test, ivals); - i += 1u; + i += 1; } // check a long read for good measure - check_read_ln(128u, wide_test, ivals); + check_read_ln(128, wide_test, ivals); } #[test] diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index a6acd1c040e..a2fb4698d7c 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -19,13 +19,13 @@ impl IMPL_T: iter::ExtendedIter { pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B { iter::foldl(&self, move b0, blk) } - pure fn position(f: fn(A) -> bool) -> Option { - iter::position(self, f) + pure fn position(f: fn(&A) -> bool) -> Option { + iter::position(&self, f) } } impl IMPL_T: iter::EqIter { - pure fn contains(x: &A) -> bool { iter::contains(self, x) } + pure fn contains(x: &A) -> bool { iter::contains(&self, x) } pure fn count(x: &A) -> uint { iter::count(&self, x) } } @@ -43,7 +43,7 @@ impl IMPL_T: iter::CopyableIter { iter::flat_map_to_vec(&self, op) } - pure fn find(p: fn(A) -> bool) -> Option { iter::find(self, p) } + pure fn find(p: fn(+a: A) -> bool) -> Option { iter::find(&self, p) } } impl IMPL_T: iter::CopyableOrderedIter { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index ebc768931b5..84a581fb2cb 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -19,7 +19,7 @@ trait ExtendedIter { pure fn all(blk: fn(&A) -> bool) -> bool; pure fn any(blk: fn(&A) -> bool) -> bool; pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B; - pure fn position(f: fn(A) -> bool) -> Option; + pure fn position(f: fn(&A) -> bool) -> Option; } trait EqIter { @@ -38,7 +38,7 @@ trait CopyableIter { pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A]; pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B]; pure fn to_vec() -> ~[A]; - pure fn find(p: fn(A) -> bool) -> Option; + pure fn find(p: fn(+a: A) -> bool) -> Option; } trait CopyableOrderedIter { @@ -131,7 +131,7 @@ pure fn to_vec>(self: &IA) -> ~[A] { foldl::(self, ~[], |r, a| vec::append(copy (*r), ~[*a])) } -pure fn contains>(self: IA, x: &A) -> bool { +pure fn contains>(self: &IA, x: &A) -> bool { for self.each |a| { if *a == *x { return true; } } @@ -148,12 +148,12 @@ pure fn count>(self: &IA, x: &A) -> uint { } } -pure fn position>(self: IA, f: fn(A) -> bool) +pure fn position>(self: &IA, f: fn(&A) -> bool) -> Option { let mut i = 0; for self.each |a| { - if f(*a) { return Some(i); } + if f(a) { return Some(i); } i += 1; } return None; @@ -164,10 +164,10 @@ pure fn position>(self: IA, f: fn(A) -> bool) // it would have to be implemented with foldr, which is too inefficient. pure fn repeat(times: uint, blk: fn() -> bool) { - let mut i = 0u; + let mut i = 0; while i < times { if !blk() { break } - i += 1u; + i += 1; } } @@ -199,8 +199,8 @@ pure fn max>(self: &IA) -> A { } } -pure fn find>(self: IA, - p: fn(A) -> bool) -> Option { +pure fn find>(self: &IA, + p: fn(+a: A) -> bool) -> Option { for self.each |i| { if p(*i) { return Some(*i) } } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 31835f255b3..cee0007f8f3 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -252,20 +252,20 @@ impl Option : Eq { #[test] fn test_unwrap_ptr() { let x = ~0; - let addr_x = ptr::addr_of(*x); + let addr_x = ptr::p2::addr_of(&(*x)); let opt = Some(x); let y = unwrap(opt); - let addr_y = ptr::addr_of(*y); + let addr_y = ptr::p2::addr_of(&(*y)); assert addr_x == addr_y; } #[test] fn test_unwrap_str() { let x = ~"test"; - let addr_x = str::as_buf(x, |buf, _len| ptr::addr_of(buf)); + let addr_x = str::as_buf(x, |buf, _len| ptr::p2::addr_of(&buf)); let opt = Some(x); let y = unwrap(opt); - let addr_y = str::as_buf(y, |buf, _len| ptr::addr_of(buf)); + let addr_y = str::as_buf(y, |buf, _len| ptr::p2::addr_of(&buf)); assert addr_x == addr_y; } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 8ec8d1a2b08..9c0d9cdc02c 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -303,7 +303,7 @@ pub fn waitpid(pid: pid_t) -> c_int { use libc::funcs::posix01::wait::*; let status = 0 as c_int; - assert (waitpid(pid, ptr::mut_addr_of(status), + assert (waitpid(pid, ptr::mut_addr_of(&status), 0 as c_int) != (-1 as c_int)); return status; } @@ -313,7 +313,7 @@ pub fn waitpid(pid: pid_t) -> c_int { pub fn pipe() -> {in: c_int, out: c_int} { let fds = {mut in: 0 as c_int, mut out: 0 as c_int }; - assert (libc::pipe(ptr::mut_addr_of(fds.in)) == (0 as c_int)); + assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int)); return {in: fds.in, out: fds.out}; } @@ -384,7 +384,7 @@ pub fn self_exe_path() -> Option { #[cfg(target_os = "macos")] fn load_self() -> Option<~str> { do fill_charp_buf() |buf, sz| { - libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(sz as u32)) + libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int) } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 7ab6e5e3909..95edeca9837 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -219,7 +219,7 @@ fn unibuffer() -> ~Buffer> { #[doc(hidden)] pub fn packet() -> *Packet { let b = unibuffer(); - let p = ptr::addr_of(b.data); + let p = ptr::p2::addr_of(&(b.data)); // We'll take over memory management from here. unsafe { forget(move b) } p @@ -359,7 +359,7 @@ pub fn send(+p: SendPacketBuffered, let header = p.header(); let p_ = p.unwrap(); let p = unsafe { &*p_ }; - assert ptr::addr_of(p.header) == header; + assert ptr::p2::addr_of(&(p.header)) == header; assert p.payload.is_none(); p.payload <- Some(move payload); let old_state = swap_state_rel(&mut p.header.state, Full); @@ -377,7 +377,7 @@ pub fn send(+p: SendPacketBuffered, let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); if !old_task.is_null() { rustrt::task_signal_event( - old_task, ptr::addr_of(p.header) as *libc::c_void); + old_task, ptr::p2::addr_of(&(p.header)) as *libc::c_void); rustrt::rust_task_deref(old_task); } @@ -529,7 +529,7 @@ fn sender_terminate(p: *Packet) { if !old_task.is_null() { rustrt::task_signal_event( old_task, - ptr::addr_of(p.header) as *libc::c_void); + ptr::p2::addr_of(&(p.header)) as *libc::c_void); rustrt::rust_task_deref(old_task); } // The receiver will eventually clean up. @@ -744,7 +744,7 @@ pub fn SendPacketBuffered(p: *Packet) p: Some(p), buffer: unsafe { Some(BufferResource( - get_buffer(ptr::addr_of((*p).header)))) + get_buffer(ptr::p2::addr_of(&((*p).header))))) } } } @@ -760,7 +760,7 @@ impl SendPacketBuffered { match self.p { Some(packet) => unsafe { let packet = &*packet; - let header = ptr::addr_of(packet.header); + let header = ptr::p2::addr_of(&(packet.header)); //forget(packet); header }, @@ -815,7 +815,7 @@ impl RecvPacketBuffered : Selectable { match self.p { Some(packet) => unsafe { let packet = &*packet; - let header = ptr::addr_of(packet.header); + let header = ptr::p2::addr_of(&(packet.header)); //forget(packet); header }, @@ -838,7 +838,7 @@ pub fn RecvPacketBuffered(p: *Packet) p: Some(p), buffer: unsafe { Some(BufferResource( - get_buffer(ptr::addr_of((*p).header)))) + get_buffer(ptr::p2::addr_of(&((*p).header))))) } } } diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 7eba81803b3..025a6f28976 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -108,8 +108,8 @@ pub fn test_from_global_chan1() { // This is unreadable, right? // The global channel - let globchan = 0u; - let globchanp = ptr::addr_of(globchan); + let globchan = 0; + let globchanp = ptr::p2::addr_of(&globchan); // Create the global channel, attached to a new task let ch = unsafe { @@ -142,23 +142,23 @@ pub fn test_from_global_chan1() { #[test] pub fn test_from_global_chan2() { - for iter::repeat(100u) { + for iter::repeat(100) { // The global channel - let globchan = 0u; - let globchanp = ptr::addr_of(globchan); + let globchan = 0; + let globchanp = ptr::p2::addr_of(&globchan); let resultpo = comm::Port(); let resultch = comm::Chan(resultpo); // Spawn a bunch of tasks that all want to compete to // create the global channel - for uint::range(0u, 10u) |i| { + for uint::range(0, 10) |i| { do task::spawn { let ch = unsafe { do chan_from_global_ptr( globchanp, task::task) |po| { - for uint::range(0u, 10u) |_j| { + for uint::range(0, 10) |_j| { let ch = comm::recv(po); comm::send(ch, {i}); } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 0cc283e89a4..d0b848adde2 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -24,15 +24,24 @@ extern mod rusti { fn addr_of(val: T) -> *T; } +/* +Remove this after snapshot; make p2::addr_of addr_of +*/ /// Get an unsafe pointer to a value #[inline(always)] pub pure fn addr_of(val: T) -> *T { unsafe { rusti::addr_of(val) } } +pub mod p2 { + /// Get an unsafe pointer to a value + #[inline(always)] + pub pure fn addr_of(val: &T) -> *T { unsafe { rusti::addr_of(*val) } } +} + /// Get an unsafe mut pointer to a value #[inline(always)] -pub pure fn mut_addr_of(val: T) -> *mut T { +pub pure fn mut_addr_of(val: &T) -> *mut T { unsafe { - cast::reinterpret_cast(&rusti::addr_of(val)) + cast::reinterpret_cast(&rusti::addr_of(*val)) } } @@ -61,16 +70,16 @@ pub fn mut_offset(ptr: *mut T, count: uint) -> *mut T { /// Return the offset of the first null pointer in `buf`. #[inline(always)] pub unsafe fn buf_len(buf: **T) -> uint { - position(buf, |i| i == null()) + position(buf, |i| *i == null()) } /// Return the first offset `i` such that `f(buf[i]) == true`. #[inline(always)] -pub unsafe fn position(buf: *T, f: fn(T) -> bool) -> uint { - let mut i = 0u; +pub unsafe fn position(buf: *T, f: fn(&T) -> bool) -> uint { + let mut i = 0; loop { - if f(*offset(buf, i)) { return i; } - else { i += 1u; } + if f(&(*offset(buf, i))) { return i; } + else { i += 1; } } } @@ -234,7 +243,7 @@ pub fn test() { unsafe { type Pair = {mut fst: int, mut snd: int}; let p = {mut fst: 10, mut snd: 20}; - let pptr: *mut Pair = mut_addr_of(p); + let pptr: *mut Pair = mut_addr_of(&p); let iptr: *mut int = cast::reinterpret_cast(&pptr); assert (*iptr == 10);; *iptr = 30; @@ -268,9 +277,9 @@ pub fn test_position() { let s = ~"hello"; unsafe { - assert 2u == as_c_str(s, |p| position(p, |c| c == 'l' as c_char)); - assert 4u == as_c_str(s, |p| position(p, |c| c == 'o' as c_char)); - assert 5u == as_c_str(s, |p| position(p, |c| c == 0 as c_char)); + assert 2u == as_c_str(s, |p| position(p, |c| *c == 'l' as c_char)); + assert 4u == as_c_str(s, |p| position(p, |c| *c == 'o' as c_char)); + assert 5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char)); } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f7d8e8d34d2..c6e7116675f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1780,7 +1780,7 @@ pub pure fn as_c_str(s: &str, f: fn(*libc::c_char) -> T) -> T { #[inline(always)] pub pure fn as_buf(s: &str, f: fn(*u8, uint) -> T) -> T { unsafe { - let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(s)); + let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::p2::addr_of(&s)); let (buf,len) = *v; f(buf, len) } @@ -2012,7 +2012,7 @@ pub mod raw { let v: **vec::raw::VecRepr = cast::transmute(copy v); let repr: *vec::raw::VecRepr = *v; (*repr).unboxed.fill = new_len + 1u; - let null = ptr::mut_offset(ptr::mut_addr_of((*repr).unboxed.data), + let null = ptr::mut_offset(ptr::mut_addr_of(&((*repr).unboxed.data)), new_len); *null = 0u8; } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 9e2949c37ef..d7e8416e9f7 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -1175,10 +1175,10 @@ fn avoid_copying_the_body(spawnfn: fn(+v: fn~())) { let ch = comm::Chan(p); let x = ~1; - let x_in_parent = ptr::addr_of(*x) as uint; + let x_in_parent = ptr::p2::addr_of(&(*x)) as uint; do spawnfn { - let x_in_child = ptr::addr_of(*x) as uint; + let x_in_child = ptr::p2::addr_of(&(*x)) as uint; comm::send(ch, x_in_child); } diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 31369c47c64..0d3007286c5 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -68,7 +68,7 @@ unsafe fn local_data_lookup( let key_value = key_to_key_value(key); let map_pos = (*map).position(|entry| - match entry { + match *entry { Some((k,_,_)) => k == key_value, None => false } diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 7ae4c7b0950..d410a4b192d 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -66,7 +66,7 @@ use rt::rust_task; use rt::rust_closure; macro_rules! move_it ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); move y } } + { $x:expr } => { unsafe { let y <- *ptr::p2::addr_of(&($x)); move y } } ) type TaskSet = send_map::linear::LinearMap<*rust_task,()>; @@ -511,7 +511,14 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { let child_wrapper = make_child_wrapper(new_task, move child_tg, move ancestors, is_main, move notify_chan, move f); - let fptr = ptr::addr_of(child_wrapper); + /* + Truly awful, but otherwise the borrow checker complains about + the move in the last line of this block, for reasons I can't + understand. -- tjc + */ + let tmp: u64 = cast::reinterpret_cast(&(&child_wrapper)); + let whatever: &~fn() = cast::reinterpret_cast(&tmp); + let fptr = ptr::p2::addr_of(whatever); let closure: *rust_closure = cast::reinterpret_cast(&fptr); // Getting killed between these two calls would free the child's diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 66b1c0d95ec..a8286eb4e08 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -6,7 +6,7 @@ use cmp::{Eq, Ord}; use option::{Some, None}; -use ptr::addr_of; +use ptr::p2::addr_of; use libc::size_t; export append; @@ -582,7 +582,7 @@ unsafe fn push_fast(+v: &mut ~[T], +initval: T) { let repr: **raw::VecRepr = ::cast::transmute(v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); - let p = ptr::addr_of((**repr).unboxed.data); + let p = addr_of(&((**repr).unboxed.data)); let p = ptr::offset(p, fill) as *mut T; rusti::move_val_init(*p, move initval); } @@ -1339,7 +1339,7 @@ pure fn as_imm_buf(s: &[T], /* NB---this CANNOT be const, see below */ unsafe { let v : *(*T,uint) = - ::cast::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&addr_of(&s)); let (buf,len) = *v; f(buf, len / sys::size_of::()) } @@ -1352,7 +1352,7 @@ pure fn as_const_buf(s: &[const T], unsafe { let v : *(*const T,uint) = - ::cast::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&addr_of(&s)); let (buf,len) = *v; f(buf, len / sys::size_of::()) } @@ -1365,7 +1365,7 @@ pure fn as_mut_buf(s: &[mut T], unsafe { let v : *(*mut T,uint) = - ::cast::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&addr_of(&s)); let (buf,len) = *v; f(buf, len / sys::size_of::()) } @@ -1816,21 +1816,21 @@ mod raw { #[inline(always)] unsafe fn to_ptr(+v: &[T]) -> *T { let repr: **SliceRepr = ::cast::transmute(&v); - return ::cast::reinterpret_cast(&addr_of((**repr).data)); + return ::cast::reinterpret_cast(&addr_of(&((**repr).data))); } /** see `to_ptr()` */ #[inline(always)] unsafe fn to_const_ptr(+v: &[const T]) -> *const T { let repr: **SliceRepr = ::cast::transmute(&v); - return ::cast::reinterpret_cast(&addr_of((**repr).data)); + return ::cast::reinterpret_cast(&addr_of(&((**repr).data))); } /** see `to_ptr()` */ #[inline(always)] unsafe fn to_mut_ptr(+v: &[mut T]) -> *mut T { let repr: **SliceRepr = ::cast::transmute(&v); - return ::cast::reinterpret_cast(&addr_of((**repr).data)); + return ::cast::reinterpret_cast(&addr_of(&((**repr).data))); } /** @@ -1841,7 +1841,7 @@ mod raw { unsafe fn form_slice(p: *T, len: uint, f: fn(v: &[T]) -> U) -> U { let pair = (p, len * sys::size_of::()); let v : *(&blk/[T]) = - ::cast::reinterpret_cast(&ptr::addr_of(pair)); + ::cast::reinterpret_cast(&addr_of(&pair)); f(*v) } @@ -1996,13 +1996,13 @@ impl &[A]: iter::ExtendedIter { pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B { iter::foldl(&self, move b0, blk) } - pure fn position(f: fn(A) -> bool) -> Option { - iter::position(self, f) + pure fn position(f: fn(&A) -> bool) -> Option { + iter::position(&self, f) } } impl &[A]: iter::EqIter { - pure fn contains(x: &A) -> bool { iter::contains(self, x) } + pure fn contains(x: &A) -> bool { iter::contains(&self, x) } pure fn count(x: &A) -> uint { iter::count(&self, x) } } @@ -2020,7 +2020,7 @@ impl &[A]: iter::CopyableIter { // iter::flat_map_to_vec(self, op) // } - pure fn find(p: fn(A) -> bool) -> Option { iter::find(self, p) } + pure fn find(p: fn(+a: A) -> bool) -> Option { iter::find(&self, p) } } impl &[A]: iter::CopyableOrderedIter { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index b9b1484ce5a..cec2972b2a7 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -71,10 +71,10 @@ impl message: gen_send { body += ~"let b = pipe.reuse_buffer();\n"; body += fmt!("let %s = pipes::SendPacketBuffered(\ - ptr::addr_of(b.buffer.data.%s));\n", + ptr::p2::addr_of(&(b.buffer.data.%s)));\n", sp, next.name); body += fmt!("let %s = pipes::RecvPacketBuffered(\ - ptr::addr_of(b.buffer.data.%s));\n", + ptr::p2::addr_of(&(b.buffer.data.%s)));\n", rp, next.name); } else { @@ -351,7 +351,7 @@ impl protocol: gen_init { fmt!("data.%s.set_buffer_(buffer)", s.name))), ext_cx.parse_expr( - fmt!("ptr::addr_of(data.%s)", + fmt!("ptr::p2::addr_of(&(data.%s))", self.states[0].name)))); #ast {{ diff --git a/src/test/compile-fail/issue-3096-2.rs b/src/test/compile-fail/issue-3096-2.rs index cd3d63b5888..03e13f67a9a 100644 --- a/src/test/compile-fail/issue-3096-2.rs +++ b/src/test/compile-fail/issue-3096-2.rs @@ -1,6 +1,6 @@ enum bottom { } fn main() { - let x = ptr::addr_of(()) as *bottom; + let x = ptr::p2::addr_of(&()) as *bottom; match x { } //~ ERROR non-exhaustive patterns } diff --git a/src/test/compile-fail/mutable-huh-ptr-assign.rs b/src/test/compile-fail/mutable-huh-ptr-assign.rs index ecfbb9a1f08..4b680ec8b70 100644 --- a/src/test/compile-fail/mutable-huh-ptr-assign.rs +++ b/src/test/compile-fail/mutable-huh-ptr-assign.rs @@ -7,7 +7,7 @@ fn main() { unsafe { let a = 0; - let v = ptr::mut_addr_of(a); + let v = ptr::mut_addr_of(&a); f(v); } } diff --git a/src/test/compile-fail/mutable-huh-variance-ptr.rs b/src/test/compile-fail/mutable-huh-variance-ptr.rs index c96f3f624f1..e98b9b34c5f 100644 --- a/src/test/compile-fail/mutable-huh-variance-ptr.rs +++ b/src/test/compile-fail/mutable-huh-variance-ptr.rs @@ -4,7 +4,7 @@ extern mod std; fn main() { let a = ~[0]; - let v: *mut ~[int] = ptr::mut_addr_of(a); + let v: *mut ~[int] = ptr::mut_addr_of(&a); fn f(&&v: *mut ~[const int]) { unsafe { diff --git a/src/test/compile-fail/non-copyable-void.rs b/src/test/compile-fail/non-copyable-void.rs index 59136683e6f..a00dd7afd6d 100644 --- a/src/test/compile-fail/non-copyable-void.rs +++ b/src/test/compile-fail/non-copyable-void.rs @@ -1,5 +1,5 @@ fn main() { - let x : *~[int] = ptr::addr_of(~[1,2,3]); + let x : *~[int] = ptr::p2::addr_of(&~[1,2,3]); let y : *libc::c_void = x as *libc::c_void; unsafe { let _z = *y; -- cgit 1.4.1-3-g733a5 From 1c76d189c02ddc6cb6fcf15ae94f3a3ae4de5fa7 Mon Sep 17 00:00:00 2001 From: Gareth Daniel Smith Date: Sat, 29 Sep 2012 12:34:11 +0100 Subject: When a vec/str bounds check fails, include the bad index and the length of the str/vec in the fail message. --- src/libcore/rt.rs | 10 ++++++++++ src/rustc/middle/trans/controlflow.rs | 18 ++++++++++++++++++ src/rustc/middle/trans/expr.rs | 4 +++- src/test/run-fail/bug-2470-bounds-check-overflow-2.rs | 4 ++-- src/test/run-fail/bug-2470-bounds-check-overflow-3.rs | 2 +- src/test/run-fail/bug-2470-bounds-check-overflow.rs | 2 +- src/test/run-fail/small-negative-indexing.rs | 2 +- src/test/run-fail/str-overrun.rs | 2 +- src/test/run-fail/vec-overrun.rs | 2 +- src/test/run-fail/vec-underrun.rs | 2 +- 10 files changed, 39 insertions(+), 9 deletions(-) (limited to 'src/test') diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index 644edb69d56..da598fc3e7f 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -40,6 +40,16 @@ fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) { rustrt::rust_upcall_fail(expr, file, line); } +#[rt(fail_bounds_check)] +fn rt_fail_bounds_check(file: *c_char, line: size_t, + index: size_t, len: size_t) { + let msg = fmt!("index out of bounds: the len is %d but the index is %d", + len as int, index as int); + do str::as_buf(msg) |p, _len| { + rt_fail_(p as *c_char, file, line); + } +} + #[rt(exchange_malloc)] fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_exchange_malloc(td, size); diff --git a/src/rustc/middle/trans/controlflow.rs b/src/rustc/middle/trans/controlflow.rs index 68ebf5fa189..ce32cd0a2dd 100644 --- a/src/rustc/middle/trans/controlflow.rs +++ b/src/rustc/middle/trans/controlflow.rs @@ -344,3 +344,21 @@ fn trans_fail_value(bcx: block, sp_opt: Option, V_fail_str: ValueRef) Unreachable(bcx); return bcx; } + +fn trans_fail_bounds_check(bcx: block, sp: span, + index: ValueRef, len: ValueRef) -> block { + let _icx = bcx.insn_ctxt("trans_fail_bounds_check"); + let ccx = bcx.ccx(); + + let loc = codemap::lookup_char_pos(bcx.sess().parse_sess.cm, sp.lo); + let line = C_int(ccx, loc.line as int); + let filename_cstr = C_cstr(bcx.ccx(), loc.file.name); + let filename = PointerCast(bcx, filename_cstr, T_ptr(T_i8())); + + let args = ~[filename, line, index, len]; + let bcx = callee::trans_rtcall(bcx, ~"fail_bounds_check", args, + expr::Ignore); + Unreachable(bcx); + return bcx; +} + diff --git a/src/rustc/middle/trans/expr.rs b/src/rustc/middle/trans/expr.rs index dafaebef9e0..57439daca2f 100644 --- a/src/rustc/middle/trans/expr.rs +++ b/src/rustc/middle/trans/expr.rs @@ -946,7 +946,9 @@ fn trans_index(bcx: block, let bounds_check = ICmp(bcx, lib::llvm::IntUGE, scaled_ix, len); let bcx = do with_cond(bcx, bounds_check) |bcx| { - controlflow::trans_fail(bcx, Some(index_expr.span), ~"bounds check") + let unscaled_len = UDiv(bcx, len, vt.llunit_size); + controlflow::trans_fail_bounds_check(bcx, index_expr.span, + ix_val, unscaled_len) }; let elt = InBoundsGEP(bcx, base, ~[ix_val]); let elt = PointerCast(bcx, elt, T_ptr(vt.llunit_ty)); diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs b/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs index 0db43856612..ef371d07569 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs @@ -1,5 +1,5 @@ // xfail-test -// error-pattern:bounds check +// error-pattern:index out of bounds fn main() { let x = ~[1u,2u,3u]; @@ -14,4 +14,4 @@ fn main() { // This should fail. error!("ov2 0x%x", x[idx]); -} \ No newline at end of file +} diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs b/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs index 949d303eb01..ae3a9c55b93 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs @@ -1,5 +1,5 @@ // xfail-test -// error-pattern:bounds check +// error-pattern:index out of bounds #[cfg(target_arch="x86")] fn main() { diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow.rs b/src/test/run-fail/bug-2470-bounds-check-overflow.rs index 924b3dda149..fdbcb4de2be 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow.rs @@ -1,4 +1,4 @@ -// error-pattern:bounds check +// error-pattern:index out of bounds fn main() { diff --git a/src/test/run-fail/small-negative-indexing.rs b/src/test/run-fail/small-negative-indexing.rs index 96f0c12c760..5ba6e9dd27a 100644 --- a/src/test/run-fail/small-negative-indexing.rs +++ b/src/test/run-fail/small-negative-indexing.rs @@ -1,4 +1,4 @@ -// error-pattern:bounds check +// error-pattern:index out of bounds: the len is 1024 but the index is -1 fn main() { let v = vec::from_fn(1024u, {|n| n}); // this should trip a bounds check diff --git a/src/test/run-fail/str-overrun.rs b/src/test/run-fail/str-overrun.rs index b8bccfe82d4..d9485f3a289 100644 --- a/src/test/run-fail/str-overrun.rs +++ b/src/test/run-fail/str-overrun.rs @@ -1,6 +1,6 @@ // -*- rust -*- -// error-pattern:bounds check +// error-pattern:index out of bounds: the len is 5 but the index is 5 fn main() { let s: ~str = ~"hello"; diff --git a/src/test/run-fail/vec-overrun.rs b/src/test/run-fail/vec-overrun.rs index 8301a05f76b..fd3254bc6b1 100644 --- a/src/test/run-fail/vec-overrun.rs +++ b/src/test/run-fail/vec-overrun.rs @@ -1,6 +1,6 @@ // -*- rust -*- -// error-pattern:bounds check +// error-pattern:index out of bounds: the len is 1 but the index is 2 fn main() { let v: ~[int] = ~[10]; let x: int = 0; diff --git a/src/test/run-fail/vec-underrun.rs b/src/test/run-fail/vec-underrun.rs index 1228e95ac1e..88b29471dac 100644 --- a/src/test/run-fail/vec-underrun.rs +++ b/src/test/run-fail/vec-underrun.rs @@ -1,6 +1,6 @@ // -*- rust -*- -// error-pattern:bounds check +// error-pattern:index out of bounds: the len is 2 but the index is -1 fn main() { let v: ~[int] = ~[10, 20]; let x: int = 0; -- cgit 1.4.1-3-g733a5 From b18320446e553a3f8436f87306dded57e16a4b94 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 1 Oct 2012 12:47:02 -0700 Subject: Move over to calling ptr::addr_of Everything should now call ptr::addr_of instead of ptr::p2::addr_of. Only the pipes macro code when compiled by stage0 will call ptr::p2::addr_of. Needs a snapshot to get rid of that. --- doc/tutorial-ffi.md | 2 +- src/libcore/at_vec.rs | 2 +- src/libcore/box.rs | 2 +- src/libcore/comm.rs | 12 +++--- src/libcore/flate.rs | 4 +- src/libcore/gc.rs | 2 +- src/libcore/pipes.rs | 18 ++++----- src/libcore/ptr.rs | 5 +-- src/libcore/str.rs | 2 +- src/libcore/task/spawn.rs | 2 +- src/libcore/vec.rs | 2 +- src/libstd/dbg.rs | 8 ++-- src/libstd/net_ip.rs | 6 +-- src/libstd/net_tcp.rs | 42 ++++++++++----------- src/libstd/sync.rs | 4 +- src/libstd/timer.rs | 4 +- src/libstd/uv_global_loop.rs | 4 +- src/libstd/uv_iotask.rs | 10 ++--- src/libstd/uv_ll.rs | 44 +++++++++++----------- src/libsyntax/ast.rs | 4 +- src/libsyntax/ext/fmt.rs | 2 +- src/libsyntax/ext/pipes/pipec.rs | 6 +-- src/rustc/middle/lang_items.rs | 2 +- src/rustc/middle/liveness.rs | 2 +- src/rustc/middle/trans/build.rs | 6 +-- src/rustc/middle/trans/common.rs | 2 +- src/rustc/middle/typeck/check.rs | 2 +- src/test/auxiliary/test_comm.rs | 6 +-- src/test/bench/msgsend-pipes-shared.rs | 2 +- src/test/bench/msgsend-pipes.rs | 2 +- src/test/bench/msgsend-ring-pipes.rs | 2 +- src/test/bench/pingpong.rs | 2 +- src/test/bench/task-perf-word-count-generic.rs | 2 +- src/test/run-pass/binops.rs | 4 +- .../run-pass/borrowck-borrow-from-expr-block.rs | 2 +- .../run-pass/borrowck-preserve-box-in-discr.rs | 6 +-- .../run-pass/borrowck-preserve-box-in-field.rs | 6 +-- src/test/run-pass/borrowck-preserve-box-in-pat.rs | 6 +-- src/test/run-pass/borrowck-preserve-box-in-uniq.rs | 6 +-- src/test/run-pass/borrowck-preserve-box.rs | 6 +-- src/test/run-pass/borrowck-preserve-expl-deref.rs | 6 +-- src/test/run-pass/cap-clause-move.rs | 24 ++++++------ src/test/run-pass/issue-2718.rs | 4 +- src/test/run-pass/last-use-corner-cases.rs | 8 ++-- src/test/run-pass/pipe-bank-proto.rs | 2 +- src/test/run-pass/pipe-pingpong-bounded.rs | 10 ++--- src/test/run-pass/reflect-visit-data.rs | 2 +- src/test/run-pass/resource-cycle.rs | 12 +++--- src/test/run-pass/rt-sched-1.rs | 2 +- src/test/run-pass/select-macro.rs | 2 +- src/test/run-pass/stable-addr-of.rs | 2 +- src/test/run-pass/task-killjoin-rsrc.rs | 4 +- src/test/run-pass/task-spawn-move-and-copy.rs | 8 ++-- src/test/run-pass/uniq-cc-generic.rs | 2 +- 54 files changed, 169 insertions(+), 172 deletions(-) (limited to 'src/test') diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index 92ba09856b0..463bd4746fe 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -231,7 +231,7 @@ fn unix_time_in_microseconds() -> u64 unsafe { mut tv_sec: 0 as c_ulonglong, mut tv_usec: 0 as c_ulonglong }; - lib_c::gettimeofday(ptr::addr_of(x), ptr::null()); + lib_c::gettimeofday(ptr::addr_of(&x), ptr::null()); return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64); } diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 6377c25b8c4..6936de2bccb 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -5,7 +5,7 @@ #[forbid(deprecated_pattern)]; use cast::transmute; -use ptr::p2::addr_of; +use ptr::addr_of; /// Code for dealing with @-vectors. This is pretty incomplete, and /// contains a bunch of duplication from the code for ~-vectors. diff --git a/src/libcore/box.rs b/src/libcore/box.rs index 43307b92664..d34679f2bd7 100644 --- a/src/libcore/box.rs +++ b/src/libcore/box.rs @@ -24,7 +24,7 @@ pub mod raw { pub pure fn ptr_eq(a: @T, b: @T) -> bool { //! Determine if two shared boxes point to the same object - unsafe { ptr::p2::addr_of(&(*a)) == ptr::p2::addr_of(&(*b)) } + unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) } } impl @const T : Eq { diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 37468aaaab6..46767bc1172 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -103,7 +103,7 @@ struct PortPtr { // Once the port is detached it's guaranteed not to receive further // messages let yield = 0; - let yieldp = ptr::p2::addr_of(&yield); + let yieldp = ptr::addr_of(&yield); rustrt::rust_port_begin_detach(self.po, yieldp); if yield != 0 { // Need to wait for the port to be detached @@ -176,7 +176,7 @@ pub fn Chan(p: Port) -> Chan { */ pub fn send(ch: Chan, +data: T) { let Chan_(p) = ch; - let data_ptr = ptr::p2::addr_of(&data) as *(); + let data_ptr = ptr::addr_of(&data) as *(); let res = rustrt::rust_port_id_send(p, data_ptr); if res != 0 unsafe { // Data sent successfully @@ -206,10 +206,10 @@ fn peek_chan(ch: comm::Chan) -> bool { /// Receive on a raw port pointer fn recv_(p: *rust_port) -> T { let yield = 0; - let yieldp = ptr::p2::addr_of(&yield); + let yieldp = ptr::addr_of(&yield); let mut res; res = rusti::init::(); - rustrt::port_recv(ptr::p2::addr_of(&res) as *uint, p, yieldp); + rustrt::port_recv(ptr::addr_of(&res) as *uint, p, yieldp); if yield != 0 { // Data isn't available yet, so res has not been initialized. @@ -233,12 +233,12 @@ fn peek_(p: *rust_port) -> bool { pub fn select2(p_a: Port, p_b: Port) -> Either { let ports = ~[(**p_a).po, (**p_b).po]; - let yield = 0, yieldp = ptr::p2::addr_of(&yield); + let yield = 0, yieldp = ptr::addr_of(&yield); let mut resport: *rust_port; resport = rusti::init::<*rust_port>(); do vec::as_imm_buf(ports) |ports, n_ports| { - rustrt::rust_port_select(ptr::p2::addr_of(&resport), ports, + rustrt::rust_port_select(ptr::addr_of(&resport), ports, n_ports as size_t, yieldp); } diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index cfc34b03a94..7c5176494a2 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -34,7 +34,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] { let res = rustrt::tdefl_compress_mem_to_heap(b as *c_void, len as size_t, - ptr::addr_of(outsz), + ptr::addr_of(&outsz), lz_norm); assert res as int != 0; let out = vec::raw::from_buf(res as *u8, @@ -52,7 +52,7 @@ pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] { let res = rustrt::tinfl_decompress_mem_to_heap(b as *c_void, len as size_t, - ptr::addr_of(outsz), + ptr::addr_of(&outsz), 0); assert res as int != 0; let out = vec::raw::from_buf(res as *u8, diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index ace4156f5b4..de2e4412812 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -316,7 +316,7 @@ pub fn cleanup_stack_for_failure() { // own stack roots on the stack anyway. let sentinel_box = ~0; let sentinel: **Word = if expect_sentinel() { - cast::reinterpret_cast(&ptr::p2::addr_of(&sentinel_box)) + cast::reinterpret_cast(&ptr::addr_of(&sentinel_box)) } else { ptr::null() }; diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 95edeca9837..4d446df9cd5 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -85,7 +85,7 @@ use option::unwrap; const SPIN_COUNT: uint = 0; macro_rules! move_it ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); move y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } } ) #[doc(hidden)] @@ -219,7 +219,7 @@ fn unibuffer() -> ~Buffer> { #[doc(hidden)] pub fn packet() -> *Packet { let b = unibuffer(); - let p = ptr::p2::addr_of(&(b.data)); + let p = ptr::addr_of(&(b.data)); // We'll take over memory management from here. unsafe { forget(move b) } p @@ -359,7 +359,7 @@ pub fn send(+p: SendPacketBuffered, let header = p.header(); let p_ = p.unwrap(); let p = unsafe { &*p_ }; - assert ptr::p2::addr_of(&(p.header)) == header; + assert ptr::addr_of(&(p.header)) == header; assert p.payload.is_none(); p.payload <- Some(move payload); let old_state = swap_state_rel(&mut p.header.state, Full); @@ -377,7 +377,7 @@ pub fn send(+p: SendPacketBuffered, let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); if !old_task.is_null() { rustrt::task_signal_event( - old_task, ptr::p2::addr_of(&(p.header)) as *libc::c_void); + old_task, ptr::addr_of(&(p.header)) as *libc::c_void); rustrt::rust_task_deref(old_task); } @@ -529,7 +529,7 @@ fn sender_terminate(p: *Packet) { if !old_task.is_null() { rustrt::task_signal_event( old_task, - ptr::p2::addr_of(&(p.header)) as *libc::c_void); + ptr::addr_of(&(p.header)) as *libc::c_void); rustrt::rust_task_deref(old_task); } // The receiver will eventually clean up. @@ -744,7 +744,7 @@ pub fn SendPacketBuffered(p: *Packet) p: Some(p), buffer: unsafe { Some(BufferResource( - get_buffer(ptr::p2::addr_of(&((*p).header))))) + get_buffer(ptr::addr_of(&((*p).header))))) } } } @@ -760,7 +760,7 @@ impl SendPacketBuffered { match self.p { Some(packet) => unsafe { let packet = &*packet; - let header = ptr::p2::addr_of(&(packet.header)); + let header = ptr::addr_of(&(packet.header)); //forget(packet); header }, @@ -815,7 +815,7 @@ impl RecvPacketBuffered : Selectable { match self.p { Some(packet) => unsafe { let packet = &*packet; - let header = ptr::p2::addr_of(&(packet.header)); + let header = ptr::addr_of(&(packet.header)); //forget(packet); header }, @@ -838,7 +838,7 @@ pub fn RecvPacketBuffered(p: *Packet) p: Some(p), buffer: unsafe { Some(BufferResource( - get_buffer(ptr::p2::addr_of(&((*p).header))))) + get_buffer(ptr::addr_of(&((*p).header))))) } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 9f9d2eea0e6..550b0121e45 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -24,12 +24,9 @@ extern mod rusti { fn addr_of(val: T) -> *T; } -/* -Remove this after snapshot; make p2::addr_of addr_of -*/ /// Get an unsafe pointer to a value #[inline(always)] -pub pure fn addr_of(val: T) -> *T { unsafe { rusti::addr_of(val) } } +pub pure fn addr_of(val: &T) -> *T { unsafe { rusti::addr_of(*val) } } pub mod p2 { /// Get an unsafe pointer to a value diff --git a/src/libcore/str.rs b/src/libcore/str.rs index c6e7116675f..227635944dd 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1780,7 +1780,7 @@ pub pure fn as_c_str(s: &str, f: fn(*libc::c_char) -> T) -> T { #[inline(always)] pub pure fn as_buf(s: &str, f: fn(*u8, uint) -> T) -> T { unsafe { - let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::p2::addr_of(&s)); + let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(&s)); let (buf,len) = *v; f(buf, len) } diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 2095961e14e..982679f9398 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -66,7 +66,7 @@ use rt::rust_task; use rt::rust_closure; macro_rules! move_it ( - { $x:expr } => { unsafe { let y <- *ptr::p2::addr_of(&($x)); move y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } } ) type TaskSet = send_map::linear::LinearMap<*rust_task,()>; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index a8286eb4e08..d01b24f5354 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -6,7 +6,7 @@ use cmp::{Eq, Ord}; use option::{Some, None}; -use ptr::p2::addr_of; +use ptr::addr_of; use libc::size_t; export append; diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index 26b2a02ec9c..df97df51643 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -21,19 +21,19 @@ pub fn debug_tydesc() { } pub fn debug_opaque(+x: T) { - rustrt::debug_opaque(sys::get_type_desc::(), ptr::addr_of(x) as *()); + rustrt::debug_opaque(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } pub fn debug_box(x: @T) { - rustrt::debug_box(sys::get_type_desc::(), ptr::addr_of(x) as *()); + rustrt::debug_box(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } pub fn debug_tag(+x: T) { - rustrt::debug_tag(sys::get_type_desc::(), ptr::addr_of(x) as *()); + rustrt::debug_tag(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } pub fn debug_fn(+x: T) { - rustrt::debug_fn(sys::get_type_desc::(), ptr::addr_of(x) as *()); + rustrt::debug_fn(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } pub unsafe fn ptr_cast(x: @T) -> @U { diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 321eb3158a9..9aa29df4a62 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -89,11 +89,11 @@ fn get_addr(node: &str, iotask: iotask) do str::as_buf(node) |node_ptr, len| unsafe { log(debug, fmt!("slice len %?", len)); let handle = create_uv_getaddrinfo_t(); - let handle_ptr = ptr::addr_of(handle); + let handle_ptr = ptr::addr_of(&handle); let handle_data: GetAddrData = { output_ch: output_ch }; - let handle_data_ptr = ptr::addr_of(handle_data); + let handle_data_ptr = ptr::addr_of(&handle_data); do interact(iotask) |loop_ptr| unsafe { let result = uv_getaddrinfo( loop_ptr, @@ -150,7 +150,7 @@ mod v4 { impl Ipv4Rep: AsUnsafeU32 { // this is pretty dastardly, i know unsafe fn as_u32() -> u32 { - *((ptr::addr_of(self)) as *u32) + *((ptr::addr_of(&self)) as *u32) } } fn parse_to_ipv4_rep(ip: &str) -> result::Result { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 820c2bfcc4d..aedd53d41cc 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -138,7 +138,7 @@ fn connect(+input_ip: ip::IpAddr, port: uint, result_ch: core::comm::Chan(result_po), closed_signal_ch: core::comm::Chan(closed_signal_po) }; - let conn_data_ptr = ptr::addr_of(conn_data); + let conn_data_ptr = ptr::addr_of(&conn_data); let reader_po = core::comm::Port::>(); let stream_handle_ptr = malloc_uv_tcp_t(); *(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t(); @@ -150,7 +150,7 @@ fn connect(+input_ip: ip::IpAddr, port: uint, write_req: uv::ll::write_t(), iotask: iotask }; - let socket_data_ptr = ptr::addr_of(*socket_data); + let socket_data_ptr = ptr::addr_of(&(*socket_data)); log(debug, fmt!("tcp_connect result_ch %?", conn_data.result_ch)); // get an unsafe representation of our stream_handle_ptr that // we can send into the interact cb to be handled in libuv.. @@ -165,7 +165,7 @@ fn connect(+input_ip: ip::IpAddr, port: uint, log(debug, ~"tcp_init successful"); log(debug, ~"dealing w/ ipv4 connection.."); let connect_req_ptr = - ptr::addr_of((*socket_data_ptr).connect_req); + ptr::addr_of(&((*socket_data_ptr).connect_req)); let addr_str = ip::format_addr(&input_ip); let connect_result = match input_ip { ip::Ipv4(ref addr) => { @@ -179,7 +179,7 @@ fn connect(+input_ip: ip::IpAddr, port: uint, uv::ll::tcp_connect( connect_req_ptr, stream_handle_ptr, - ptr::addr_of(in_addr), + ptr::addr_of(&in_addr), tcp_connect_on_connect_cb) } ip::Ipv6(ref addr) => { @@ -188,7 +188,7 @@ fn connect(+input_ip: ip::IpAddr, port: uint, uv::ll::tcp_connect6( connect_req_ptr, stream_handle_ptr, - ptr::addr_of(in_addr), + ptr::addr_of(&in_addr), tcp_connect_on_connect_cb) } }; @@ -264,7 +264,7 @@ fn connect(+input_ip: ip::IpAddr, port: uint, */ fn write(sock: &TcpSocket, raw_write_data: ~[u8]) -> result::Result<(), TcpErrData> unsafe { - let socket_data_ptr = ptr::addr_of(*(sock.socket_data)); + let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data))); write_common_impl(socket_data_ptr, raw_write_data) } @@ -301,7 +301,7 @@ fn write(sock: &TcpSocket, raw_write_data: ~[u8]) */ fn write_future(sock: &TcpSocket, raw_write_data: ~[u8]) -> future::Future> unsafe { - let socket_data_ptr = ptr::addr_of(*(sock.socket_data)); + let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data))); do future_spawn { let data_copy = copy(raw_write_data); write_common_impl(socket_data_ptr, data_copy) @@ -326,7 +326,7 @@ fn write_future(sock: &TcpSocket, raw_write_data: ~[u8]) fn read_start(sock: &TcpSocket) -> result::Result>, TcpErrData> unsafe { - let socket_data = ptr::addr_of(*(sock.socket_data)); + let socket_data = ptr::addr_of(&(*(sock.socket_data))); read_start_common_impl(socket_data) } @@ -341,7 +341,7 @@ fn read_stop(sock: &TcpSocket, +read_port: comm::Port>) -> result::Result<(), TcpErrData> unsafe { log(debug, fmt!("taking the read_port out of commission %?", read_port)); - let socket_data = ptr::addr_of(*sock.socket_data); + let socket_data = ptr::addr_of(&(*sock.socket_data)); read_stop_common_impl(socket_data) } @@ -362,7 +362,7 @@ fn read_stop(sock: &TcpSocket, */ fn read(sock: &TcpSocket, timeout_msecs: uint) -> result::Result<~[u8],TcpErrData> { - let socket_data = ptr::addr_of(*(sock.socket_data)); + let socket_data = ptr::addr_of(&(*(sock.socket_data))); read_common_impl(socket_data, timeout_msecs) } @@ -397,7 +397,7 @@ fn read(sock: &TcpSocket, timeout_msecs: uint) */ fn read_future(sock: &TcpSocket, timeout_msecs: uint) -> future::Future> { - let socket_data = ptr::addr_of(*(sock.socket_data)); + let socket_data = ptr::addr_of(&(*(sock.socket_data))); do future_spawn { read_common_impl(socket_data, timeout_msecs) } @@ -491,7 +491,7 @@ fn accept(new_conn: TcpNewConnection) write_req : uv::ll::write_t(), iotask : iotask }; - let client_socket_data_ptr = ptr::addr_of(*client_socket_data); + let client_socket_data_ptr = ptr::addr_of(&(*client_socket_data)); let client_stream_handle_ptr = (*client_socket_data_ptr).stream_handle_ptr; @@ -596,7 +596,7 @@ fn listen_common(+host_ip: ip::IpAddr, port: uint, backlog: uint, let kill_po = core::comm::Port::>(); let kill_ch = core::comm::Chan(kill_po); let server_stream = uv::ll::tcp_t(); - let server_stream_ptr = ptr::addr_of(server_stream); + let server_stream_ptr = ptr::addr_of(&server_stream); let server_data = { server_stream_ptr: server_stream_ptr, stream_closed_ch: core::comm::Chan(stream_closed_po), @@ -605,7 +605,7 @@ fn listen_common(+host_ip: ip::IpAddr, port: uint, backlog: uint, iotask: iotask, mut active: true }; - let server_data_ptr = ptr::addr_of(server_data); + let server_data_ptr = ptr::addr_of(&server_data); let setup_result = do core::comm::listen |setup_ch| { // this is to address a compiler warning about @@ -627,13 +627,13 @@ fn listen_common(+host_ip: ip::IpAddr, port: uint, backlog: uint, log(debug, fmt!("addr: %?", addr)); let in_addr = uv::ll::ip4_addr(addr_str, port as int); uv::ll::tcp_bind(server_stream_ptr, - ptr::addr_of(in_addr)) + ptr::addr_of(&in_addr)) } ip::Ipv6(ref addr) => { log(debug, fmt!("addr: %?", addr)); let in_addr = uv::ll::ip6_addr(addr_str, port as int); uv::ll::tcp_bind6(server_stream_ptr, - ptr::addr_of(in_addr)) + ptr::addr_of(&in_addr)) } }; match bind_result { @@ -818,7 +818,7 @@ impl TcpSocketBuf: io::Reader { impl TcpSocketBuf: io::Writer { fn write(data: &[const u8]) unsafe { let socket_data_ptr = - ptr::addr_of(*((*(self.data)).sock).socket_data); + ptr::addr_of(&(*((*(self.data)).sock).socket_data)); let w_result = write_common_impl(socket_data_ptr, vec::slice(data, 0, vec::len(data))); if w_result.is_err() { @@ -850,7 +850,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) unsafe { let close_data = { closed_ch: closed_ch }; - let close_data_ptr = ptr::addr_of(close_data); + let close_data_ptr = ptr::addr_of(&close_data); let stream_handle_ptr = (*socket_data).stream_handle_ptr; do iotask::interact((*socket_data).iotask) |loop_ptr| unsafe { log(debug, fmt!("interact dtor for tcp_socket stream %? loop %?", @@ -966,18 +966,18 @@ fn read_start_common_impl(socket_data: *TcpSocketData) fn write_common_impl(socket_data_ptr: *TcpSocketData, raw_write_data: ~[u8]) -> result::Result<(), TcpErrData> unsafe { - let write_req_ptr = ptr::addr_of((*socket_data_ptr).write_req); + let write_req_ptr = ptr::addr_of(&((*socket_data_ptr).write_req)); let stream_handle_ptr = (*socket_data_ptr).stream_handle_ptr; let write_buf_vec = ~[ uv::ll::buf_init( vec::raw::to_ptr(raw_write_data), vec::len(raw_write_data)) ]; - let write_buf_vec_ptr = ptr::addr_of(write_buf_vec); + let write_buf_vec_ptr = ptr::addr_of(&write_buf_vec); let result_po = core::comm::Port::(); let write_data = { result_ch: core::comm::Chan(result_po) }; - let write_data_ptr = ptr::addr_of(write_data); + let write_data_ptr = ptr::addr_of(&write_data); do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| unsafe { log(debug, fmt!("in interact cb for tcp::write %?", loop_ptr)); match uv::ll::write(write_req_ptr, diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 2b2cd2b0ba7..f66f2f5b5d3 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -773,7 +773,7 @@ mod tests { let m = ~Mutex(); let m2 = ~m.clone(); let mut sharedstate = ~0; - let ptr = ptr::addr_of(*sharedstate); + let ptr = ptr::p2::addr_of(&(*sharedstate)); do task::spawn { let sharedstate: &mut int = unsafe { cast::reinterpret_cast(&ptr) }; @@ -1045,7 +1045,7 @@ mod tests { let (c,p) = pipes::stream(); let x2 = ~x.clone(); let mut sharedstate = ~0; - let ptr = ptr::addr_of(*sharedstate); + let ptr = ptr::p2::addr_of(&(*sharedstate)); do task::spawn { let sharedstate: &mut int = unsafe { cast::reinterpret_cast(&ptr) }; diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index a2f9796f89e..8aaf7d3fd87 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -28,9 +28,9 @@ pub fn delayed_send(iotask: IoTask, unsafe { let timer_done_po = core::comm::Port::<()>(); let timer_done_ch = core::comm::Chan(timer_done_po); - let timer_done_ch_ptr = ptr::addr_of(timer_done_ch); + let timer_done_ch_ptr = ptr::addr_of(&timer_done_ch); let timer = uv::ll::timer_t(); - let timer_ptr = ptr::addr_of(timer); + let timer_ptr = ptr::addr_of(&timer); do iotask::interact(iotask) |loop_ptr| unsafe { let init_result = uv::ll::timer_init(loop_ptr, timer_ptr); if (init_result == 0i32) { diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 508426588d0..9ccacd1f7f6 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -138,11 +138,11 @@ mod test { fn impl_uv_hl_simple_timer(iotask: IoTask) unsafe { let exit_po = core::comm::Port::(); let exit_ch = core::comm::Chan(exit_po); - let exit_ch_ptr = ptr::addr_of(exit_ch); + let exit_ch_ptr = ptr::p2::addr_of(&exit_ch); log(debug, fmt!("EXIT_CH_PTR newly created exit_ch_ptr: %?", exit_ch_ptr)); let timer_handle = ll::timer_t(); - let timer_ptr = ptr::addr_of(timer_handle); + let timer_ptr = ptr::p2::addr_of(&timer_handle); do iotask::interact(iotask) |loop_ptr| unsafe { log(debug, ~"user code inside interact loop!!!"); let init_status = ll::timer_init(loop_ptr, timer_ptr); diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index c31238ecf4f..ab50cc9d929 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -13,7 +13,7 @@ export interact; export exit; use libc::c_void; -use ptr::addr_of; +use ptr::p2::addr_of; use comm = core::comm; use comm::{Port, Chan, listen}; use task::TaskBuilder; @@ -96,7 +96,7 @@ fn run_loop(iotask_ch: Chan) unsafe { // set up the special async handle we'll use to allow multi-task // communication with this loop let async = ll::async_t(); - let async_handle = addr_of(async); + let async_handle = addr_of(&async); // associate the async handle with the loop ll::async_init(loop_ptr, async_handle, wake_up_cb); @@ -106,7 +106,7 @@ fn run_loop(iotask_ch: Chan) unsafe { async_handle: async_handle, msg_po: Port() }; - ll::set_data_for_uv_handle(async_handle, addr_of(data)); + ll::set_data_for_uv_handle(async_handle, addr_of(&data)); // Send out a handle through which folks can talk to us // while we dwell in the I/O loop @@ -188,14 +188,14 @@ mod test { }; fn impl_uv_iotask_async(iotask: IoTask) unsafe { let async_handle = ll::async_t(); - let ah_ptr = ptr::addr_of(async_handle); + let ah_ptr = ptr::addr_of(&async_handle); let exit_po = core::comm::Port::<()>(); let exit_ch = core::comm::Chan(exit_po); let ah_data = { iotask: iotask, exit_ch: exit_ch }; - let ah_data_ptr = ptr::addr_of(ah_data); + let ah_data_ptr = ptr::addr_of(&ah_data); do interact(iotask) |loop_ptr| unsafe { ll::async_init(loop_ptr, ah_ptr, async_handle_cb); ll::set_data_for_uv_handle(ah_ptr, ah_data_ptr as *libc::c_void); diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 6d212cd7e92..fca34c01bc1 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -796,7 +796,7 @@ unsafe fn async_send(async_handle: *uv_async_t) { } unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { let out_buf = { base: ptr::null(), len: 0 as libc::size_t }; - let out_buf_ptr = ptr::addr_of(out_buf); + let out_buf_ptr = ptr::addr_of(&out_buf); log(debug, fmt!("buf_init - input %u len %u out_buf: %u", input as uint, len as uint, @@ -968,7 +968,7 @@ unsafe fn free_base_of_buf(buf: uv_buf_t) { unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(err); + let err_ptr = ptr::addr_of(&err); let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); return fmt!("LIBUV ERROR: name: %s msg: %s", @@ -977,7 +977,7 @@ unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data { let err = last_error(uv_loop); - let err_ptr = ptr::addr_of(err); + let err_ptr = ptr::addr_of(&err); let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); { err_name: err_name, err_msg: err_msg } @@ -1120,9 +1120,9 @@ mod test { client_chan: *comm::Chan<~str>) unsafe { let test_loop = loop_new(); let tcp_handle = tcp_t(); - let tcp_handle_ptr = ptr::addr_of(tcp_handle); + let tcp_handle_ptr = ptr::addr_of(&tcp_handle); let connect_handle = connect_t(); - let connect_req_ptr = ptr::addr_of(connect_handle); + let connect_req_ptr = ptr::addr_of(&connect_handle); // this is the persistent payload of data that we // need to pass around to get this example to work. @@ -1138,12 +1138,12 @@ mod test { // this is the enclosing record, we'll pass a ptr to // this to C.. let write_handle = write_t(); - let write_handle_ptr = ptr::addr_of(write_handle); + let write_handle_ptr = ptr::addr_of(&write_handle); log(debug, fmt!("tcp req: tcp stream: %d write_handle: %d", tcp_handle_ptr as int, write_handle_ptr as int)); let client_data = { writer_handle: write_handle_ptr, - req_buf: ptr::addr_of(req_msg), + req_buf: ptr::addr_of(&req_msg), read_chan: client_chan }; let tcp_init_result = tcp_init( @@ -1154,7 +1154,7 @@ mod test { log(debug, ~"building addr..."); let addr = ip4_addr(ip, port); // FIXME ref #2064 - let addr_ptr = ptr::addr_of(addr); + let addr_ptr = ptr::addr_of(&addr); log(debug, fmt!("after build addr in rust. port: %u", addr.sin_port as uint)); @@ -1169,10 +1169,10 @@ mod test { // until its initialized set_data_for_req( connect_req_ptr as *libc::c_void, - ptr::addr_of(client_data) as *libc::c_void); + ptr::addr_of(&client_data) as *libc::c_void); set_data_for_uv_handle( tcp_handle_ptr as *libc::c_void, - ptr::addr_of(client_data) as *libc::c_void); + ptr::addr_of(&client_data) as *libc::c_void); log(debug, ~"before run tcp req loop"); run(test_loop); log(debug, ~"after run tcp req loop"); @@ -1369,13 +1369,13 @@ mod test { continue_chan: *comm::Chan) unsafe { let test_loop = loop_new(); let tcp_server = tcp_t(); - let tcp_server_ptr = ptr::addr_of(tcp_server); + let tcp_server_ptr = ptr::addr_of(&tcp_server); let tcp_client = tcp_t(); - let tcp_client_ptr = ptr::addr_of(tcp_client); + let tcp_client_ptr = ptr::addr_of(&tcp_client); let server_write_req = write_t(); - let server_write_req_ptr = ptr::addr_of(server_write_req); + let server_write_req_ptr = ptr::addr_of(&server_write_req); let resp_str_bytes = str::to_bytes(server_resp_msg); let resp_msg_ptr: *u8 = vec::raw::to_ptr(resp_str_bytes); @@ -1386,20 +1386,20 @@ mod test { let continue_async_handle = async_t(); let continue_async_handle_ptr = - ptr::addr_of(continue_async_handle); + ptr::addr_of(&continue_async_handle); let async_data = { continue_chan: continue_chan }; - let async_data_ptr = ptr::addr_of(async_data); + let async_data_ptr = ptr::addr_of(&async_data); let server_data: tcp_server_data = { client: tcp_client_ptr, server: tcp_server_ptr, server_kill_msg: kill_server_msg, - server_resp_buf: ptr::addr_of(resp_msg), + server_resp_buf: ptr::addr_of(&resp_msg), server_chan: server_chan, server_write_req: server_write_req_ptr }; - let server_data_ptr = ptr::addr_of(server_data); + let server_data_ptr = ptr::addr_of(&server_data); set_data_for_uv_handle(tcp_server_ptr as *libc::c_void, server_data_ptr as *libc::c_void); @@ -1409,7 +1409,7 @@ mod test { if (tcp_init_result == 0i32) { let server_addr = ip4_addr(server_ip, server_port); // FIXME ref #2064 - let server_addr_ptr = ptr::addr_of(server_addr); + let server_addr_ptr = ptr::addr_of(&server_addr); // uv_tcp_bind() let bind_result = tcp_bind(tcp_server_ptr, @@ -1478,13 +1478,13 @@ mod test { let continue_port = core::comm::Port::(); let continue_chan = core::comm::Chan::(continue_port); - let continue_chan_ptr = ptr::addr_of(continue_chan); + let continue_chan_ptr = ptr::addr_of(&continue_chan); - do task::spawn_sched(task::ManualThreads(1u)) { + do task::spawn_sched(task::ManualThreads(1)) { impl_uv_tcp_server(bind_ip, port, kill_server_msg, server_resp_msg, - ptr::addr_of(server_chan), + ptr::addr_of(&server_chan), continue_chan_ptr); }; @@ -1496,7 +1496,7 @@ mod test { do task::spawn_sched(task::ManualThreads(1u)) { impl_uv_tcp_request(request_ip, port, kill_server_msg, - ptr::addr_of(client_chan)); + ptr::addr_of(&client_chan)); }; let msg_from_client = core::comm::recv(server_port); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3e62d0b3ab7..67841158ce1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1094,10 +1094,10 @@ enum ty_ { // since we only care about this for normalizing them to "real" types. impl ty : cmp::Eq { pure fn eq(other: &ty) -> bool { - ptr::addr_of(self) == ptr::addr_of((*other)) + ptr::addr_of(&self) == ptr::addr_of(&(*other)) } pure fn ne(other: &ty) -> bool { - ptr::addr_of(self) != ptr::addr_of((*other)) + ptr::addr_of(&self) != ptr::addr_of(&(*other)) } } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 619511f0454..ea493eab561 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -188,7 +188,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, return make_conv_call(cx, arg.span, ~"float", cnv, arg); } TyPoly => return make_conv_call(cx, arg.span, ~"poly", cnv, - mk_addr_of(cx, sp, arg)) + mk_addr_of(cx, sp, arg)) } } fn log_conv(c: Conv) { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index cec2972b2a7..9c10d228a23 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -71,10 +71,10 @@ impl message: gen_send { body += ~"let b = pipe.reuse_buffer();\n"; body += fmt!("let %s = pipes::SendPacketBuffered(\ - ptr::p2::addr_of(&(b.buffer.data.%s)));\n", + ptr::addr_of(&(b.buffer.data.%s)));\n", sp, next.name); body += fmt!("let %s = pipes::RecvPacketBuffered(\ - ptr::p2::addr_of(&(b.buffer.data.%s)));\n", + ptr::addr_of(&(b.buffer.data.%s)));\n", rp, next.name); } else { @@ -351,7 +351,7 @@ impl protocol: gen_init { fmt!("data.%s.set_buffer_(buffer)", s.name))), ext_cx.parse_expr( - fmt!("ptr::p2::addr_of(&(data.%s))", + fmt!("ptr::addr_of(&(data.%s))", self.states[0].name)))); #ast {{ diff --git a/src/rustc/middle/lang_items.rs b/src/rustc/middle/lang_items.rs index ea22e3a7809..7cb2c9eb9cf 100644 --- a/src/rustc/middle/lang_items.rs +++ b/src/rustc/middle/lang_items.rs @@ -179,7 +179,7 @@ impl LanguageItemCollector { } fn collect_local_language_items() { - let this = unsafe { ptr::addr_of(self) }; + let this = unsafe { ptr::addr_of(&self) }; visit_crate(*self.crate, (), mk_simple_visitor(@{ visit_item: |item| { for item.attrs.each |attribute| { diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index 90762c5b714..69b325b03a4 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -416,7 +416,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, let fn_maps = @IrMaps(self.tcx, self.method_map, self.last_use_map); - debug!("creating fn_maps: %x", ptr::addr_of(*fn_maps) as uint); + debug!("creating fn_maps: %x", ptr::addr_of(&(*fn_maps)) as uint); for decl.inputs.each |arg| { debug!("adding argument %d", arg.id); diff --git a/src/rustc/middle/trans/build.rs b/src/rustc/middle/trans/build.rs index 070132b4b18..69de8a2cca3 100644 --- a/src/rustc/middle/trans/build.rs +++ b/src/rustc/middle/trans/build.rs @@ -134,7 +134,7 @@ fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) { // lot more efficient) than doing str::as_c_str("", ...) every time. fn noname() -> *libc::c_char unsafe { const cnull: uint = 0u; - return cast::reinterpret_cast(&ptr::addr_of(cnull)); + return cast::reinterpret_cast(&ptr::addr_of(&cnull)); } fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef], @@ -629,8 +629,8 @@ fn Phi(cx: block, Ty: TypeRef, vals: ~[ValueRef], bbs: ~[BasicBlockRef]) fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; } unsafe { - let valptr = cast::reinterpret_cast(&ptr::addr_of(val)); - let bbptr = cast::reinterpret_cast(&ptr::addr_of(bb)); + let valptr = cast::reinterpret_cast(&ptr::addr_of(&val)); + let bbptr = cast::reinterpret_cast(&ptr::addr_of(&bb)); llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint); } } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index 907146be4fd..d68bdb08221 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -645,7 +645,7 @@ impl block { fmt!("[block %d]", node_info.id) } None => { - fmt!("[block %x]", ptr::addr_of(*self) as uint) + fmt!("[block %x]", ptr::addr_of(&(*self)) as uint) } } } diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 41acc2ce070..368b69cafab 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -605,7 +605,7 @@ impl @fn_ctxt: region_scope { } impl @fn_ctxt { - fn tag() -> ~str { fmt!("%x", ptr::addr_of(*self) as uint) } + fn tag() -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) } fn expr_to_str(expr: @ast::expr) -> ~str { fmt!("expr(%?:%s)", expr.id, diff --git a/src/test/auxiliary/test_comm.rs b/src/test/auxiliary/test_comm.rs index b150b58c638..77f107fda09 100644 --- a/src/test/auxiliary/test_comm.rs +++ b/src/test/auxiliary/test_comm.rs @@ -34,7 +34,7 @@ struct port_ptr { debug!("in the port_ptr destructor"); do task::unkillable { let yield = 0u; - let yieldp = ptr::addr_of(yield); + let yieldp = ptr::addr_of(&yield); rustrt::rust_port_begin_detach(self.po, yieldp); if yield != 0u { task::yield(); @@ -66,10 +66,10 @@ fn recv(p: port) -> T { recv_((**p).po) } /// Receive on a raw port pointer fn recv_(p: *rust_port) -> T { let yield = 0u; - let yieldp = ptr::addr_of(yield); + let yieldp = ptr::addr_of(&yield); let mut res; res = rusti::init::(); - rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp); + rustrt::port_recv(ptr::addr_of(&res) as *uint, p, yieldp); if yield != 0u { // Data isn't available yet, so res has not been initialized. diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 392f67d6714..0a55e7572db 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -19,7 +19,7 @@ use io::WriterUtil; use pipes::{Port, Chan, SharedChan}; macro_rules! move_out ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); y } } ) enum request { diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 6ba8b71d8c4..ab67a8c7cb1 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -15,7 +15,7 @@ use io::WriterUtil; use pipes::{Port, PortSet, Chan}; macro_rules! move_out ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); y } } ) enum request { diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 3c888fd0c8d..119c2065d6b 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -24,7 +24,7 @@ proto! ring ( fn macros() { #macro[ [#move_out[x], - unsafe { let y <- *ptr::addr_of(x); y }] + unsafe { let y <- *ptr::addr_of(&x); y }] ]; } diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs index 570ec8c0b6b..70f98934e1b 100644 --- a/src/test/bench/pingpong.rs +++ b/src/test/bench/pingpong.rs @@ -33,7 +33,7 @@ proto! pingpong_unbounded ( // This stuff should go in libcore::pipes macro_rules! move_it ( - { $x:expr } => { let t <- *ptr::addr_of($x); t } + { $x:expr } => { let t <- *ptr::addr_of(&($x)); t } ) macro_rules! follow ( diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index 3add41792f3..62612366524 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -32,7 +32,7 @@ use cmp::Eq; use to_bytes::IterBytes; macro_rules! move_out ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); y } } ) trait word_reader { diff --git a/src/test/run-pass/binops.rs b/src/test/run-pass/binops.rs index 0cc828132c9..cfcb158a990 100644 --- a/src/test/run-pass/binops.rs +++ b/src/test/run-pass/binops.rs @@ -103,8 +103,8 @@ fn test_class() { unsafe { error!("q = %x, r = %x", - (cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(q))), - (cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(r)))); + (cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(&q))), + (cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(&r)))); } assert(q == r); r.y = 17; diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index ec31225f46b..d180fc4b8ae 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -7,7 +7,7 @@ fn borrow(x: &int, f: fn(x: &int)) { fn test1(x: @~int) { // Right now, at least, this induces a copy of the unique pointer: do borrow({*x}) |p| { - let x_a = ptr::addr_of(**x); + let x_a = ptr::addr_of(&(**x)); assert (x_a as uint) != to_uint(p); assert unsafe{*x_a} == *p; } diff --git a/src/test/run-pass/borrowck-preserve-box-in-discr.rs b/src/test/run-pass/borrowck-preserve-box-in-discr.rs index 373830d77af..5ed78488b35 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-discr.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-discr.rs @@ -5,13 +5,13 @@ fn main() { match *x { {f: b_x} => { assert *b_x == 3; - assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); x = @{f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(*b_x) as uint); + debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); assert *b_x == 3; - assert ptr::addr_of(*x.f) != ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)); } } } \ No newline at end of file diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs index 7ab2dc4b99d..d7d3aa68faf 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-field.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-field.rs @@ -11,11 +11,11 @@ fn main() { let mut x = @{f: ~3}; do borrow(x.f) |b_x| { assert *b_x == 3; - assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); x = @{f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(*b_x) as uint); + debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); assert *b_x == 3; - assert ptr::addr_of(*x.f) != ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)); } } \ No newline at end of file diff --git a/src/test/run-pass/borrowck-preserve-box-in-pat.rs b/src/test/run-pass/borrowck-preserve-box-in-pat.rs index 599879f82f1..f0944ea3544 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-pat.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-pat.rs @@ -5,13 +5,13 @@ fn main() { match x { @@{f: b_x} => { assert *b_x == 3; - assert ptr::addr_of(x.f) == ptr::addr_of(b_x); + assert ptr::addr_of(&(x.f)) == ptr::addr_of(&(b_x)); *x = @{f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(*b_x) as uint); + debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); assert *b_x == 3; - assert ptr::addr_of(*x.f) != ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)); } } } diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index bd43ad65cff..b0bb4d8d40c 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -11,11 +11,11 @@ fn main() { let mut x = ~mut @{f: ~3}; do borrow(x.f) |b_x| { assert *b_x == 3; - assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); *x = @{f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(*b_x) as uint); + debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); assert *b_x == 3; - assert ptr::addr_of(*x.f) != ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)); } } \ No newline at end of file diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs index 8d59975204b..88f4b459d36 100644 --- a/src/test/run-pass/borrowck-preserve-box.rs +++ b/src/test/run-pass/borrowck-preserve-box.rs @@ -11,11 +11,11 @@ fn main() { let mut x = @3; do borrow(x) |b_x| { assert *b_x == 3; - assert ptr::addr_of(*x) == ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x)) == ptr::addr_of(&(*b_x)); x = @22; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(*b_x) as uint); + debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); assert *b_x == 3; - assert ptr::addr_of(*x) != ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x)) != ptr::addr_of(&(*b_x)); } } \ No newline at end of file diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs index e126ecc4340..ba525eafc51 100644 --- a/src/test/run-pass/borrowck-preserve-expl-deref.rs +++ b/src/test/run-pass/borrowck-preserve-expl-deref.rs @@ -11,11 +11,11 @@ fn main() { let mut x = @{f: ~3}; do borrow((*x).f) |b_x| { assert *b_x == 3; - assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); x = @{f: ~4}; - debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(*b_x) as uint); + debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint); assert *b_x == 3; - assert ptr::addr_of(*x.f) != ptr::addr_of(*b_x); + assert ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)); } } diff --git a/src/test/run-pass/cap-clause-move.rs b/src/test/run-pass/cap-clause-move.rs index 260c1d45b76..0561af6ca6d 100644 --- a/src/test/run-pass/cap-clause-move.rs +++ b/src/test/run-pass/cap-clause-move.rs @@ -1,29 +1,29 @@ fn main() { let x = ~1; - let y = ptr::addr_of(*x) as uint; - let lam_copy = fn@(copy x) -> uint { ptr::addr_of(*x) as uint }; - let lam_move = fn@(move x) -> uint { ptr::addr_of(*x) as uint }; + let y = ptr::addr_of(&(*x)) as uint; + let lam_copy = fn@(copy x) -> uint { ptr::addr_of(&(*x)) as uint }; + let lam_move = fn@(move x) -> uint { ptr::addr_of(&(*x)) as uint }; assert lam_copy() != y; assert lam_move() == y; let x = ~2; - let y = ptr::addr_of(*x) as uint; - let lam_copy: fn@() -> uint = |copy x| ptr::addr_of(*x) as uint; - let lam_move: fn@() -> uint = |move x| ptr::addr_of(*x) as uint; + let y = ptr::addr_of(&(*x)) as uint; + let lam_copy: fn@() -> uint = |copy x| ptr::addr_of(&(*x)) as uint; + let lam_move: fn@() -> uint = |move x| ptr::addr_of(&(*x)) as uint; assert lam_copy() != y; assert lam_move() == y; let x = ~3; - let y = ptr::addr_of(*x) as uint; - let snd_copy = fn~(copy x) -> uint { ptr::addr_of(*x) as uint }; - let snd_move = fn~(move x) -> uint { ptr::addr_of(*x) as uint }; + let y = ptr::addr_of(&(*x)) as uint; + let snd_copy = fn~(copy x) -> uint { ptr::addr_of(&(*x)) as uint }; + let snd_move = fn~(move x) -> uint { ptr::addr_of(&(*x)) as uint }; assert snd_copy() != y; assert snd_move() == y; let x = ~4; - let y = ptr::addr_of(*x) as uint; - let lam_copy: fn~() -> uint = |copy x| ptr::addr_of(*x) as uint; - let lam_move: fn~() -> uint = |move x| ptr::addr_of(*x) as uint; + let y = ptr::addr_of(&(*x)) as uint; + let lam_copy: fn~() -> uint = |copy x| ptr::addr_of(&(*x)) as uint; + let lam_move: fn~() -> uint = |move x| ptr::addr_of(&(*x)) as uint; assert lam_copy() != y; assert lam_move() == y; } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 6da4349ba5f..b887b86cf2f 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -201,7 +201,7 @@ mod pingpong { fn liberate_ping(-p: ping) -> pipes::send_packet unsafe { let addr : *pipes::send_packet = match p { - ping(x) => { cast::transmute(ptr::addr_of(x)) } + ping(x) => { cast::transmute(ptr::addr_of(&x)) } }; let liberated_value <- *addr; cast::forget(p); @@ -210,7 +210,7 @@ mod pingpong { fn liberate_pong(-p: pong) -> pipes::send_packet unsafe { let addr : *pipes::send_packet = match p { - pong(x) => { cast::transmute(ptr::addr_of(x)) } + pong(x) => { cast::transmute(ptr::addr_of(&x)) } }; let liberated_value <- *addr; cast::forget(p); diff --git a/src/test/run-pass/last-use-corner-cases.rs b/src/test/run-pass/last-use-corner-cases.rs index 2d8e3aa7b8c..a3088a2c125 100644 --- a/src/test/run-pass/last-use-corner-cases.rs +++ b/src/test/run-pass/last-use-corner-cases.rs @@ -4,14 +4,14 @@ fn main() { // Make sure closing over can be a last use let q = ~10; - let addr = ptr::addr_of(*q); - let f = fn@() -> *int { ptr::addr_of(*q) }; + let addr = ptr::addr_of(&(*q)); + let f = fn@() -> *int { ptr::addr_of(&(*q)) }; assert addr == f(); // But only when it really is the last use let q = ~20; - let f = fn@() -> *int { ptr::addr_of(*q) }; - assert ptr::addr_of(*q) != f(); + let f = fn@() -> *int { ptr::addr_of(&(*q)) }; + assert ptr::addr_of(&(*q)) != f(); // Ensure function arguments and box arguments interact sanely. fn call_me(x: fn() -> int, y: ~int) { assert x() == *y; } diff --git a/src/test/run-pass/pipe-bank-proto.rs b/src/test/run-pass/pipe-bank-proto.rs index 8ac76293284..899b74b2866 100644 --- a/src/test/run-pass/pipe-bank-proto.rs +++ b/src/test/run-pass/pipe-bank-proto.rs @@ -33,7 +33,7 @@ proto! bank ( ) macro_rules! move_it ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); y } } ) fn switch(+endp: pipes::RecvPacket, diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index f9f091131ab..9bfbbe338e7 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -28,7 +28,7 @@ mod pingpong { do pipes::entangle_buffer(buffer) |buffer, data| { data.ping.set_buffer_(buffer); data.pong.set_buffer_(buffer); - ptr::addr_of(data.ping) + ptr::addr_of(&(data.ping)) } } enum ping = server::pong; @@ -38,8 +38,8 @@ mod pingpong { fn ping(+pipe: ping) -> pong { { let b = pipe.reuse_buffer(); - let s = SendPacketBuffered(ptr::addr_of(b.buffer.data.pong)); - let c = RecvPacketBuffered(ptr::addr_of(b.buffer.data.pong)); + let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.pong))); + let c = RecvPacketBuffered(ptr::addr_of(&(b.buffer.data.pong))); let message = pingpong::ping(s); pipes::send(pipe, message); c @@ -57,8 +57,8 @@ mod pingpong { fn pong(+pipe: pong) -> ping { { let b = pipe.reuse_buffer(); - let s = SendPacketBuffered(ptr::addr_of(b.buffer.data.ping)); - let c = RecvPacketBuffered(ptr::addr_of(b.buffer.data.ping)); + let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.ping))); + let c = RecvPacketBuffered(ptr::addr_of(&(b.buffer.data.ping))); let message = pingpong::pong(s); pipes::send(pipe, message); c diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index affd0ef6162..e27aaa618ac 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -612,7 +612,7 @@ fn get_tydesc_for(&&_t: T) -> *TyDesc { fn main() { let r = (1,2,3,true,false,{x:5,y:4,z:3}); - let p = ptr::addr_of(r) as *c_void; + let p = ptr::addr_of(&r) as *c_void; let u = my_visitor(@{mut ptr1: p, mut ptr2: p, mut vals: ~[]}); diff --git a/src/test/run-pass/resource-cycle.rs b/src/test/run-pass/resource-cycle.rs index 9e0a2c35e2f..26e19ee1b0c 100644 --- a/src/test/run-pass/resource-cycle.rs +++ b/src/test/run-pass/resource-cycle.rs @@ -4,8 +4,8 @@ struct r { v: *int, drop unsafe { debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x", - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)), - cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)), + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&self)), + cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(&(self.v))), cast::reinterpret_cast::<*int, uint>(&self.v)); let v2: ~int = cast::reinterpret_cast(&self.v); } } @@ -34,27 +34,27 @@ fn main() unsafe { r: { let rs = r(i1p); debug!("r = %x", - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs))); + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&rs))); rs } }); debug!("x1 = %x, x1.r = %x", cast::reinterpret_cast::<@t, uint>(&x1), - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(x1.r))); + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x1.r)))); let x2 = @t({ mut next: None, r: { let rs = r(i2p); debug!("r2 = %x", - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs))); + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&rs))); rs } }); debug!("x2 = %x, x2.r = %x", cast::reinterpret_cast::<@t, uint>(&x2), - cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(x2.r))); + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x2.r)))); x1.next = Some(x2); x2.next = Some(x1); diff --git a/src/test/run-pass/rt-sched-1.rs b/src/test/run-pass/rt-sched-1.rs index 9604dff64d7..15207b668fe 100644 --- a/src/test/run-pass/rt-sched-1.rs +++ b/src/test/run-pass/rt-sched-1.rs @@ -33,7 +33,7 @@ fn main() unsafe { assert child_sched_id == new_sched_id; comm::send(ch, ()); }; - let fptr = cast::reinterpret_cast(&ptr::addr_of(f)); + let fptr = cast::reinterpret_cast(&ptr::addr_of(&f)); rustrt::start_task(new_task_id, fptr); cast::forget(f); comm::recv(po); diff --git a/src/test/run-pass/select-macro.rs b/src/test/run-pass/select-macro.rs index 15dd56e46c5..78bddffcc1d 100644 --- a/src/test/run-pass/select-macro.rs +++ b/src/test/run-pass/select-macro.rs @@ -28,7 +28,7 @@ macro_rules! select_if ( match move pipes::try_recv($port) { $(Some($message($($(ref $x,)+)* ref next)) => { // FIXME (#2329) we really want move out of enum here. - let $next = unsafe { let x <- *ptr::addr_of(*next); x }; + let $next = unsafe { let x <- *ptr::addr_of(&(*next)); x }; $e })+ _ => fail diff --git a/src/test/run-pass/stable-addr-of.rs b/src/test/run-pass/stable-addr-of.rs index 060994ed48f..dceb80331b4 100644 --- a/src/test/run-pass/stable-addr-of.rs +++ b/src/test/run-pass/stable-addr-of.rs @@ -2,5 +2,5 @@ fn main() { let foo = 1; - assert ptr::addr_of(foo) == ptr::addr_of(foo); + assert ptr::addr_of(&foo) == ptr::addr_of(&foo); } diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 98d5193c86d..405ba82b790 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -10,7 +10,7 @@ struct notify { drop { error!("notify: task=%? v=%x unwinding=%b b=%b", task::get_task(), - ptr::addr_of(*(self.v)) as uint, + ptr::addr_of(&(*(self.v))) as uint, task::failing(), *(self.v)); let b = *(self.v); @@ -30,7 +30,7 @@ fn joinable(+f: fn~()) -> comm::Port { let b = @mut false; error!("wrapper: task=%? allocated v=%x", task::get_task(), - ptr::addr_of(*b) as uint); + ptr::addr_of(&(*b)) as uint); let _r = notify(c, b); f(); *b = true; diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index 9cedfea6130..7316a927751 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -3,16 +3,16 @@ fn main() { let ch = comm::Chan(p); let x = ~1; - let x_in_parent = ptr::addr_of(*x) as uint; + let x_in_parent = ptr::addr_of(&(*x)) as uint; let y = ~2; - let y_in_parent = ptr::addr_of(*y) as uint; + let y_in_parent = ptr::addr_of(&(*y)) as uint; task::spawn(fn~(copy ch, copy y, move x) { - let x_in_child = ptr::addr_of(*x) as uint; + let x_in_child = ptr::addr_of(&(*x)) as uint; comm::send(ch, x_in_child); - let y_in_child = ptr::addr_of(*y) as uint; + let y_in_child = ptr::addr_of(&(*y)) as uint; comm::send(ch, y_in_child); }); // Ensure last-use analysis doesn't move y to child. diff --git a/src/test/run-pass/uniq-cc-generic.rs b/src/test/run-pass/uniq-cc-generic.rs index 18c3db591f6..592d49cc2a8 100644 --- a/src/test/run-pass/uniq-cc-generic.rs +++ b/src/test/run-pass/uniq-cc-generic.rs @@ -9,7 +9,7 @@ type pointy = { }; fn make_uniq_closure(a: A) -> fn~() -> uint { - fn~() -> uint { ptr::addr_of(a) as uint } + fn~() -> uint { ptr::addr_of(&a) as uint } } fn empty_pointy() -> @pointy { -- cgit 1.4.1-3-g733a5 From 0a950f394dbe3275c4879dc1f26f78a096f93e28 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 26 Sep 2012 15:04:33 -0700 Subject: test: un-xfail the auto_serialize for boxes test --- src/test/run-pass/auto_serialize2-box.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/test') diff --git a/src/test/run-pass/auto_serialize2-box.rs b/src/test/run-pass/auto_serialize2-box.rs index e395b1bfe5d..286b0eba5a1 100644 --- a/src/test/run-pass/auto_serialize2-box.rs +++ b/src/test/run-pass/auto_serialize2-box.rs @@ -1,5 +1,3 @@ -// xfail-test FIXME Blocked on (#3585) - extern mod std; // These tests used to be separate files, but I wanted to refactor all -- cgit 1.4.1-3-g733a5 From 81423a3866fb6cd4cadd28ed49273d7e22d48c17 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 26 Sep 2012 21:35:13 -0700 Subject: Add deserializable and more types to serialization2 --- src/libstd/ebml2.rs | 93 ++++++++++---- src/libstd/json.rs | 176 +++++++++++++++++--------- src/libstd/prettyprint2.rs | 63 +++++++--- src/libstd/serialization2.rs | 208 +++++++++++++++++++++++++++---- src/libsyntax/ext/auto_serialize2.rs | 189 +++++++++++++++++++--------- src/test/run-pass/auto_serialize2-box.rs | 71 ----------- src/test/run-pass/auto_serialize2.rs | 47 ++++++- 7 files changed, 581 insertions(+), 266 deletions(-) delete mode 100644 src/test/run-pass/auto_serialize2-box.rs (limited to 'src/test') diff --git a/src/libstd/ebml2.rs b/src/libstd/ebml2.rs index 10653760368..3ed6426b829 100644 --- a/src/libstd/ebml2.rs +++ b/src/libstd/ebml2.rs @@ -384,7 +384,25 @@ impl Serializer: serialization2::Serializer { fail ~"Unimplemented: serializing a float"; } - fn emit_str(&self, v: &str) { self.wr_tagged_str(EsStr as uint, v) } + fn emit_char(&self, _v: char) { + fail ~"Unimplemented: serializing a char"; + } + + fn emit_borrowed_str(&self, v: &str) { + self.wr_tagged_str(EsStr as uint, v) + } + + fn emit_owned_str(&self, v: &str) { + self.emit_borrowed_str(v) + } + + fn emit_managed_str(&self, v: &str) { + self.emit_borrowed_str(v) + } + + fn emit_borrowed(&self, f: fn()) { f() } + fn emit_owned(&self, f: fn()) { f() } + fn emit_managed(&self, f: fn()) { f() } fn emit_enum(&self, name: &str, f: fn()) { self._emit_label(name); @@ -397,25 +415,33 @@ impl Serializer: serialization2::Serializer { } fn emit_enum_variant_arg(&self, _idx: uint, f: fn()) { f() } - fn emit_vec(&self, len: uint, f: fn()) { + fn emit_borrowed_vec(&self, len: uint, f: fn()) { do self.wr_tag(EsVec as uint) { self._emit_tagged_uint(EsVecLen, len); f() } } + fn emit_owned_vec(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f) + } + + fn emit_managed_vec(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f) + } + fn emit_vec_elt(&self, _idx: uint, f: fn()) { self.wr_tag(EsVecElt as uint, f) } - fn emit_box(&self, f: fn()) { f() } - fn emit_uniq(&self, f: fn()) { f() } fn emit_rec(&self, f: fn()) { f() } - fn emit_rec_field(&self, f_name: &str, _f_idx: uint, f: fn()) { - self._emit_label(f_name); + fn emit_struct(&self, _name: &str, f: fn()) { f() } + fn emit_field(&self, name: &str, _idx: uint, f: fn()) { + self._emit_label(name); f() } - fn emit_tup(&self, _sz: uint, f: fn()) { f() } + + fn emit_tup(&self, _len: uint, f: fn()) { f() } fn emit_tup_elt(&self, _idx: uint, f: fn()) { f() } } @@ -525,9 +551,22 @@ impl Deserializer: serialization2::Deserializer { fn read_f32(&self) -> f32 { fail ~"read_f32()"; } fn read_float(&self) -> float { fail ~"read_float()"; } - fn read_str(&self) -> ~str { doc_as_str(self.next_doc(EsStr)) } + fn read_char(&self) -> char { fail ~"read_char()"; } + + fn read_owned_str(&self) -> ~str { doc_as_str(self.next_doc(EsStr)) } + fn read_managed_str(&self) -> @str { fail ~"read_managed_str()"; } // Compound types: + fn read_owned(&self, f: fn() -> T) -> T { + debug!("read_owned()"); + f() + } + + fn read_managed(&self, f: fn() -> T) -> T { + debug!("read_managed()"); + f() + } + fn read_enum(&self, name: &str, f: fn() -> T) -> T { debug!("read_enum(%s)", name); self._check_label(name); @@ -548,8 +587,17 @@ impl Deserializer: serialization2::Deserializer { f() } - fn read_vec(&self, f: fn(uint) -> T) -> T { - debug!("read_vec()"); + fn read_owned_vec(&self, f: fn(uint) -> T) -> T { + debug!("read_owned_vec()"); + do self.push_doc(self.next_doc(EsVec)) { + let len = self._next_uint(EsVecLen); + debug!(" len=%u", len); + f(len) + } + } + + fn read_managed_vec(&self, f: fn(uint) -> T) -> T { + debug!("read_managed_vec()"); do self.push_doc(self.next_doc(EsVec)) { let len = self._next_uint(EsVecLen); debug!(" len=%u", len); @@ -562,30 +610,24 @@ impl Deserializer: serialization2::Deserializer { self.push_doc(self.next_doc(EsVecElt), f) } - fn read_box(&self, f: fn() -> T) -> T { - debug!("read_box()"); + fn read_rec(&self, f: fn() -> T) -> T { + debug!("read_rec()"); f() } - fn read_uniq(&self, f: fn() -> T) -> T { - debug!("read_uniq()"); + fn read_struct(&self, name: &str, f: fn() -> T) -> T { + debug!("read_struct(name=%s)", name); f() } - fn read_rec(&self, f: fn() -> T) -> T { - debug!("read_rec()"); - f() - } - - fn read_rec_field(&self, f_name: &str, f_idx: uint, - f: fn() -> T) -> T { - debug!("read_rec_field(%s, idx=%u)", f_name, f_idx); - self._check_label(f_name); + fn read_field(&self, name: &str, idx: uint, f: fn() -> T) -> T { + debug!("read_field(name=%s, idx=%u)", name, idx); + self._check_label(name); f() } - fn read_tup(&self, sz: uint, f: fn() -> T) -> T { - debug!("read_tup(sz=%u)", sz); + fn read_tup(&self, len: uint, f: fn() -> T) -> T { + debug!("read_tup(len=%u)", len); f() } @@ -595,7 +637,6 @@ impl Deserializer: serialization2::Deserializer { } } - // ___________________________________________________________________________ // Testing diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 09fb5441375..d3713bdb29d 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -92,10 +92,15 @@ pub impl Serializer: serialization2::Serializer { self.wr.write_str(float::to_str(v, 6u)); } - fn emit_str(&self, v: &str) { - let s = escape_str(v); - self.wr.write_str(s); - } + fn emit_char(&self, v: char) { self.emit_borrowed_str(str::from_char(v)) } + + fn emit_borrowed_str(&self, v: &str) { self.wr.write_str(escape_str(v)) } + fn emit_owned_str(&self, v: &str) { self.emit_borrowed_str(v) } + fn emit_managed_str(&self, v: &str) { self.emit_borrowed_str(v) } + + fn emit_borrowed(&self, f: fn()) { f() } + fn emit_owned(&self, f: fn()) { f() } + fn emit_managed(&self, f: fn()) { f() } fn emit_enum(&self, name: &str, f: fn()) { if name != "option" { fail ~"only supports option enum" } @@ -112,32 +117,41 @@ pub impl Serializer: serialization2::Serializer { f() } - fn emit_vec(&self, _len: uint, f: fn()) { + fn emit_borrowed_vec(&self, _len: uint, f: fn()) { self.wr.write_char('['); f(); self.wr.write_char(']'); } - + fn emit_owned_vec(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f) + } + fn emit_managed_vec(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f) + } fn emit_vec_elt(&self, idx: uint, f: fn()) { if idx != 0 { self.wr.write_char(','); } f() } - fn emit_box(&self, f: fn()) { f() } - fn emit_uniq(&self, f: fn()) { f() } fn emit_rec(&self, f: fn()) { self.wr.write_char('{'); f(); self.wr.write_char('}'); } - fn emit_rec_field(&self, name: &str, idx: uint, f: fn()) { + fn emit_struct(&self, _name: &str, f: fn()) { + self.wr.write_char('{'); + f(); + self.wr.write_char('}'); + } + fn emit_field(&self, name: &str, idx: uint, f: fn()) { if idx != 0 { self.wr.write_char(','); } self.wr.write_str(escape_str(name)); self.wr.write_char(':'); f(); } - fn emit_tup(&self, sz: uint, f: fn()) { - self.emit_vec(sz, f); + + fn emit_tup(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f); } fn emit_tup_elt(&self, idx: uint, f: fn()) { self.emit_vec_elt(idx, f) @@ -182,7 +196,15 @@ pub impl PrettySerializer: serialization2::Serializer { self.wr.write_str(float::to_str(v, 6u)); } - fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)); } + fn emit_char(&self, v: char) { self.emit_borrowed_str(str::from_char(v)) } + + fn emit_borrowed_str(&self, v: &str) { self.wr.write_str(escape_str(v)); } + fn emit_owned_str(&self, v: &str) { self.emit_borrowed_str(v) } + fn emit_managed_str(&self, v: &str) { self.emit_borrowed_str(v) } + + fn emit_borrowed(&self, f: fn()) { f() } + fn emit_owned(&self, f: fn()) { f() } + fn emit_managed(&self, f: fn()) { f() } fn emit_enum(&self, name: &str, f: fn()) { if name != "option" { fail ~"only supports option enum" } @@ -199,14 +221,19 @@ pub impl PrettySerializer: serialization2::Serializer { f() } - fn emit_vec(&self, _len: uint, f: fn()) { + fn emit_borrowed_vec(&self, _len: uint, f: fn()) { self.wr.write_char('['); self.indent += 2; f(); self.indent -= 2; self.wr.write_char(']'); } - + fn emit_owned_vec(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f) + } + fn emit_managed_vec(&self, len: uint, f: fn()) { + self.emit_borrowed_vec(len, f) + } fn emit_vec_elt(&self, idx: uint, f: fn()) { if idx == 0 { self.wr.write_char('\n'); @@ -217,8 +244,6 @@ pub impl PrettySerializer: serialization2::Serializer { f() } - fn emit_box(&self, f: fn()) { f() } - fn emit_uniq(&self, f: fn()) { f() } fn emit_rec(&self, f: fn()) { self.wr.write_char('{'); self.indent += 2; @@ -226,7 +251,10 @@ pub impl PrettySerializer: serialization2::Serializer { self.indent -= 2; self.wr.write_char('}'); } - fn emit_rec_field(&self, name: &str, idx: uint, f: fn()) { + fn emit_struct(&self, _name: &str, f: fn()) { + self.emit_rec(f) + } + fn emit_field(&self, name: &str, idx: uint, f: fn()) { if idx == 0 { self.wr.write_char('\n'); } else { @@ -238,43 +266,39 @@ pub impl PrettySerializer: serialization2::Serializer { f(); } fn emit_tup(&self, sz: uint, f: fn()) { - self.emit_vec(sz, f); + self.emit_borrowed_vec(sz, f); } fn emit_tup_elt(&self, idx: uint, f: fn()) { self.emit_vec_elt(idx, f) } } -pub fn to_serializer(ser: &S, json: &Json) { - match *json { - Number(f) => ser.emit_float(f), - String(ref s) => ser.emit_str(*s), - Boolean(b) => ser.emit_bool(b), - List(v) => { - do ser.emit_vec(v.len()) || { - for v.eachi |i, elt| { - ser.emit_vec_elt(i, || to_serializer(ser, elt)) - } - } - } - Object(ref o) => { - do ser.emit_rec || { - let mut idx = 0; - for o.each |key, value| { - do ser.emit_rec_field(*key, idx) { - to_serializer(ser, value); +pub impl Json: serialization2::Serializable { + fn serialize(&self, s: &S) { + match *self { + Number(v) => v.serialize(s), + String(ref v) => v.serialize(s), + Boolean(v) => v.serialize(s), + List(v) => v.serialize(s), + Object(ref v) => { + do s.emit_rec || { + let mut idx = 0; + for v.each |key, value| { + do s.emit_field(*key, idx) { + value.serialize(s); + } + idx += 1; } - idx += 1; } - } + }, + Null => s.emit_nil(), } - Null => ser.emit_nil(), } } /// Serializes a json value into a io::writer pub fn to_writer(wr: io::Writer, json: &Json) { - to_serializer(&Serializer(wr), json) + json.serialize(&Serializer(wr)) } /// Serializes a json value into a string @@ -284,7 +308,7 @@ pub fn to_str(json: &Json) -> ~str { /// Serializes a json value into a io::writer pub fn to_pretty_writer(wr: io::Writer, json: &Json) { - to_serializer(&PrettySerializer(wr), json) + json.serialize(&PrettySerializer(wr)) } /// Serializes a json value into a string @@ -736,14 +760,35 @@ pub impl Deserializer: serialization2::Deserializer { } } - fn read_str(&self) -> ~str { - debug!("read_str"); + fn read_char(&self) -> char { + let v = str::chars(self.read_owned_str()); + if v.len() != 1 { fail ~"string must have one character" } + v[0] + } + + fn read_owned_str(&self) -> ~str { + debug!("read_owned_str"); match *self.pop() { String(ref s) => copy *s, _ => fail ~"not a string" } } + fn read_managed_str(&self) -> @str { + // FIXME(#3604): There's no way to convert from a ~str to a @str. + fail ~"read_managed_str()"; + } + + fn read_owned(&self, f: fn() -> T) -> T { + debug!("read_owned()"); + f() + } + + fn read_managed(&self, f: fn() -> T) -> T { + debug!("read_managed()"); + f() + } + fn read_enum(&self, name: &str, f: fn() -> T) -> T { debug!("read_enum(%s)", name); if name != ~"option" { fail ~"only supports the option enum" } @@ -765,8 +810,19 @@ pub impl Deserializer: serialization2::Deserializer { f() } - fn read_vec(&self, f: fn(uint) -> T) -> T { - debug!("read_vec()"); + fn read_owned_vec(&self, f: fn(uint) -> T) -> T { + debug!("read_owned_vec()"); + let len = match *self.peek() { + List(list) => list.len(), + _ => fail ~"not a list", + }; + let res = f(len); + self.pop(); + res + } + + fn read_managed_vec(&self, f: fn(uint) -> T) -> T { + debug!("read_owned_vec()"); let len = match *self.peek() { List(ref list) => list.len(), _ => fail ~"not a list", @@ -790,16 +846,6 @@ pub impl Deserializer: serialization2::Deserializer { } } - fn read_box(&self, f: fn() -> T) -> T { - debug!("read_box()"); - f() - } - - fn read_uniq(&self, f: fn() -> T) -> T { - debug!("read_uniq()"); - f() - } - fn read_rec(&self, f: fn() -> T) -> T { debug!("read_rec()"); let value = f(); @@ -807,17 +853,23 @@ pub impl Deserializer: serialization2::Deserializer { value } - fn read_rec_field(&self, f_name: &str, f_idx: uint, - f: fn() -> T) -> T { - debug!("read_rec_field(%s, idx=%u)", f_name, f_idx); + fn read_struct(&self, _name: &str, f: fn() -> T) -> T { + debug!("read_struct()"); + let value = f(); + self.pop(); + value + } + + fn read_field(&self, name: &str, idx: uint, f: fn() -> T) -> T { + debug!("read_rec_field(%s, idx=%u)", name, idx); let top = self.peek(); match *top { Object(ref obj) => { // FIXME(#3148) This hint should not be necessary. let obj: &self/~Object = obj; - match obj.find_ref(&(f_name.to_unique())) { - None => fail fmt!("no such field: %s", f_name), + match obj.find_ref(&name.to_unique()) { + None => fail fmt!("no such field: %s", name), Some(json) => { self.stack.push(json); f() @@ -834,8 +886,8 @@ pub impl Deserializer: serialization2::Deserializer { } } - fn read_tup(&self, sz: uint, f: fn() -> T) -> T { - debug!("read_tup(sz=%u)", sz); + fn read_tup(&self, len: uint, f: fn() -> T) -> T { + debug!("read_tup(len=%u)", len); let value = f(); self.pop(); value diff --git a/src/libstd/prettyprint2.rs b/src/libstd/prettyprint2.rs index 68421a217ee..87af519eb12 100644 --- a/src/libstd/prettyprint2.rs +++ b/src/libstd/prettyprint2.rs @@ -12,7 +12,7 @@ pub fn Serializer(wr: io::Writer) -> Serializer { Serializer { wr: wr } } -impl Serializer: serialization2::Serializer { +pub impl Serializer: serialization2::Serializer { fn emit_nil(&self) { self.wr.write_str(~"()") } @@ -73,10 +73,37 @@ impl Serializer: serialization2::Serializer { self.wr.write_str(fmt!("%?_f32", v)); } - fn emit_str(&self, v: &str) { + fn emit_char(&self, v: char) { self.wr.write_str(fmt!("%?", v)); } + fn emit_borrowed_str(&self, v: &str) { + self.wr.write_str(fmt!("&%?", v)); + } + + fn emit_owned_str(&self, v: &str) { + self.wr.write_str(fmt!("~%?", v)); + } + + fn emit_managed_str(&self, v: &str) { + self.wr.write_str(fmt!("@%?", v)); + } + + fn emit_borrowed(&self, f: fn()) { + self.wr.write_str(~"&"); + f(); + } + + fn emit_owned(&self, f: fn()) { + self.wr.write_str(~"~"); + f(); + } + + fn emit_managed(&self, f: fn()) { + self.wr.write_str(~"@"); + f(); + } + fn emit_enum(&self, _name: &str, f: fn()) { f(); } @@ -94,24 +121,26 @@ impl Serializer: serialization2::Serializer { f(); } - fn emit_vec(&self, _len: uint, f: fn()) { - self.wr.write_str(~"["); + fn emit_borrowed_vec(&self, _len: uint, f: fn()) { + self.wr.write_str(~"&["); f(); self.wr.write_str(~"]"); } - fn emit_vec_elt(&self, idx: uint, f: fn()) { - if idx > 0u { self.wr.write_str(~", "); } + fn emit_owned_vec(&self, _len: uint, f: fn()) { + self.wr.write_str(~"~["); f(); + self.wr.write_str(~"]"); } - fn emit_box(&self, f: fn()) { - self.wr.write_str(~"@"); + fn emit_managed_vec(&self, _len: uint, f: fn()) { + self.wr.write_str(~"@["); f(); + self.wr.write_str(~"]"); } - fn emit_uniq(&self, f: fn()) { - self.wr.write_str(~"~"); + fn emit_vec_elt(&self, idx: uint, f: fn()) { + if idx > 0u { self.wr.write_str(~", "); } f(); } @@ -121,14 +150,20 @@ impl Serializer: serialization2::Serializer { self.wr.write_str(~"}"); } - fn emit_rec_field(&self, f_name: &str, f_idx: uint, f: fn()) { - if f_idx > 0u { self.wr.write_str(~", "); } - self.wr.write_str(f_name); + fn emit_struct(&self, name: &str, f: fn()) { + self.wr.write_str(fmt!("%s {", name)); + f(); + self.wr.write_str(~"}"); + } + + fn emit_field(&self, name: &str, idx: uint, f: fn()) { + if idx > 0u { self.wr.write_str(~", "); } + self.wr.write_str(name); self.wr.write_str(~": "); f(); } - fn emit_tup(&self, _sz: uint, f: fn()) { + fn emit_tup(&self, _len: uint, f: fn()) { self.wr.write_str(~"("); f(); self.wr.write_str(~")"); diff --git a/src/libstd/serialization2.rs b/src/libstd/serialization2.rs index 9cceccf42c6..5173ef163a2 100644 --- a/src/libstd/serialization2.rs +++ b/src/libstd/serialization2.rs @@ -24,19 +24,30 @@ pub trait Serializer { fn emit_float(&self, v: float); fn emit_f64(&self, v: f64); fn emit_f32(&self, v: f32); - fn emit_str(&self, v: &str); + fn emit_char(&self, v: char); + fn emit_borrowed_str(&self, v: &str); + fn emit_owned_str(&self, v: &str); + fn emit_managed_str(&self, v: &str); // Compound types: + fn emit_borrowed(&self, f: fn()); + fn emit_owned(&self, f: fn()); + fn emit_managed(&self, f: fn()); + fn emit_enum(&self, name: &str, f: fn()); fn emit_enum_variant(&self, v_name: &str, v_id: uint, sz: uint, f: fn()); fn emit_enum_variant_arg(&self, idx: uint, f: fn()); - fn emit_vec(&self, len: uint, f: fn()); + + fn emit_borrowed_vec(&self, len: uint, f: fn()); + fn emit_owned_vec(&self, len: uint, f: fn()); + fn emit_managed_vec(&self, len: uint, f: fn()); fn emit_vec_elt(&self, idx: uint, f: fn()); - fn emit_box(&self, f: fn()); - fn emit_uniq(&self, f: fn()); + fn emit_rec(&self, f: fn()); - fn emit_rec_field(&self, f_name: &str, f_idx: uint, f: fn()); - fn emit_tup(&self, sz: uint, f: fn()); + fn emit_struct(&self, name: &str, f: fn()); + fn emit_field(&self, f_name: &str, f_idx: uint, f: fn()); + + fn emit_tup(&self, len: uint, f: fn()); fn emit_tup_elt(&self, idx: uint, f: fn()); } @@ -57,29 +68,43 @@ pub trait Deserializer { fn read_f64(&self) -> f64; fn read_f32(&self) -> f32; fn read_float(&self) -> float; - fn read_str(&self) -> ~str; + fn read_char(&self) -> char; + fn read_owned_str(&self) -> ~str; + fn read_managed_str(&self) -> @str; // Compound types: fn read_enum(&self, name: &str, f: fn() -> T) -> T; fn read_enum_variant(&self, f: fn(uint) -> T) -> T; fn read_enum_variant_arg(&self, idx: uint, f: fn() -> T) -> T; - fn read_vec(&self, f: fn(uint) -> T) -> T; + + fn read_owned(&self, f: fn() -> T) -> T; + fn read_managed(&self, f: fn() -> T) -> T; + + fn read_owned_vec(&self, f: fn(uint) -> T) -> T; + fn read_managed_vec(&self, f: fn(uint) -> T) -> T; fn read_vec_elt(&self, idx: uint, f: fn() -> T) -> T; - fn read_box(&self, f: fn() -> T) -> T; - fn read_uniq(&self, f: fn() -> T) -> T; + fn read_rec(&self, f: fn() -> T) -> T; - fn read_rec_field(&self, f_name: &str, f_idx: uint, f: fn() -> T) -> T; + fn read_struct(&self, name: &str, f: fn() -> T) -> T; + fn read_field(&self, name: &str, idx: uint, f: fn() -> T) -> T; + fn read_tup(&self, sz: uint, f: fn() -> T) -> T; fn read_tup_elt(&self, idx: uint, f: fn() -> T) -> T; } pub trait Serializable { fn serialize(&self, s: &S); +} + +pub trait Deserializable { static fn deserialize(&self, d: &D) -> self; } pub impl uint: Serializable { fn serialize(&self, s: &S) { s.emit_uint(*self) } +} + +pub impl uint: Deserializable { static fn deserialize(&self, d: &D) -> uint { d.read_uint() } @@ -87,6 +112,9 @@ pub impl uint: Serializable { pub impl u8: Serializable { fn serialize(&self, s: &S) { s.emit_u8(*self) } +} + +pub impl u8: Deserializable { static fn deserialize(&self, d: &D) -> u8 { d.read_u8() } @@ -94,6 +122,9 @@ pub impl u8: Serializable { pub impl u16: Serializable { fn serialize(&self, s: &S) { s.emit_u16(*self) } +} + +pub impl u16: Deserializable { static fn deserialize(&self, d: &D) -> u16 { d.read_u16() } @@ -101,6 +132,9 @@ pub impl u16: Serializable { pub impl u32: Serializable { fn serialize(&self, s: &S) { s.emit_u32(*self) } +} + +pub impl u32: Deserializable { static fn deserialize(&self, d: &D) -> u32 { d.read_u32() } @@ -108,6 +142,9 @@ pub impl u32: Serializable { pub impl u64: Serializable { fn serialize(&self, s: &S) { s.emit_u64(*self) } +} + +pub impl u64: Deserializable { static fn deserialize(&self, d: &D) -> u64 { d.read_u64() } @@ -115,6 +152,9 @@ pub impl u64: Serializable { pub impl int: Serializable { fn serialize(&self, s: &S) { s.emit_int(*self) } +} + +pub impl int: Deserializable { static fn deserialize(&self, d: &D) -> int { d.read_int() } @@ -122,6 +162,9 @@ pub impl int: Serializable { pub impl i8: Serializable { fn serialize(&self, s: &S) { s.emit_i8(*self) } +} + +pub impl i8: Deserializable { static fn deserialize(&self, d: &D) -> i8 { d.read_i8() } @@ -129,6 +172,9 @@ pub impl i8: Serializable { pub impl i16: Serializable { fn serialize(&self, s: &S) { s.emit_i16(*self) } +} + +pub impl i16: Deserializable { static fn deserialize(&self, d: &D) -> i16 { d.read_i16() } @@ -136,6 +182,9 @@ pub impl i16: Serializable { pub impl i32: Serializable { fn serialize(&self, s: &S) { s.emit_i32(*self) } +} + +pub impl i32: Deserializable { static fn deserialize(&self, d: &D) -> i32 { d.read_i32() } @@ -143,20 +192,43 @@ pub impl i32: Serializable { pub impl i64: Serializable { fn serialize(&self, s: &S) { s.emit_i64(*self) } +} + +pub impl i64: Deserializable { static fn deserialize(&self, d: &D) -> i64 { d.read_i64() } } +pub impl &str: Serializable { + fn serialize(&self, s: &S) { s.emit_borrowed_str(*self) } +} + pub impl ~str: Serializable { - fn serialize(&self, s: &S) { s.emit_str(*self) } + fn serialize(&self, s: &S) { s.emit_owned_str(*self) } +} + +pub impl ~str: Deserializable { static fn deserialize(&self, d: &D) -> ~str { - d.read_str() + d.read_owned_str() + } +} + +pub impl @str: Serializable { + fn serialize(&self, s: &S) { s.emit_managed_str(*self) } +} + +pub impl @str: Deserializable { + static fn deserialize(&self, d: &D) -> @str { + d.read_managed_str() } } pub impl float: Serializable { fn serialize(&self, s: &S) { s.emit_float(*self) } +} + +pub impl float: Deserializable { static fn deserialize(&self, d: &D) -> float { d.read_float() } @@ -164,12 +236,18 @@ pub impl float: Serializable { pub impl f32: Serializable { fn serialize(&self, s: &S) { s.emit_f32(*self) } +} + +pub impl f32: Deserializable { static fn deserialize(&self, d: &D) -> f32 { d.read_f32() } } pub impl f64: Serializable { fn serialize(&self, s: &S) { s.emit_f64(*self) } +} + +pub impl f64: Deserializable { static fn deserialize(&self, d: &D) -> f64 { d.read_f64() } @@ -177,6 +255,9 @@ pub impl f64: Serializable { pub impl bool: Serializable { fn serialize(&self, s: &S) { s.emit_bool(*self) } +} + +pub impl bool: Deserializable { static fn deserialize(&self, d: &D) -> bool { d.read_bool() } @@ -184,42 +265,67 @@ pub impl bool: Serializable { pub impl (): Serializable { fn serialize(&self, s: &S) { s.emit_nil() } +} + +pub impl (): Deserializable { static fn deserialize(&self, d: &D) -> () { d.read_nil() } } -pub impl @T: Serializable { +pub impl &T: Serializable { fn serialize(&self, s: &S) { - s.emit_box(|| (*self).serialize(s)) - } - - static fn deserialize(&self, d: &D) -> @T { - d.read_box(|| @deserialize(d)) + s.emit_borrowed(|| (**self).serialize(s)) } } pub impl ~T: Serializable { fn serialize(&self, s: &S) { - s.emit_uniq(|| (*self).serialize(s)) + s.emit_owned(|| (**self).serialize(s)) } +} +pub impl ~T: Deserializable { static fn deserialize(&self, d: &D) -> ~T { - d.read_uniq(|| ~deserialize(d)) + d.read_owned(|| ~deserialize(d)) + } +} + +pub impl @T: Serializable { + fn serialize(&self, s: &S) { + s.emit_managed(|| (**self).serialize(s)) + } +} + +pub impl @T: Deserializable { + static fn deserialize(&self, d: &D) -> @T { + d.read_managed(|| @deserialize(d)) + } +} + +pub impl &[T]: Serializable { + fn serialize(&self, s: &S) { + do s.emit_borrowed_vec(self.len()) { + for self.eachi |i, e| { + s.emit_vec_elt(i, || e.serialize(s)) + } + } } } pub impl ~[T]: Serializable { fn serialize(&self, s: &S) { - do s.emit_vec(self.len()) { + do s.emit_owned_vec(self.len()) { for self.eachi |i, e| { s.emit_vec_elt(i, || e.serialize(s)) } } } +} +pub impl ~[T]: Deserializable { static fn deserialize(&self, d: &D) -> ~[T] { - do d.read_vec |len| { + do d.read_owned_vec |len| { do vec::from_fn(len) |i| { d.read_vec_elt(i, || deserialize(d)) } @@ -227,6 +333,26 @@ pub impl ~[T]: Serializable { } } +pub impl @[T]: Serializable { + fn serialize(&self, s: &S) { + do s.emit_managed_vec(self.len()) { + for self.eachi |i, e| { + s.emit_vec_elt(i, || e.serialize(s)) + } + } + } +} + +pub impl @[T]: Deserializable { + static fn deserialize(&self, d: &D) -> @[T] { + do d.read_managed_vec |len| { + do at_vec::from_fn(len) |i| { + d.read_vec_elt(i, || deserialize(d)) + } + } + } +} + pub impl Option: Serializable { fn serialize(&self, s: &S) { do s.emit_enum(~"option") { @@ -240,7 +366,9 @@ pub impl Option: Serializable { } } } +} +pub impl Option: Deserializable { static fn deserialize(&self, d: &D) -> Option { do d.read_enum(~"option") { do d.read_enum_variant |i| { @@ -268,7 +396,12 @@ pub impl< } } } +} +pub impl< + T0: Deserializable, + T1: Deserializable +> (T0, T1): Deserializable { static fn deserialize(&self, d: &D) -> (T0, T1) { do d.read_tup(2) { ( @@ -295,7 +428,13 @@ pub impl< } } } +} +pub impl< + T0: Deserializable, + T1: Deserializable, + T2: Deserializable +> (T0, T1, T2): Deserializable { static fn deserialize(&self, d: &D) -> (T0, T1, T2) { do d.read_tup(3) { ( @@ -325,7 +464,14 @@ pub impl< } } } +} +pub impl< + T0: Deserializable, + T1: Deserializable, + T2: Deserializable, + T3: Deserializable +> (T0, T1, T2, T3): Deserializable { static fn deserialize(&self, d: &D) -> (T0, T1, T2, T3) { do d.read_tup(4) { ( @@ -358,7 +504,15 @@ pub impl< } } } +} +pub impl< + T0: Deserializable, + T1: Deserializable, + T2: Deserializable, + T3: Deserializable, + T4: Deserializable +> (T0, T1, T2, T3, T4): Deserializable { static fn deserialize(&self, d: &D) -> (T0, T1, T2, T3, T4) { do d.read_tup(5) { @@ -379,12 +533,12 @@ pub impl< // In some cases, these should eventually be coded as traits. pub trait SerializerHelpers { - fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)); + fn emit_from_vec(&self, v: &[T], f: fn(&T)); } pub impl S: SerializerHelpers { - fn emit_from_vec(&self, v: ~[T], f: fn(v: &T)) { - do self.emit_vec(v.len()) { + fn emit_from_vec(&self, v: &[T], f: fn(&T)) { + do self.emit_owned_vec(v.len()) { for v.eachi |i, e| { do self.emit_vec_elt(i) { f(e) @@ -400,7 +554,7 @@ pub trait DeserializerHelpers { pub impl D: DeserializerHelpers { fn read_to_vec(&self, f: fn() -> T) -> ~[T] { - do self.read_vec |len| { + do self.read_owned_vec |len| { do vec::from_fn(len) |i| { self.read_vec_elt(i, || f()) } diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index 099ba67713f..d4a1a448936 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -9,14 +9,16 @@ For example, a type like: type node_id = uint; -would generate two functions like: +would generate two implementations like: impl node_id: Serializable { - fn serialize(s: S) { + fn serialize(s: &S) { s.emit_uint(self) } + } - static fn deserialize(d: D) -> node_id { + impl node_id: Deserializable { + static fn deserialize(d: &D) -> node_id { d.read_uint() } } @@ -29,18 +31,20 @@ references other non-built-in types. A type definition like: would yield functions like: impl spanned: Serializable { - fn serialize(s: S) { + fn serialize(s: &S) { do s.emit_rec { - s.emit_rec_field("node", 0, self.node.serialize(s)); - s.emit_rec_field("span", 1, self.span.serialize(s)); + s.emit_field("node", 0, self.node.serialize(s)); + s.emit_field("span", 1, self.span.serialize(s)); } } + } - static fn deserialize(d: D) -> spanned { + impl spanned: Deserializable { + static fn deserialize(d: &D) -> spanned { do d.read_rec { { - node: d.read_rec_field(~"node", 0, || deserialize(d)), - span: d.read_rec_field(~"span", 1, || deserialize(d)), + node: d.read_field(~"node", 0, || deserialize(d)), + span: d.read_field(~"span", 1, || deserialize(d)), } } } @@ -87,22 +91,22 @@ fn expand(cx: ext_ctxt, do vec::flat_map(in_items) |item| { match item.node { ast::item_ty(@{node: ast::ty_rec(fields), _}, tps) => { - ~[ - filter_attrs(*item), - mk_rec_impl(cx, item.span, item.ident, fields, tps), - ] + vec::append( + ~[filter_attrs(*item)], + mk_rec_impl(cx, item.span, item.ident, fields, tps) + ) }, ast::item_class(@{ fields, _}, tps) => { - ~[ - filter_attrs(*item), - mk_struct_impl(cx, item.span, item.ident, fields, tps), - ] + vec::append( + ~[filter_attrs(*item)], + mk_struct_impl(cx, item.span, item.ident, fields, tps) + ) }, ast::item_enum(enum_def, tps) => { - ~[ - filter_attrs(*item), - mk_enum_impl(cx, item.span, item.ident, enum_def, tps), - ] + vec::append( + ~[filter_attrs(*item)], + mk_enum_impl(cx, item.span, item.ident, enum_def, tps) + ) }, _ => { cx.span_err(span, ~"#[auto_serialize2] can only be applied \ @@ -152,22 +156,11 @@ fn mk_impl( cx: ext_ctxt, span: span, ident: ast::ident, + path: @ast::path, tps: ~[ast::ty_param], - ser_body: @ast::expr, - deser_body: @ast::expr + f: fn(@ast::ty) -> @ast::method ) -> @ast::item { - // Make a path to the std::serialization2::Serializable trait. - let path = cx.path( - span, - ~[ - cx.ident_of(~"std"), - cx.ident_of(~"serialization2"), - cx.ident_of(~"Serializable"), - ] - ); - - // All the type parameters need to bound to - // std::serialization::Serializable. + // All the type parameters need to bound to the trait. let trait_tps = do tps.map |tp| { let t_bound = ast::bound_trait(@{ id: cx.next_id(), @@ -194,23 +187,72 @@ fn mk_impl( tps.map(|tp| cx.ty_path(span, ~[tp.ident], ~[])) ); - let methods = ~[ - mk_ser_method(cx, span, cx.expr_blk(ser_body)), - mk_deser_method(cx, span, ty, cx.expr_blk(deser_body)), - ]; - @{ // This is a new-style impl declaration. // XXX: clownshoes ident: ast::token::special_idents::clownshoes_extensions, attrs: ~[], id: cx.next_id(), - node: ast::item_impl(trait_tps, opt_trait, ty, methods), + node: ast::item_impl(trait_tps, opt_trait, ty, ~[f(ty)]), vis: ast::public, span: span, } } +fn mk_ser_impl( + cx: ext_ctxt, + span: span, + ident: ast::ident, + tps: ~[ast::ty_param], + body: @ast::expr +) -> @ast::item { + // Make a path to the std::serialization2::Serializable trait. + let path = cx.path( + span, + ~[ + cx.ident_of(~"std"), + cx.ident_of(~"serialization2"), + cx.ident_of(~"Serializable"), + ] + ); + + mk_impl( + cx, + span, + ident, + path, + tps, + |_ty| mk_ser_method(cx, span, cx.expr_blk(body)) + ) +} + +fn mk_deser_impl( + cx: ext_ctxt, + span: span, + ident: ast::ident, + tps: ~[ast::ty_param], + body: @ast::expr +) -> @ast::item { + // Make a path to the std::serialization2::Deserializable trait. + let path = cx.path( + span, + ~[ + cx.ident_of(~"std"), + cx.ident_of(~"serialization2"), + cx.ident_of(~"Deserializable"), + ] + ); + + mk_impl( + cx, + span, + ident, + path, + tps, + |ty| mk_deser_method(cx, span, ty, cx.expr_blk(body)) + ) +} + fn mk_ser_method( cx: ext_ctxt, span: span, @@ -352,7 +394,7 @@ fn mk_rec_impl( ident: ast::ident, fields: ~[ast::ty_field], tps: ~[ast::ty_param] -) -> @ast::item { +) -> ~[@ast::item] { // Records and structs don't have the same fields types, but they share // enough that if we extract the right subfields out we can share the // serialization generator code. @@ -365,11 +407,26 @@ fn mk_rec_impl( }; let ser_body = mk_ser_fields(cx, span, fields); + + // ast for `__s.emit_rec($(ser_body))` + let ser_body = cx.expr_call( + span, + cx.expr_field( + span, + cx.expr_var(span, ~"__s"), + cx.ident_of(~"emit_rec") + ), + ~[ser_body] + ); + let deser_body = do mk_deser_fields(cx, span, fields) |fields| { cx.expr(span, ast::expr_rec(fields, None)) }; - mk_impl(cx, span, ident, tps, ser_body, deser_body) + ~[ + mk_ser_impl(cx, span, ident, tps, ser_body), + mk_deser_impl(cx, span, ident, tps, deser_body), + ] } fn mk_struct_impl( @@ -378,7 +435,7 @@ fn mk_struct_impl( ident: ast::ident, fields: ~[@ast::struct_field], tps: ~[ast::ty_param] -) -> @ast::item { +) -> ~[@ast::item] { // Records and structs don't have the same fields types, but they share // enough that if we extract the right subfields out we can share the // serialization generator code. @@ -400,11 +457,26 @@ fn mk_struct_impl( }; let ser_body = mk_ser_fields(cx, span, fields); + + // ast for `__s.emit_struct($(name), $(ser_body))` + let ser_body = cx.expr_call( + span, + cx.expr_field( + span, + cx.expr_var(span, ~"__s"), + cx.ident_of(~"emit_struct") + ), + ~[cx.lit_str(span, @cx.str_of(ident)), ser_body] + ); + let deser_body = do mk_deser_fields(cx, span, fields) |fields| { cx.expr(span, ast::expr_struct(cx.path(span, ~[ident]), fields, None)) }; - mk_impl(cx, span, ident, tps, ser_body, deser_body) + ~[ + mk_ser_impl(cx, span, ident, tps, ser_body), + mk_deser_impl(cx, span, ident, tps, deser_body), + ] } fn mk_ser_fields( @@ -430,14 +502,14 @@ fn mk_ser_fields( ) ); - // ast for `__s.emit_rec_field($(name), $(idx), $(expr_lambda))` + // ast for `__s.emit_field($(name), $(idx), $(expr_lambda))` cx.stmt( cx.expr_call( span, cx.expr_field( span, cx.expr_var(span, ~"__s"), - cx.ident_of(~"emit_rec_field") + cx.ident_of(~"emit_field") ), ~[ cx.lit_str(span, @cx.str_of(field.ident)), @@ -448,16 +520,8 @@ fn mk_ser_fields( ) }; - // ast for `__s.emit_rec(|| $(stmts))` - cx.expr_call( - span, - cx.expr_field( - span, - cx.expr_var(span, ~"__s"), - cx.ident_of(~"emit_rec") - ), - ~[cx.lambda_stmts(span, stmts)] - ) + // ast for `|| $(stmts)` + cx.lambda_stmts(span, stmts) } fn mk_deser_fields( @@ -482,13 +546,13 @@ fn mk_deser_fields( ) ); - // ast for `__d.read_rec_field($(name), $(idx), $(expr_lambda))` + // ast for `__d.read_field($(name), $(idx), $(expr_lambda))` let expr: @ast::expr = cx.expr_call( span, cx.expr_field( span, cx.expr_var(span, ~"__d"), - cx.ident_of(~"read_rec_field") + cx.ident_of(~"read_field") ), ~[ cx.lit_str(span, @cx.str_of(field.ident)), @@ -521,7 +585,7 @@ fn mk_enum_impl( ident: ast::ident, enum_def: ast::enum_def, tps: ~[ast::ty_param] -) -> @ast::item { +) -> ~[@ast::item] { let ser_body = mk_enum_ser_body( cx, span, @@ -536,7 +600,10 @@ fn mk_enum_impl( enum_def.variants ); - mk_impl(cx, span, ident, tps, ser_body, deser_body) + ~[ + mk_ser_impl(cx, span, ident, tps, ser_body), + mk_deser_impl(cx, span, ident, tps, deser_body), + ] } fn ser_variant( diff --git a/src/test/run-pass/auto_serialize2-box.rs b/src/test/run-pass/auto_serialize2-box.rs deleted file mode 100644 index 286b0eba5a1..00000000000 --- a/src/test/run-pass/auto_serialize2-box.rs +++ /dev/null @@ -1,71 +0,0 @@ -extern mod std; - -// These tests used to be separate files, but I wanted to refactor all -// the common code. - -use cmp::Eq; -use std::ebml2; -use io::Writer; -use std::serialization2::{Serializer, Serializable, deserialize}; -use std::prettyprint2; - -fn test_ser_and_deser( - a1: A, - expected: ~str -) { - // check the pretty printer: - let s = do io::with_str_writer |w| { - a1.serialize(&prettyprint2::Serializer(w)) - }; - debug!("s == %?", s); - assert s == expected; - - // check the EBML serializer: - let bytes = do io::with_bytes_writer |wr| { - let ebml_w = &ebml2::Serializer(wr); - a1.serialize(ebml_w) - }; - let d = ebml2::Doc(@bytes); - let a2: A = deserialize(&ebml2::Deserializer(d)); - assert a1 == a2; -} - -#[auto_serialize2] -enum Expr { - Val(uint), - Plus(@Expr, @Expr), - Minus(@Expr, @Expr) -} - -impl Expr : cmp::Eq { - pure fn eq(other: &Expr) -> bool { - match self { - Val(e0a) => { - match *other { - Val(e0b) => e0a == e0b, - _ => false - } - } - Plus(e0a, e1a) => { - match *other { - Plus(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - Minus(e0a, e1a) => { - match *other { - Minus(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - } - } - pure fn ne(other: &Expr) -> bool { !self.eq(other) } -} - -fn main() { - test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), - @Plus(@Val(22u), @Val(5u))), - ~"Plus(@Minus(@Val(3u), @Val(10u)), \ - @Plus(@Val(22u), @Val(5u)))"); -} diff --git a/src/test/run-pass/auto_serialize2.rs b/src/test/run-pass/auto_serialize2.rs index ac526a8f0b6..8328c4a5126 100644 --- a/src/test/run-pass/auto_serialize2.rs +++ b/src/test/run-pass/auto_serialize2.rs @@ -6,14 +6,13 @@ extern mod std; use cmp::Eq; use std::ebml2; use io::Writer; -use std::serialization2::{Serializer, Serializable, deserialize}; +use std::serialization2::{Serializable, Deserializable, deserialize}; use std::prettyprint2; -fn test_ser_and_deser( +fn test_ser_and_deser( a1: A, expected: ~str ) { - // check the pretty printer: let s = do io::with_str_writer |w| { a1.serialize(&prettyprint2::Serializer(w)) @@ -31,6 +30,39 @@ fn test_ser_and_deser( assert a1 == a2; } +#[auto_serialize2] +enum Expr { + Val(uint), + Plus(@Expr, @Expr), + Minus(@Expr, @Expr) +} + +impl Expr : cmp::Eq { + pure fn eq(other: &Expr) -> bool { + match self { + Val(e0a) => { + match *other { + Val(e0b) => e0a == e0b, + _ => false + } + } + Plus(e0a, e1a) => { + match *other { + Plus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + Minus(e0a, e1a) => { + match *other { + Minus(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + } + } + pure fn ne(other: &Expr) -> bool { !self.eq(other) } +} + impl AnEnum : cmp::Eq { pure fn eq(other: &AnEnum) -> bool { self.v == other.v @@ -101,15 +133,20 @@ enum Quark { enum CLike { A, B, C } fn main() { + test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), + @Plus(@Val(22u), @Val(5u))), + ~"Plus(@Minus(@Val(3u), @Val(10u)), \ + @Plus(@Val(22u), @Val(5u)))"); + test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, ~"{lo: 0u, hi: 5u, node: 22u}"); test_ser_and_deser(AnEnum({v: ~[1u, 2u, 3u]}), - ~"AnEnum({v: [1u, 2u, 3u]})"); + ~"AnEnum({v: ~[1u, 2u, 3u]})"); test_ser_and_deser({x: 3u, y: 5u}, ~"{x: 3u, y: 5u}"); - test_ser_and_deser(~[1u, 2u, 3u], ~"[1u, 2u, 3u]"); + test_ser_and_deser(@[1u, 2u, 3u], ~"@[1u, 2u, 3u]"); test_ser_and_deser(Top(22u), ~"Top(22u)"); test_ser_and_deser(Bottom(222u), ~"Bottom(222u)"); -- cgit 1.4.1-3-g733a5 From 372c7de20104bd3f968cda6429dfad2c1d559a35 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 1 Oct 2012 11:35:27 -0700 Subject: Add struct to auto_serialize2 test --- src/test/run-pass/auto_serialize2.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/test') diff --git a/src/test/run-pass/auto_serialize2.rs b/src/test/run-pass/auto_serialize2.rs index 8328c4a5126..f3f7e80e8a2 100644 --- a/src/test/run-pass/auto_serialize2.rs +++ b/src/test/run-pass/auto_serialize2.rs @@ -10,8 +10,8 @@ use std::serialization2::{Serializable, Deserializable, deserialize}; use std::prettyprint2; fn test_ser_and_deser( - a1: A, - expected: ~str + a1: &A, + +expected: ~str ) { // check the pretty printer: let s = do io::with_str_writer |w| { @@ -27,7 +27,7 @@ fn test_ser_and_deser( }; let d = ebml2::Doc(@bytes); let a2: A = deserialize(&ebml2::Deserializer(d)); - assert a1 == a2; + assert *a1 == a2; } #[auto_serialize2] @@ -121,7 +121,7 @@ type SomeRec = {v: ~[uint]}; enum AnEnum = SomeRec; #[auto_serialize2] -type Point = {x: uint, y: uint}; +struct Point {x: uint, y: uint} #[auto_serialize2] enum Quark { @@ -133,24 +133,24 @@ enum Quark { enum CLike { A, B, C } fn main() { - test_ser_and_deser(Plus(@Minus(@Val(3u), @Val(10u)), - @Plus(@Val(22u), @Val(5u))), + test_ser_and_deser(&Plus(@Minus(@Val(3u), @Val(10u)), + @Plus(@Val(22u), @Val(5u))), ~"Plus(@Minus(@Val(3u), @Val(10u)), \ @Plus(@Val(22u), @Val(5u)))"); - test_ser_and_deser({lo: 0u, hi: 5u, node: 22u}, + test_ser_and_deser(&{lo: 0u, hi: 5u, node: 22u}, ~"{lo: 0u, hi: 5u, node: 22u}"); - test_ser_and_deser(AnEnum({v: ~[1u, 2u, 3u]}), + test_ser_and_deser(&AnEnum({v: ~[1u, 2u, 3u]}), ~"AnEnum({v: ~[1u, 2u, 3u]})"); - test_ser_and_deser({x: 3u, y: 5u}, ~"{x: 3u, y: 5u}"); + test_ser_and_deser(&Point {x: 3u, y: 5u}, ~"Point {x: 3u, y: 5u}"); - test_ser_and_deser(@[1u, 2u, 3u], ~"@[1u, 2u, 3u]"); + test_ser_and_deser(&@[1u, 2u, 3u], ~"@[1u, 2u, 3u]"); - test_ser_and_deser(Top(22u), ~"Top(22u)"); - test_ser_and_deser(Bottom(222u), ~"Bottom(222u)"); + test_ser_and_deser(&Top(22u), ~"Top(22u)"); + test_ser_and_deser(&Bottom(222u), ~"Bottom(222u)"); - test_ser_and_deser(A, ~"A"); - test_ser_and_deser(B, ~"B"); + test_ser_and_deser(&A, ~"A"); + test_ser_and_deser(&B, ~"B"); } -- cgit 1.4.1-3-g733a5 From 2569adc5ea0b950c6e41a1c72d9eb7efdba49f05 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 1 Oct 2012 08:12:39 -0700 Subject: Split auto_serialize2 into two macros --- src/libsyntax/ext/auto_serialize2.rs | 199 ++++++++++++++++++++++------------- src/libsyntax/ext/base.rs | 8 +- src/test/run-pass/auto_serialize2.rs | 7 ++ 3 files changed, 137 insertions(+), 77 deletions(-) (limited to 'src/test') diff --git a/src/libsyntax/ext/auto_serialize2.rs b/src/libsyntax/ext/auto_serialize2.rs index 426873ce347..99f837a4c84 100644 --- a/src/libsyntax/ext/auto_serialize2.rs +++ b/src/libsyntax/ext/auto_serialize2.rs @@ -1,13 +1,14 @@ /* -The compiler code necessary to implement the #[auto_serialize2] -extension. The idea here is that type-defining items may be tagged -with #[auto_serialize2], which will cause us to generate a little -companion module with the same name as the item. +The compiler code necessary to implement the #[auto_serialize2] and +#[auto_deserialize2] extension. The idea here is that type-defining items may +be tagged with #[auto_serialize2] and #[auto_deserialize2], which will cause +us to generate a little companion module with the same name as the item. For example, a type like: #[auto_serialize2] + #[auto_deserialize2] struct Node {id: uint} would generate two implementations like: @@ -34,6 +35,7 @@ Other interesting scenarios are whe the item has type parameters or references other non-built-in types. A type definition like: #[auto_serialize2] + #[auto_deserialize2] type spanned = {node: T, span: span}; would yield functions like: @@ -75,7 +77,8 @@ use codemap::span; use std::map; use std::map::HashMap; -export expand; +export expand_auto_serialize; +export expand_auto_deserialize; // Transitional reexports so qquote can find the paths it is looking for mod syntax { @@ -83,84 +86,130 @@ mod syntax { pub use parse; } -fn expand(cx: ext_ctxt, - span: span, - _mitem: ast::meta_item, - in_items: ~[@ast::item]) -> ~[@ast::item] { - fn not_auto_serialize2(a: &ast::attribute) -> bool { - attr::get_attr_name(*a) != ~"auto_serialize2" +fn expand_auto_serialize( + cx: ext_ctxt, + span: span, + _mitem: ast::meta_item, + in_items: ~[@ast::item] +) -> ~[@ast::item] { + fn is_auto_serialize2(a: &ast::attribute) -> bool { + attr::get_attr_name(*a) == ~"auto_serialize2" } fn filter_attrs(item: @ast::item) -> @ast::item { - @{attrs: vec::filter(item.attrs, not_auto_serialize2), + @{attrs: vec::filter(item.attrs, |a| !is_auto_serialize2(a)), .. *item} } do vec::flat_map(in_items) |item| { - match item.node { - ast::item_ty(@{node: ast::ty_rec(fields), _}, tps) => { - let ser_impl = mk_rec_ser_impl( - cx, - item.span, - item.ident, - fields, - tps - ); - - let deser_impl = mk_rec_deser_impl( - cx, - item.span, - item.ident, - fields, - tps - ); - - ~[filter_attrs(*item), ser_impl, deser_impl] - }, - ast::item_class(@{ fields, _}, tps) => { - let ser_impl = mk_struct_ser_impl( - cx, - item.span, - item.ident, - fields, - tps - ); - - let deser_impl = mk_struct_deser_impl( - cx, - item.span, - item.ident, - fields, - tps - ); - - ~[filter_attrs(*item), ser_impl, deser_impl] - }, - ast::item_enum(enum_def, tps) => { - let ser_impl = mk_enum_ser_impl( - cx, - item.span, - item.ident, - enum_def, - tps - ); - - let deser_impl = mk_enum_deser_impl( - cx, - item.span, - item.ident, - enum_def, - tps - ); - - ~[filter_attrs(*item), ser_impl, deser_impl] - }, - _ => { - cx.span_err(span, ~"#[auto_serialize2] can only be applied \ - to structs, record types, and enum \ - definitions"); - ~[*item] + if item.attrs.any(is_auto_serialize2) { + match item.node { + ast::item_ty(@{node: ast::ty_rec(fields), _}, tps) => { + let ser_impl = mk_rec_ser_impl( + cx, + item.span, + item.ident, + fields, + tps + ); + + ~[filter_attrs(*item), ser_impl] + }, + ast::item_class(@{ fields, _}, tps) => { + let ser_impl = mk_struct_ser_impl( + cx, + item.span, + item.ident, + fields, + tps + ); + + ~[filter_attrs(*item), ser_impl] + }, + ast::item_enum(enum_def, tps) => { + let ser_impl = mk_enum_ser_impl( + cx, + item.span, + item.ident, + enum_def, + tps + ); + + ~[filter_attrs(*item), ser_impl] + }, + _ => { + cx.span_err(span, ~"#[auto_serialize2] can only be \ + applied to structs, record types, \ + and enum definitions"); + ~[*item] + } + } + } else { + ~[*item] + } + } +} + +fn expand_auto_deserialize( + cx: ext_ctxt, + span: span, + _mitem: ast::meta_item, + in_items: ~[@ast::item] +) -> ~[@ast::item] { + fn is_auto_deserialize2(a: &ast::attribute) -> bool { + attr::get_attr_name(*a) == ~"auto_deserialize2" + } + + fn filter_attrs(item: @ast::item) -> @ast::item { + @{attrs: vec::filter(item.attrs, |a| !is_auto_deserialize2(a)), + .. *item} + } + + do vec::flat_map(in_items) |item| { + if item.attrs.any(is_auto_deserialize2) { + match item.node { + ast::item_ty(@{node: ast::ty_rec(fields), _}, tps) => { + let deser_impl = mk_rec_deser_impl( + cx, + item.span, + item.ident, + fields, + tps + ); + + ~[filter_attrs(*item), deser_impl] + }, + ast::item_class(@{ fields, _}, tps) => { + let deser_impl = mk_struct_deser_impl( + cx, + item.span, + item.ident, + fields, + tps + ); + + ~[filter_attrs(*item), deser_impl] + }, + ast::item_enum(enum_def, tps) => { + let deser_impl = mk_enum_deser_impl( + cx, + item.span, + item.ident, + enum_def, + tps + ); + + ~[filter_attrs(*item), deser_impl] + }, + _ => { + cx.span_err(span, ~"#[auto_deserialize2] can only be \ + applied to structs, record types, \ + and enum definitions"); + ~[*item] + } } + } else { + ~[*item] } } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 6c71fd8fcbc..9a31cc1d8f6 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -82,8 +82,12 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> { syntax_expanders.insert(~"fmt", builtin(ext::fmt::expand_syntax_ext)); syntax_expanders.insert(~"auto_serialize", item_decorator(ext::auto_serialize::expand)); - syntax_expanders.insert(~"auto_serialize2", - item_decorator(ext::auto_serialize2::expand)); + syntax_expanders.insert( + ~"auto_serialize2", + item_decorator(ext::auto_serialize2::expand_auto_serialize)); + syntax_expanders.insert( + ~"auto_deserialize2", + item_decorator(ext::auto_serialize2::expand_auto_deserialize)); syntax_expanders.insert(~"env", builtin(ext::env::expand_syntax_ext)); syntax_expanders.insert(~"concat_idents", builtin(ext::concat_idents::expand_syntax_ext)); diff --git a/src/test/run-pass/auto_serialize2.rs b/src/test/run-pass/auto_serialize2.rs index f3f7e80e8a2..4503ea6c7e0 100644 --- a/src/test/run-pass/auto_serialize2.rs +++ b/src/test/run-pass/auto_serialize2.rs @@ -31,6 +31,7 @@ fn test_ser_and_deser( } #[auto_serialize2] +#[auto_deserialize2] enum Expr { Val(uint), Plus(@Expr, @Expr), @@ -105,6 +106,7 @@ impl CLike : cmp::Eq { } #[auto_serialize2] +#[auto_deserialize2] type Spanned = {lo: uint, hi: uint, node: T}; impl Spanned : cmp::Eq { @@ -115,21 +117,26 @@ impl Spanned : cmp::Eq { } #[auto_serialize2] +#[auto_deserialize2] type SomeRec = {v: ~[uint]}; #[auto_serialize2] +#[auto_deserialize2] enum AnEnum = SomeRec; #[auto_serialize2] +#[auto_deserialize2] struct Point {x: uint, y: uint} #[auto_serialize2] +#[auto_deserialize2] enum Quark { Top(T), Bottom(T) } #[auto_serialize2] +#[auto_deserialize2] enum CLike { A, B, C } fn main() { -- cgit 1.4.1-3-g733a5 From 92841793114d7e60e3227d9087dc8741e7592789 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 2 Oct 2012 12:19:04 -0700 Subject: libstd: Switch off legacy modes in both core and std. --- src/cargo/cargo.rs | 4 +- src/fuzzer/fuzzer.rs | 2 +- src/libcore/cast.rs | 2 +- src/libcore/comm.rs | 4 +- src/libcore/core.rc | 1 - src/libcore/os.rs | 4 +- src/libcore/ptr.rs | 2 +- src/libcore/rand.rs | 4 +- src/libcore/stackwalk.rs | 7 ++- src/libstd/ebml.rs | 8 +-- src/libstd/serialization.rs | 72 +++++++++++----------- src/libstd/std.rc | 1 - src/libsyntax/ast.rs | 24 ++++---- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/parse/obsolete.rs | 2 +- src/rt/rust_builtin.cpp | 10 +++ src/rt/rustrt.def.in | 2 + src/rustc/middle/borrowck.rs | 2 +- src/rustc/middle/trans/common.rs | 4 +- src/rustc/middle/trans/datum.rs | 2 +- src/rustc/middle/ty.rs | 38 ++++++------ .../middle/typeck/infer/region_var_bindings.rs | 4 +- src/test/bench/graph500-bfs.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- 24 files changed, 108 insertions(+), 97 deletions(-) (limited to 'src/test') diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 6136652c873..81c0ce9a5b7 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -144,7 +144,7 @@ fn is_uuid(id: ~str) -> bool { if vec::len(parts) == 5u { let mut correct = 0u; for vec::eachi(parts) |i, part| { - fn is_hex_digit(ch: char) -> bool { + fn is_hex_digit(+ch: char) -> bool { ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') @@ -402,7 +402,7 @@ fn need_dir(s: &Path) { } fn valid_pkg_name(s: &str) -> bool { - fn is_valid_digit(c: char) -> bool { + fn is_valid_digit(+c: char) -> bool { ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index ace96c389ef..cd312362d6a 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -221,7 +221,7 @@ fn under(n: uint, it: fn(uint)) { while i < n { it(i); i += 1u; } } -fn as_str(f: fn@(io::Writer)) -> ~str { +fn as_str(f: fn@(+x: io::Writer)) -> ~str { io::with_str_writer(f) } diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 714c85c75c3..21f5861b89e 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -3,7 +3,7 @@ #[abi = "rust-intrinsic"] extern mod rusti { fn forget(-x: T); - fn reinterpret_cast(e: T) -> U; + fn reinterpret_cast(&&e: T) -> U; } /// Casts the value at `src` to U. The two types must have the same length. diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 81b648d9840..ff9f9498a98 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -33,7 +33,7 @@ will once again be the preferred module for intertask communication. */ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +#[warn(deprecated_mode)]; #[forbid(deprecated_pattern)]; use either::Either; @@ -166,7 +166,7 @@ fn as_raw_port(ch: comm::Chan, f: fn(*rust_port) -> U) -> U { * Constructs a channel. The channel is bound to the port used to * construct it. */ -pub fn Chan(p: Port) -> Chan { +pub fn Chan(&&p: Port) -> Chan { Chan_(rustrt::get_port_id((**p).po)) } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index c781a26185a..6cada58fa02 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -36,7 +36,6 @@ Implicitly, all crates behave as if they included the following prologue: // Don't link to core. We are core. #[no_core]; -#[legacy_modes]; #[legacy_exports]; #[warn(deprecated_mode)]; diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 1b53a163ad5..1cf4fbab6c9 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -35,7 +35,7 @@ extern mod rustrt { fn rust_getcwd() -> ~str; fn rust_path_is_dir(path: *libc::c_char) -> c_int; fn rust_path_exists(path: *libc::c_char) -> c_int; - fn rust_list_files(path: ~str) -> ~[~str]; + fn rust_list_files2(&&path: ~str) -> ~[~str]; fn rust_process_wait(handle: c_int) -> c_int; fn last_os_error() -> ~str; fn rust_set_exit_status(code: libc::intptr_t); @@ -582,7 +582,7 @@ pub fn list_dir(p: &Path) -> ~[~str] { #[cfg(windows)] fn star(p: &Path) -> Path { p.push("*") } - do rustrt::rust_list_files(star(p).to_str()).filter |filename| { + do rustrt::rust_list_files2(star(p).to_str()).filter |filename| { *filename != ~"." && *filename != ~".." } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 550b0121e45..fad7eddd2d8 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -21,7 +21,7 @@ extern mod libc_ { #[abi = "rust-intrinsic"] extern mod rusti { - fn addr_of(val: T) -> *T; + fn addr_of(&&val: T) -> *T; } /// Get an unsafe pointer to a value diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 501afc0c4bc..f6b7dfa568c 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -11,7 +11,7 @@ enum rctx {} extern mod rustrt { fn rand_seed() -> ~[u8]; fn rand_new() -> *rctx; - fn rand_new_seeded(seed: ~[u8]) -> *rctx; + fn rand_new_seeded2(&&seed: ~[u8]) -> *rctx; fn rand_next(c: *rctx) -> u32; fn rand_free(c: *rctx); } @@ -276,7 +276,7 @@ pub fn Rng() -> Rng { * length. */ pub fn seeded_rng(seed: &~[u8]) -> Rng { - @RandRes(rustrt::rand_new_seeded(*seed)) as Rng + @RandRes(rustrt::rand_new_seeded2(*seed)) as Rng } type XorShiftState = { diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 4cc91b8b425..d0f8de136e2 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -1,7 +1,8 @@ #[doc(hidden)]; // FIXME #3538 // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// XXX: Can't do this because frame_address needs a deprecated mode. +//#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cast::reinterpret_cast; @@ -74,7 +75,7 @@ fn breakpoint() { rustrt::rust_dbg_breakpoint() } -fn frame_address(f: fn(*u8)) { +fn frame_address(f: fn(++x: *u8)) { rusti::frame_address(f) } @@ -86,5 +87,5 @@ extern mod rustrt { #[abi = "rust-intrinsic"] extern mod rusti { #[legacy_exports]; - fn frame_address(f: fn(*u8)); + fn frame_address(f: fn(++x: *u8)); } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index b88142e9502..7c5b7929f84 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -588,11 +588,11 @@ impl EbmlDeserializer: serialization::Deserializer { #[test] fn test_option_int() { - fn serialize_1(s: S, v: int) { + fn serialize_1(&&s: S, v: int) { s.emit_i64(v as i64); } - fn serialize_0(s: S, v: Option) { + fn serialize_0(&&s: S, v: Option) { do s.emit_enum(~"core::option::t") { match v { None => s.emit_enum_variant( @@ -606,11 +606,11 @@ fn test_option_int() { } } - fn deserialize_1(s: S) -> int { + fn deserialize_1(&&s: S) -> int { s.read_i64() as int } - fn deserialize_0(s: S) -> Option { + fn deserialize_0(&&s: S) -> Option { do s.read_enum(~"core::option::t") { do s.read_enum_variant |i| { match i { diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index 7cf7779f13d..e9067bc6404 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -81,7 +81,7 @@ trait Deserializer { // // In some cases, these should eventually be coded as traits. -fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { +fn emit_from_vec(&&s: S, &&v: ~[T], f: fn(&&x: T)) { do s.emit_vec(vec::len(v)) { for vec::eachi(v) |i,e| { do s.emit_vec_elt(i) { @@ -91,7 +91,7 @@ fn emit_from_vec(s: S, v: ~[T], f: fn(T)) { } } -fn read_to_vec(d: D, f: fn() -> T) -> ~[T] { +fn read_to_vec(&&d: D, f: fn() -> T) -> ~[T] { do d.read_vec |len| { do vec::from_fn(len) |i| { d.read_vec_elt(i, || f()) @@ -100,11 +100,11 @@ fn read_to_vec(d: D, f: fn() -> T) -> ~[T] { } trait SerializerHelpers { - fn emit_from_vec(v: ~[T], f: fn(T)); + fn emit_from_vec(&&v: ~[T], f: fn(&&x: T)); } impl S: SerializerHelpers { - fn emit_from_vec(v: ~[T], f: fn(T)) { + fn emit_from_vec(&&v: ~[T], f: fn(&&x: T)) { emit_from_vec(self, v, f) } } @@ -119,127 +119,127 @@ impl D: DeserializerHelpers { } } -fn serialize_uint(s: S, v: uint) { +fn serialize_uint(&&s: S, v: uint) { s.emit_uint(v); } -fn deserialize_uint(d: D) -> uint { +fn deserialize_uint(&&d: D) -> uint { d.read_uint() } -fn serialize_u8(s: S, v: u8) { +fn serialize_u8(&&s: S, v: u8) { s.emit_u8(v); } -fn deserialize_u8(d: D) -> u8 { +fn deserialize_u8(&&d: D) -> u8 { d.read_u8() } -fn serialize_u16(s: S, v: u16) { +fn serialize_u16(&&s: S, v: u16) { s.emit_u16(v); } -fn deserialize_u16(d: D) -> u16 { +fn deserialize_u16(&&d: D) -> u16 { d.read_u16() } -fn serialize_u32(s: S, v: u32) { +fn serialize_u32(&&s: S, v: u32) { s.emit_u32(v); } -fn deserialize_u32(d: D) -> u32 { +fn deserialize_u32(&&d: D) -> u32 { d.read_u32() } -fn serialize_u64(s: S, v: u64) { +fn serialize_u64(&&s: S, v: u64) { s.emit_u64(v); } -fn deserialize_u64(d: D) -> u64 { +fn deserialize_u64(&&d: D) -> u64 { d.read_u64() } -fn serialize_int(s: S, v: int) { +fn serialize_int(&&s: S, v: int) { s.emit_int(v); } -fn deserialize_int(d: D) -> int { +fn deserialize_int(&&d: D) -> int { d.read_int() } -fn serialize_i8(s: S, v: i8) { +fn serialize_i8(&&s: S, v: i8) { s.emit_i8(v); } -fn deserialize_i8(d: D) -> i8 { +fn deserialize_i8(&&d: D) -> i8 { d.read_i8() } -fn serialize_i16(s: S, v: i16) { +fn serialize_i16(&&s: S, v: i16) { s.emit_i16(v); } -fn deserialize_i16(d: D) -> i16 { +fn deserialize_i16(&&d: D) -> i16 { d.read_i16() } -fn serialize_i32(s: S, v: i32) { +fn serialize_i32(&&s: S, v: i32) { s.emit_i32(v); } -fn deserialize_i32(d: D) -> i32 { +fn deserialize_i32(&&d: D) -> i32 { d.read_i32() } -fn serialize_i64(s: S, v: i64) { +fn serialize_i64(&&s: S, v: i64) { s.emit_i64(v); } -fn deserialize_i64(d: D) -> i64 { +fn deserialize_i64(&&d: D) -> i64 { d.read_i64() } -fn serialize_str(s: S, v: &str) { +fn serialize_str(&&s: S, v: &str) { s.emit_str(v); } -fn deserialize_str(d: D) -> ~str { +fn deserialize_str(&&d: D) -> ~str { d.read_str() } -fn serialize_float(s: S, v: float) { +fn serialize_float(&&s: S, v: float) { s.emit_float(v); } -fn deserialize_float(d: D) -> float { +fn deserialize_float(&&d: D) -> float { d.read_float() } -fn serialize_f32(s: S, v: f32) { +fn serialize_f32(&&s: S, v: f32) { s.emit_f32(v); } -fn deserialize_f32(d: D) -> f32 { +fn deserialize_f32(&&d: D) -> f32 { d.read_f32() } -fn serialize_f64(s: S, v: f64) { +fn serialize_f64(&&s: S, v: f64) { s.emit_f64(v); } -fn deserialize_f64(d: D) -> f64 { +fn deserialize_f64(&&d: D) -> f64 { d.read_f64() } -fn serialize_bool(s: S, v: bool) { +fn serialize_bool(&&s: S, v: bool) { s.emit_bool(v); } -fn deserialize_bool(d: D) -> bool { +fn deserialize_bool(&&d: D) -> bool { d.read_bool() } -fn serialize_Option(s: S, v: Option, st: fn(T)) { +fn serialize_Option(&&s: S, &&v: Option, st: fn(&&x: T)) { do s.emit_enum(~"option") { match v { None => do s.emit_enum_variant(~"none", 0u, 0u) { @@ -254,7 +254,7 @@ fn serialize_Option(s: S, v: Option, st: fn(T)) { } } -fn deserialize_Option(d: D, st: fn() -> T) +fn deserialize_Option(&&d: D, st: fn() -> T) -> Option { do d.read_enum(~"option") { do d.read_enum_variant |i| { diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 4831ac993a2..aa26c4af29c 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -18,7 +18,6 @@ not required in or otherwise suitable for the core library. #[no_core]; -#[legacy_modes]; #[legacy_exports]; #[allow(vecs_implicitly_copyable)]; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 67841158ce1..e17b52fb27d 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -69,7 +69,7 @@ impl ident: cmp::Eq { } impl ident: to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { self.repr.iter_bytes(lsb0, f) } } @@ -328,7 +328,7 @@ enum binding_mode { } impl binding_mode : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { bind_by_value => 0u8.iter_bytes(lsb0, f), @@ -402,7 +402,7 @@ enum pat_ { enum mutability { m_mutbl, m_imm, m_const, } impl mutability : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -541,7 +541,7 @@ enum inferable { } impl inferable : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { expl(ref t) => to_bytes::iter_bytes_2(&0u8, t, lsb0, f), @@ -577,7 +577,7 @@ impl inferable : cmp::Eq { enum rmode { by_ref, by_val, by_mutbl_ref, by_move, by_copy } impl rmode : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -937,7 +937,7 @@ enum trait_method { enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, } impl int_ty : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -966,7 +966,7 @@ impl int_ty : cmp::Eq { enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, } impl uint_ty : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -993,7 +993,7 @@ impl uint_ty : cmp::Eq { enum float_ty { ty_f, ty_f32, ty_f64, } impl float_ty : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -1102,7 +1102,7 @@ impl ty : cmp::Eq { } impl ty : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f); } } @@ -1126,7 +1126,7 @@ enum purity { } impl purity : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -1146,7 +1146,7 @@ enum ret_style { } impl ret_style : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -1443,7 +1443,7 @@ enum item_ { enum class_mutability { class_mutable, class_immutable } impl class_mutability : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 2431947184d..e8099de246c 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -254,7 +254,7 @@ pure fn is_call_expr(e: @expr) -> bool { // This makes def_id hashable impl def_id : core::to_bytes::IterBytes { #[inline(always)] - pure fn iter_bytes(lsb0: bool, f: core::to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: core::to_bytes::Cb) { core::to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f); } } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 9cfa84ad9e0..782535f5c2b 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -36,7 +36,7 @@ impl ObsoleteSyntax : cmp::Eq { impl ObsoleteSyntax: to_bytes::IterBytes { #[inline(always)] - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as uint).iter_bytes(lsb0, f); } } diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 91c5760d3e9..6f985601f8b 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -180,6 +180,11 @@ rand_new_seeded(rust_vec_box* seed) { return rctx; } +extern "C" CDECL void * +rand_new_seeded2(rust_vec_box** seed) { + return rand_new_seeded(*seed); +} + extern "C" CDECL size_t rand_next(randctx *rctx) { return isaac_rand(rctx); @@ -371,6 +376,11 @@ rust_list_files(rust_str *path) { return vec; } +extern "C" CDECL rust_vec_box* +rust_list_files2(rust_str **path) { + return rust_list_files(*path); +} + extern "C" CDECL int rust_path_is_dir(char *path) { struct stat buf; diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 43f24f4dd4f..551378a3d6c 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -27,6 +27,7 @@ rust_port_select rand_free rand_new rand_new_seeded +rand_new_seeded2 rand_next rand_seed rust_get_sched_id @@ -40,6 +41,7 @@ rust_get_stdin rust_get_stdout rust_get_stderr rust_list_files +rust_list_files2 rust_log_console_on rust_log_console_off rust_port_begin_detach diff --git a/src/rustc/middle/borrowck.rs b/src/rustc/middle/borrowck.rs index 4906eb4a0a3..414890cbd7c 100644 --- a/src/rustc/middle/borrowck.rs +++ b/src/rustc/middle/borrowck.rs @@ -415,7 +415,7 @@ impl root_map_key : cmp::Eq { } impl root_map_key : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.id, &self.derefs, lsb0, f); } } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index d68bdb08221..6768f3e71a0 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -1142,7 +1142,7 @@ impl mono_id_ : cmp::Eq { } impl mono_param_id : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { mono_precise(t, mids) => to_bytes::iter_bytes_3(&0u8, &ty::type_id(t), &mids, lsb0, f), @@ -1156,7 +1156,7 @@ impl mono_param_id : to_bytes::IterBytes { } impl mono_id_ : core::to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.def, &self.params, lsb0, f); } } diff --git a/src/rustc/middle/trans/datum.rs b/src/rustc/middle/trans/datum.rs index 59e8cd72025..241fa5e53af 100644 --- a/src/rustc/middle/trans/datum.rs +++ b/src/rustc/middle/trans/datum.rs @@ -146,7 +146,7 @@ impl DatumMode: cmp::Eq { } impl DatumMode: to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as uint).iter_bytes(lsb0, f) } } diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 973db90ff66..a96388e9d77 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -248,7 +248,7 @@ impl creader_cache_key : cmp::Eq { } impl creader_cache_key : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_3(&self.cnum, &self.pos, &self.len, lsb0, f); } } @@ -263,7 +263,7 @@ impl intern_key : cmp::Eq { } impl intern_key : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.sty, &self.o_def_id, lsb0, f); } } @@ -406,7 +406,7 @@ enum closure_kind { } impl closure_kind : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (self as u8).iter_bytes(lsb0, f) } } @@ -424,7 +424,7 @@ enum fn_proto { } impl fn_proto : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { proto_bare => 0u8.iter_bytes(lsb0, f), @@ -502,7 +502,7 @@ impl param_ty : cmp::Eq { } impl param_ty : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.idx, &self.def_id, lsb0, f) } } @@ -676,7 +676,7 @@ enum InferTy { } impl InferTy : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { TyVar(ref tv) => to_bytes::iter_bytes_2(&0u8, tv, lsb0, f), IntVar(ref iv) => to_bytes::iter_bytes_2(&1u8, iv, lsb0, f) @@ -685,7 +685,7 @@ impl InferTy : to_bytes::IterBytes { } impl param_bound : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { bound_copy => 0u8.iter_bytes(lsb0, f), bound_owned => 1u8.iter_bytes(lsb0, f), @@ -749,25 +749,25 @@ impl purity: purity_to_str { } impl RegionVid : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (*self).iter_bytes(lsb0, f) } } impl TyVid : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (*self).iter_bytes(lsb0, f) } } impl IntVid : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (*self).iter_bytes(lsb0, f) } } impl FnVid : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { (*self).iter_bytes(lsb0, f) } } @@ -2505,7 +2505,7 @@ fn index_sty(cx: ctxt, sty: &sty) -> Option { } impl bound_region : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { ty::br_self => 0u8.iter_bytes(lsb0, f), @@ -2522,7 +2522,7 @@ impl bound_region : to_bytes::IterBytes { } impl region : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { re_bound(ref br) => to_bytes::iter_bytes_2(&0u8, br, lsb0, f), @@ -2542,7 +2542,7 @@ impl region : to_bytes::IterBytes { } impl vstore : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { vstore_fixed(ref u) => to_bytes::iter_bytes_2(&0u8, u, lsb0, f), @@ -2557,7 +2557,7 @@ impl vstore : to_bytes::IterBytes { } impl substs : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_3(&self.self_r, &self.self_ty, &self.tps, lsb0, f) @@ -2565,28 +2565,28 @@ impl substs : to_bytes::IterBytes { } impl mt : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.ty, &self.mutbl, lsb0, f) } } impl field : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.ident, &self.mt, lsb0, f) } } impl arg : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.mode, &self.ty, lsb0, f) } } impl sty : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { ty_nil => 0u8.iter_bytes(lsb0, f), ty_bool => 1u8.iter_bytes(lsb0, f), diff --git a/src/rustc/middle/typeck/infer/region_var_bindings.rs b/src/rustc/middle/typeck/infer/region_var_bindings.rs index c86850e19d2..8bbdab74d23 100644 --- a/src/rustc/middle/typeck/infer/region_var_bindings.rs +++ b/src/rustc/middle/typeck/infer/region_var_bindings.rs @@ -350,7 +350,7 @@ impl Constraint : cmp::Eq { } impl Constraint : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { match self { ConstrainVarSubVar(ref v0, ref v1) => to_bytes::iter_bytes_3(&0u8, v0, v1, lsb0, f), @@ -377,7 +377,7 @@ impl TwoRegions : cmp::Eq { } impl TwoRegions : to_bytes::IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { to_bytes::iter_bytes_2(&self.a, &self.b, lsb0, f) } } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index f35a3ce735f..a34fcc89c04 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -251,7 +251,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { colors = do par::mapi_factory(*color_vec) { let colors = arc::clone(&color); let graph = arc::clone(&graph); - fn~(i: uint, c: color) -> color { + fn~(+i: uint, +c: color) -> color { let c : color = c; let colors = arc::get(&colors); let graph = arc::get(&graph); diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index d9859d54648..ee38b957b0c 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -94,7 +94,7 @@ type devnull = {dn: int}; impl devnull: io::Writer { fn write(_b: &[const u8]) {} - fn seek(_i: int, _s: io::SeekStyle) {} + fn seek(+_i: int, +_s: io::SeekStyle) {} fn tell() -> uint {0_u} fn flush() -> int {0} fn get_type() -> io::WriterType { io::File } -- cgit 1.4.1-3-g733a5 From f78cdcb6364cf938bfeb71da0c7eca62e257d537 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 2 Oct 2012 11:37:37 -0700 Subject: Removing explicit uses of + mode This removes most explicit uses of the + argument mode. Pending a snapshot, I had to remove the forbid(deprecated_modes) pragma from a bunch of files. I'll put it back! + mode still has to be used in a few places for functions that get moved (see task.rs) The changes outside core and std are due to the to_bytes trait and making the compiler (with legacy modes on) agree with the libraries (with legacy modes off) about modes. --- src/libcore/at_vec.rs | 18 +++---- src/libcore/cast.rs | 18 +++---- src/libcore/comm.rs | 10 ++-- src/libcore/dlist.rs | 32 ++++++------- src/libcore/dvec.rs | 28 +++++------ src/libcore/either.rs | 7 +-- src/libcore/extfmt.rs | 10 ++-- src/libcore/future.rs | 6 +-- src/libcore/int-template.rs | 4 +- src/libcore/io.rs | 18 +++---- src/libcore/iter-trait.rs | 10 ++-- src/libcore/iter.rs | 27 +++++------ src/libcore/mutable.rs | 7 ++- src/libcore/ops.rs | 2 +- src/libcore/option.rs | 32 ++++++------- src/libcore/os.rs | 6 +-- src/libcore/pipes.rs | 68 +++++++++++++------------- src/libcore/private.rs | 10 ++-- src/libcore/reflect.rs | 2 +- src/libcore/result.rs | 18 +++---- src/libcore/run.rs | 6 +-- src/libcore/send_map.rs | 8 ++-- src/libcore/stackwalk.rs | 2 + src/libcore/str.rs | 2 +- src/libcore/sys.rs | 2 +- src/libcore/task.rs | 16 +++---- src/libcore/task/local_data.rs | 32 ++++++------- src/libcore/task/local_data_priv.rs | 2 +- src/libcore/task/spawn.rs | 20 ++++---- src/libcore/util.rs | 10 ++-- src/libcore/vec.rs | 96 ++++++++++++++++++------------------- src/libstd/getopts.rs | 2 +- src/libstd/net_tcp.rs | 8 ++-- src/libstd/net_url.rs | 2 +- src/libstd/rope.rs | 4 +- src/libstd/std.rc | 3 ++ src/rustc/middle/lint.rs | 8 +++- src/test/bench/graph500-bfs.rs | 2 +- 38 files changed, 282 insertions(+), 276 deletions(-) (limited to 'src/test') diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 6936de2bccb..7d410c0337a 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -1,7 +1,7 @@ //! Managed vectors // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use cast::transmute; @@ -48,7 +48,7 @@ pub pure fn capacity(v: @[const T]) -> uint { */ #[inline(always)] pub pure fn build_sized(size: uint, - builder: &fn(push: pure fn(+v: A))) -> @[A] { + builder: &fn(push: pure fn(v: A))) -> @[A] { let mut vec: @[const A] = @[]; unsafe { raw::reserve(&mut vec, size); } builder(|+x| unsafe { raw::push(&mut vec, move x) }); @@ -66,7 +66,7 @@ pub pure fn build_sized(size: uint, * onto the vector being constructed. */ #[inline(always)] -pub pure fn build(builder: &fn(push: pure fn(+v: A))) -> @[A] { +pub pure fn build(builder: &fn(push: pure fn(v: A))) -> @[A] { build_sized(4, builder) } @@ -83,8 +83,8 @@ pub pure fn build(builder: &fn(push: pure fn(+v: A))) -> @[A] { * onto the vector being constructed. */ #[inline(always)] -pub pure fn build_sized_opt(+size: Option, - builder: &fn(push: pure fn(+v: A))) -> @[A] { +pub pure fn build_sized_opt(size: Option, + builder: &fn(push: pure fn(v: A))) -> @[A] { build_sized(size.get_default(4), builder) } @@ -126,7 +126,7 @@ pub pure fn from_fn(n_elts: uint, op: iter::InitOp) -> @[T] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value `t`. */ -pub pure fn from_elem(n_elts: uint, +t: T) -> @[T] { +pub pure fn from_elem(n_elts: uint, t: T) -> @[T] { do build_sized(n_elts) |push| { let mut i: uint = 0u; while i < n_elts { push(copy t); i += 1u; } @@ -166,7 +166,7 @@ pub mod raw { } #[inline(always)] - pub unsafe fn push(v: &mut @[const T], +initval: T) { + pub unsafe fn push(v: &mut @[const T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { @@ -178,7 +178,7 @@ pub mod raw { } // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please - pub unsafe fn push_fast(v: &mut @[const T], +initval: T) { + pub unsafe fn push_fast(v: &mut @[const T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); @@ -187,7 +187,7 @@ pub mod raw { rusti::move_val_init(*p, move initval); } - pub unsafe fn push_slow(v: &mut @[const T], +initval: T) { + pub unsafe fn push_slow(v: &mut @[const T], initval: T) { reserve_at_least(v, v.len() + 1u); push_fast(v, move initval); } diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 21f5861b89e..f4f0d7b6104 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -21,7 +21,7 @@ pub unsafe fn reinterpret_cast(src: &T) -> U { * reinterpret_cast on managed pointer types. */ #[inline(always)] -pub unsafe fn forget(+thing: T) { rusti::forget(move thing); } +pub unsafe fn forget(thing: T) { rusti::forget(move thing); } /** * Force-increment the reference count on a shared box. If used @@ -29,7 +29,7 @@ pub unsafe fn forget(+thing: T) { rusti::forget(move thing); } * and/or reinterpret_cast when such calls would otherwise scramble a box's * reference count */ -pub unsafe fn bump_box_refcount(+t: @T) { forget(move t); } +pub unsafe fn bump_box_refcount(t: @T) { forget(move t); } /** * Transform a value of one type into a value of another type. @@ -40,7 +40,7 @@ pub unsafe fn bump_box_refcount(+t: @T) { forget(move t); } * assert transmute("L") == ~[76u8, 0u8]; */ #[inline(always)] -pub unsafe fn transmute(+thing: L) -> G { +pub unsafe fn transmute(thing: L) -> G { let newthing: G = reinterpret_cast(&thing); forget(move thing); move newthing @@ -48,33 +48,33 @@ pub unsafe fn transmute(+thing: L) -> G { /// Coerce an immutable reference to be mutable. #[inline(always)] -pub unsafe fn transmute_mut(+ptr: &a/T) -> &a/mut T { transmute(move ptr) } +pub unsafe fn transmute_mut(ptr: &a/T) -> &a/mut T { transmute(move ptr) } /// Coerce a mutable reference to be immutable. #[inline(always)] -pub unsafe fn transmute_immut(+ptr: &a/mut T) -> &a/T { +pub unsafe fn transmute_immut(ptr: &a/mut T) -> &a/T { transmute(move ptr) } /// Coerce a borrowed pointer to have an arbitrary associated region. #[inline(always)] -pub unsafe fn transmute_region(+ptr: &a/T) -> &b/T { transmute(move ptr) } +pub unsafe fn transmute_region(ptr: &a/T) -> &b/T { transmute(move ptr) } /// Coerce an immutable reference to be mutable. #[inline(always)] -pub unsafe fn transmute_mut_unsafe(+ptr: *const T) -> *mut T { +pub unsafe fn transmute_mut_unsafe(ptr: *const T) -> *mut T { transmute(ptr) } /// Coerce an immutable reference to be mutable. #[inline(always)] -pub unsafe fn transmute_immut_unsafe(+ptr: *const T) -> *T { +pub unsafe fn transmute_immut_unsafe(ptr: *const T) -> *T { transmute(ptr) } /// Coerce a borrowed mutable pointer to have an arbitrary associated region. #[inline(always)] -pub unsafe fn transmute_mut_region(+ptr: &a/mut T) -> &b/mut T { +pub unsafe fn transmute_mut_region(ptr: &a/mut T) -> &b/mut T { transmute(move ptr) } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index ff9f9498a98..64c38d13e49 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -32,8 +32,8 @@ will once again be the preferred module for intertask communication. */ -// NB: transitionary, de-mode-ing. -#[warn(deprecated_mode)]; +// NB: transitionary, de-mode-ing +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use either::Either; @@ -75,7 +75,7 @@ pub fn Port() -> Port { impl Port { fn chan() -> Chan { Chan(self) } - fn send(+v: T) { self.chan().send(move v) } + fn send(v: T) { self.chan().send(move v) } fn recv() -> T { recv(self) } fn peek() -> bool { peek(self) } @@ -84,7 +84,7 @@ impl Port { impl Chan { fn chan() -> Chan { self } - fn send(+v: T) { send(self, move v) } + fn send(v: T) { send(self, move v) } fn recv() -> T { recv_chan(self) } fn peek() -> bool { peek_chan(self) } @@ -174,7 +174,7 @@ pub fn Chan(&&p: Port) -> Chan { * Sends data over a channel. The sent data is moved into the channel, * whereupon the caller loses access to it. */ -pub fn send(ch: Chan, +data: T) { +pub fn send(ch: Chan, data: T) { let Chan_(p) = ch; let data_ptr = ptr::addr_of(&data) as *(); let res = rustrt::rust_port_id_send(p, data_ptr); diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 4e08dd4c2f3..17ddd6ea73b 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -9,7 +9,7 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate. */ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; type DListLink = Option>; @@ -80,7 +80,7 @@ impl DListNode { } /// Creates a new dlist node with the given data. -pure fn new_dlist_node(+data: T) -> DListNode { +pure fn new_dlist_node(data: T) -> DListNode { DListNode(@{data: move data, mut linked: false, mut prev: None, mut next: None}) } @@ -91,13 +91,13 @@ pure fn DList() -> DList { } /// Creates a new dlist with a single element -pub pure fn from_elem(+data: T) -> DList { +pub pure fn from_elem(data: T) -> DList { let list = DList(); unsafe { list.push(move data); } list } -pub fn from_vec(+vec: &[T]) -> DList { +pub fn from_vec(vec: &[T]) -> DList { do vec::foldl(DList(), vec) |list,data| { list.push(*data); // Iterating left-to-right -- add newly to the tail. list @@ -115,7 +115,7 @@ fn concat(lists: DList>) -> DList { } priv impl DList { - pure fn new_link(+data: T) -> DListLink { + pure fn new_link(data: T) -> DListLink { Some(DListNode(@{data: move data, mut linked: true, mut prev: None, mut next: None})) } @@ -142,7 +142,7 @@ priv impl DList { // Link two nodes together. If either of them are 'none', also sets // the head and/or tail pointers appropriately. #[inline(always)] - fn link(+before: DListLink, +after: DListLink) { + fn link(before: DListLink, after: DListLink) { match before { Some(neighbour) => neighbour.next = after, None => self.hd = after @@ -163,12 +163,12 @@ priv impl DList { self.size -= 1; } - fn add_head(+nobe: DListLink) { + fn add_head(nobe: DListLink) { self.link(nobe, self.hd); // Might set tail too. self.hd = nobe; self.size += 1; } - fn add_tail(+nobe: DListLink) { + fn add_tail(nobe: DListLink) { self.link(self.tl, nobe); // Might set head too. self.tl = nobe; self.size += 1; @@ -198,27 +198,27 @@ impl DList { pure fn is_not_empty() -> bool { self.len() != 0 } /// Add data to the head of the list. O(1). - fn push_head(+data: T) { + fn push_head(data: T) { self.add_head(self.new_link(move data)); } /** * Add data to the head of the list, and get the new containing * node. O(1). */ - fn push_head_n(+data: T) -> DListNode { + fn push_head_n(data: T) -> DListNode { let mut nobe = self.new_link(move data); self.add_head(nobe); option::get(&nobe) } /// Add data to the tail of the list. O(1). - fn push(+data: T) { + fn push(data: T) { self.add_tail(self.new_link(move data)); } /** * Add data to the tail of the list, and get the new containing * node. O(1). */ - fn push_n(+data: T) -> DListNode { + fn push_n(data: T) -> DListNode { let mut nobe = self.new_link(move data); self.add_tail(nobe); option::get(&nobe) @@ -227,7 +227,7 @@ impl DList { * Insert data into the middle of the list, left of the given node. * O(1). */ - fn insert_before(+data: T, neighbour: DListNode) { + fn insert_before(data: T, neighbour: DListNode) { self.insert_left(self.new_link(move data), neighbour); } /** @@ -242,7 +242,7 @@ impl DList { * Insert data in the middle of the list, left of the given node, * and get its containing node. O(1). */ - fn insert_before_n(+data: T, neighbour: DListNode) -> DListNode { + fn insert_before_n(data: T, neighbour: DListNode) -> DListNode { let mut nobe = self.new_link(move data); self.insert_left(nobe, neighbour); option::get(&nobe) @@ -251,7 +251,7 @@ impl DList { * Insert data into the middle of the list, right of the given node. * O(1). */ - fn insert_after(+data: T, neighbour: DListNode) { + fn insert_after(data: T, neighbour: DListNode) { self.insert_right(neighbour, self.new_link(move data)); } /** @@ -266,7 +266,7 @@ impl DList { * Insert data in the middle of the list, right of the given node, * and get its containing node. O(1). */ - fn insert_after_n(+data: T, neighbour: DListNode) -> DListNode { + fn insert_after_n(data: T, neighbour: DListNode) -> DListNode { let mut nobe = self.new_link(move data); self.insert_right(neighbour, nobe); option::get(&nobe) diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 3ce5a7153fd..a2a70908797 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -10,7 +10,7 @@ Note that recursive use is not permitted. */ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use cast::reinterpret_cast; @@ -61,17 +61,17 @@ pub fn DVec() -> DVec { } /// Creates a new dvec with a single element -pub fn from_elem(+e: A) -> DVec { +pub fn from_elem(e: A) -> DVec { DVec_({mut data: ~[move e]}) } /// Creates a new dvec with the contents of a vector -pub fn from_vec(+v: ~[A]) -> DVec { +pub fn from_vec(v: ~[A]) -> DVec { DVec_({mut data: move v}) } /// Consumes the vector and returns its contents -pub fn unwrap(+d: DVec) -> ~[A] { +pub fn unwrap(d: DVec) -> ~[A] { let DVec_({data: v}) <- d; move v } @@ -87,7 +87,7 @@ priv impl DVec { } #[inline(always)] - fn check_out(f: &fn(+v: ~[A]) -> B) -> B { + fn check_out(f: &fn(v: ~[A]) -> B) -> B { unsafe { let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; @@ -98,7 +98,7 @@ priv impl DVec { } #[inline(always)] - fn give_back(+data: ~[A]) { + fn give_back(data: ~[A]) { unsafe { self.data = move data; } @@ -120,7 +120,7 @@ impl DVec { * and return a new vector to replace it with. */ #[inline(always)] - fn swap(f: &fn(+v: ~[A]) -> ~[A]) { + fn swap(f: &fn(v: ~[A]) -> ~[A]) { self.check_out(|v| self.give_back(f(move v))) } @@ -130,7 +130,7 @@ impl DVec { * and return a new vector to replace it with. */ #[inline(always)] - fn swap_mut(f: &fn(+v: ~[mut A]) -> ~[mut A]) { + fn swap_mut(f: &fn(v: ~[mut A]) -> ~[mut A]) { do self.swap |v| { vec::from_mut(f(vec::to_mut(move v))) } @@ -148,7 +148,7 @@ impl DVec { } /// Overwrite the current contents - fn set(+w: ~[A]) { + fn set(w: ~[A]) { self.check_not_borrowed(); self.data <- w; } @@ -164,7 +164,7 @@ impl DVec { } /// Insert a single item at the front of the list - fn unshift(+t: A) { + fn unshift(t: A) { unsafe { let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; @@ -178,7 +178,7 @@ impl DVec { } /// Append a single item to the end of the list - fn push(+t: A) { + fn push(t: A) { self.check_not_borrowed(); self.data.push(move t); } @@ -295,7 +295,7 @@ impl DVec { } /// Overwrites the contents of the element at `idx` with `a` - fn set_elt(idx: uint, +a: A) { + fn set_elt(idx: uint, a: A) { self.check_not_borrowed(); self.data[idx] = a; } @@ -305,7 +305,7 @@ impl DVec { * growing the vector if necessary. New elements will be initialized * with `initval` */ - fn grow_set_elt(idx: uint, initval: &A, +val: A) { + fn grow_set_elt(idx: uint, initval: &A, val: A) { do self.swap |v| { let mut v = move v; v.grow_set(idx, initval, val); @@ -354,7 +354,7 @@ impl DVec { } impl DVec: Index { - pure fn index(+idx: uint) -> A { + pure fn index(idx: uint) -> A { self.get_elt(idx) } } diff --git a/src/libcore/either.rs b/src/libcore/either.rs index dd3bcdfdf88..c64cd25e481 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; //! A type that represents one of two alternatives @@ -114,7 +114,8 @@ pub pure fn is_right(eith: &Either) -> bool { match *eith { Right(_) => true, _ => false } } -pub pure fn unwrap_left(+eith: Either) -> T { +// tjc: fix the next two after a snapshot +pub pure fn unwrap_left(eith: Either) -> T { //! Retrieves the value in the left branch. Fails if the either is Right. match move eith { @@ -122,7 +123,7 @@ pub pure fn unwrap_left(+eith: Either) -> T { } } -pub pure fn unwrap_right(+eith: Either) -> U { +pub pure fn unwrap_right(eith: Either) -> U { //! Retrieves the value in the right branch. Fails if the either is Left. match move eith { diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 25f92e61726..e10ff4bac71 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -87,7 +87,7 @@ mod ct { let mut pieces: ~[Piece] = ~[]; let lim = str::len(s); let mut buf = ~""; - fn flush_buf(+buf: ~str, pieces: &mut ~[Piece]) -> ~str { + fn flush_buf(buf: ~str, pieces: &mut ~[Piece]) -> ~str { if buf.len() > 0 { let piece = PieceString(move buf); pieces.push(move piece); @@ -323,7 +323,7 @@ mod rt { let mut s = str::from_char(c); return unsafe { pad(cv, s, PadNozero) }; } - pure fn conv_str(cv: Conv, +s: &str) -> ~str { + pure fn conv_str(cv: Conv, s: &str) -> ~str { // For strings, precision is the maximum characters // displayed let mut unpadded = match cv.precision { @@ -405,7 +405,7 @@ mod rt { pure fn ne(other: &PadMode) -> bool { !self.eq(other) } } - fn pad(cv: Conv, +s: ~str, mode: PadMode) -> ~str { + fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str { let mut s = move s; // sadtimes let uwidth : uint = match cv.width { CountImplied => return s, @@ -518,7 +518,7 @@ mod rt2 { let mut s = str::from_char(c); return unsafe { pad(cv, s, PadNozero) }; } - pure fn conv_str(cv: Conv, +s: &str) -> ~str { + pure fn conv_str(cv: Conv, s: &str) -> ~str { // For strings, precision is the maximum characters // displayed let mut unpadded = match cv.precision { @@ -600,7 +600,7 @@ mod rt2 { pure fn ne(other: &PadMode) -> bool { !self.eq(other) } } - fn pad(cv: Conv, +s: ~str, mode: PadMode) -> ~str { + fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str { let mut s = move s; // sadtimes let uwidth : uint = match cv.width { CountImplied => return s, diff --git a/src/libcore/future.rs b/src/libcore/future.rs index db311ea3e82..11b6a2c0135 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; /*! @@ -55,7 +55,7 @@ impl Future { } } -pub fn from_value(+val: A) -> Future { +pub fn from_value(val: A) -> Future { /*! * Create a future from a value * @@ -66,7 +66,7 @@ pub fn from_value(+val: A) -> Future { Future {state: Forced(~(move val))} } -pub fn from_port(+port: future_pipe::client::waiting) -> +pub fn from_port(port: future_pipe::client::waiting) -> Future { /*! * Create a future from a port diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index ddd26205000..6942d38d5d3 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use T = inst::T; @@ -231,7 +231,7 @@ fn test_to_str() { #[test] fn test_interfaces() { - fn test(+ten: U) { + fn test(ten: U) { assert (ten.to_int() == 10); let two: U = from_int(2); diff --git a/src/libcore/io.rs b/src/libcore/io.rs index f8f644a17ab..2efc96933da 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -813,7 +813,7 @@ pub mod fsync { } } - pub fn Res(+arg: Arg) -> Res{ + pub fn Res(arg: Arg) -> Res{ Res { arg: move arg } @@ -822,17 +822,17 @@ pub mod fsync { pub type Arg = { val: t, opt_level: Option, - fsync_fn: fn@(+f: t, Level) -> int + fsync_fn: fn@(f: t, Level) -> int }; // fsync file after executing blk // FIXME (#2004) find better way to create resources within lifetime of // outer res pub fn FILE_res_sync(file: &FILERes, opt_level: Option, - blk: fn(+v: Res<*libc::FILE>)) { + blk: fn(v: Res<*libc::FILE>)) { blk(move Res({ val: file.f, opt_level: opt_level, - fsync_fn: fn@(+file: *libc::FILE, l: Level) -> int { + fsync_fn: fn@(file: *libc::FILE, l: Level) -> int { return os::fsync_fd(libc::fileno(file), l) as int; } })); @@ -840,10 +840,10 @@ pub mod fsync { // fsync fd after executing blk pub fn fd_res_sync(fd: &FdRes, opt_level: Option, - blk: fn(+v: Res)) { + blk: fn(v: Res)) { blk(move Res({ val: fd.fd, opt_level: opt_level, - fsync_fn: fn@(+fd: fd_t, l: Level) -> int { + fsync_fn: fn@(fd: fd_t, l: Level) -> int { return os::fsync_fd(fd, l) as int; } })); @@ -853,11 +853,11 @@ pub mod fsync { pub trait FSyncable { fn fsync(l: Level) -> int; } // Call o.fsync after executing blk - pub fn obj_sync(+o: FSyncable, opt_level: Option, - blk: fn(+v: Res)) { + pub fn obj_sync(o: FSyncable, opt_level: Option, + blk: fn(v: Res)) { blk(Res({ val: o, opt_level: opt_level, - fsync_fn: fn@(+o: FSyncable, l: Level) -> int { + fsync_fn: fn@(o: FSyncable, l: Level) -> int { return o.fsync(l); } })); diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index a2fb4698d7c..09bfe2eff36 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -16,7 +16,7 @@ impl IMPL_T: iter::ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(&self, blk) } pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } - pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B { + pure fn foldl(b0: B, blk: fn(&B, &A) -> B) -> B { iter::foldl(&self, move b0, blk) } pure fn position(f: fn(&A) -> bool) -> Option { @@ -30,20 +30,20 @@ impl IMPL_T: iter::EqIter { } impl IMPL_T: iter::CopyableIter { - pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A] { + pure fn filter_to_vec(pred: fn(a: A) -> bool) -> ~[A] { iter::filter_to_vec(&self, pred) } - pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B] { + pure fn map_to_vec(op: fn(v: A) -> B) -> ~[B] { iter::map_to_vec(&self, op) } pure fn to_vec() -> ~[A] { iter::to_vec(&self) } - pure fn flat_map_to_vec>(op: fn(+a: A) -> IB) + pure fn flat_map_to_vec>(op: fn(a: A) -> IB) -> ~[B] { iter::flat_map_to_vec(&self, op) } - pure fn find(p: fn(+a: A) -> bool) -> Option { iter::find(&self, p) } + pure fn find(p: fn(a: A) -> bool) -> Option { iter::find(&self, p) } } impl IMPL_T: iter::CopyableOrderedIter { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 5271555d299..bf3e91f7071 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -18,7 +18,7 @@ pub trait ExtendedIter { pure fn eachi(blk: fn(uint, v: &A) -> bool); pure fn all(blk: fn(&A) -> bool) -> bool; pure fn any(blk: fn(&A) -> bool) -> bool; - pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B; + pure fn foldl(b0: B, blk: fn(&B, &A) -> B) -> B; pure fn position(f: fn(&A) -> bool) -> Option; } @@ -36,10 +36,10 @@ pub trait TimesIx{ } pub trait CopyableIter { - pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A]; - pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B]; + pure fn filter_to_vec(pred: fn(a: A) -> bool) -> ~[A]; + pure fn map_to_vec(op: fn(v: A) -> B) -> ~[B]; pure fn to_vec() -> ~[A]; - pure fn find(p: fn(+a: A) -> bool) -> Option; + pure fn find(p: fn(a: A) -> bool) -> Option; } pub trait CopyableOrderedIter { @@ -64,7 +64,7 @@ pub trait Buildable { * onto the sequence being constructed. */ static pure fn build_sized(size: uint, - builder: fn(push: pure fn(+v: A))) -> self; + builder: fn(push: pure fn(v: A))) -> self; } pub pure fn eachi>(self: &IA, @@ -93,7 +93,7 @@ pub pure fn any>(self: &IA, } pub pure fn filter_to_vec>( - self: &IA, prd: fn(+a: A) -> bool) -> ~[A] { + self: &IA, prd: fn(a: A) -> bool) -> ~[A] { do vec::build_sized_opt(self.size_hint()) |push| { for self.each |a| { if prd(*a) { push(*a); } @@ -102,7 +102,7 @@ pub pure fn filter_to_vec>( } pub pure fn map_to_vec>(self: &IA, - op: fn(+v: A) -> B) + op: fn(v: A) -> B) -> ~[B] { do vec::build_sized_opt(self.size_hint()) |push| { for self.each |a| { @@ -112,8 +112,7 @@ pub pure fn map_to_vec>(self: &IA, } pub pure fn flat_map_to_vec,IB:BaseIter>( - self: &IA, op: fn(+a: A) -> IB) -> ~[B] { - + self: &IA, op: fn(a: A) -> IB) -> ~[B] { do vec::build |push| { for self.each |a| { for op(*a).each |b| { @@ -123,7 +122,7 @@ pub pure fn flat_map_to_vec,IB:BaseIter>( } } -pub pure fn foldl>(self: &IA, +b0: B, +pub pure fn foldl>(self: &IA, b0: B, blk: fn(&B, &A) -> B) -> B { let mut b <- b0; @@ -206,7 +205,7 @@ pub pure fn max>(self: &IA) -> A { } pub pure fn find>(self: &IA, - p: fn(+a: A) -> bool) -> Option { + p: fn(a: A) -> bool) -> Option { for self.each |i| { if p(*i) { return Some(*i) } } @@ -226,7 +225,7 @@ pub pure fn find>(self: &IA, * onto the sequence being constructed. */ #[inline(always)] -pub pure fn build>(builder: fn(push: pure fn(+v: A))) +pub pure fn build>(builder: fn(push: pure fn(v: A))) -> B { build_sized(4, builder) } @@ -247,7 +246,7 @@ pub pure fn build>(builder: fn(push: pure fn(+v: A))) #[inline(always)] pub pure fn build_sized_opt>( size: Option, - builder: fn(push: pure fn(+v: A))) -> B { + builder: fn(push: pure fn(v: A))) -> B { build_sized(size.get_default(4), builder) } @@ -285,7 +284,7 @@ pub pure fn from_fn>(n_elts: uint, * to the value `t`. */ pub pure fn from_elem>(n_elts: uint, - +t: T) -> BT { + t: T) -> BT { do build_sized(n_elts) |push| { let mut i: uint = 0; while i < n_elts { push(t); i += 1; } diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index a1f65117ecf..5948c630cd8 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -8,8 +8,7 @@ dynamic checks: your program will fail if you attempt to perform mutation when the data structure should be immutable. */ - -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use util::with; @@ -24,11 +23,11 @@ struct Data { pub type Mut = Data; -pub fn Mut(+t: T) -> Mut { +pub fn Mut(t: T) -> Mut { Data {value: t, mode: ReadOnly} } -pub fn unwrap(+m: Mut) -> T { +pub fn unwrap(m: Mut) -> T { // Borrowck should prevent us from calling unwrap while the value // is in use, as that would be a move from a borrowed value. assert (m.mode as uint) == (ReadOnly as uint); diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 994e010e452..038c117b8be 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -77,6 +77,6 @@ pub trait Shr { #[lang="index"] pub trait Index { - pure fn index(+index: Index) -> Result; + pure fn index(index: Index) -> Result; } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 87d6aeefbc3..6bd326186cb 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -49,7 +49,7 @@ pub pure fn get_ref(opt: &r/Option) -> &r/T { } } -pub pure fn expect(opt: &Option, +reason: ~str) -> T { +pub pure fn expect(opt: &Option, reason: ~str) -> T { /*! * Gets the value out of an option, printing a specified message on * failure @@ -67,8 +67,8 @@ pub pure fn map(opt: &Option, f: fn(x: &T) -> U) -> Option { match *opt { Some(ref x) => Some(f(x)), None => None } } -pub pure fn map_consume(+opt: Option, - f: fn(+v: T) -> U) -> Option { +pub pure fn map_consume(opt: Option, + f: fn(v: T) -> U) -> Option { /*! * As `map`, but consumes the option and gives `f` ownership to avoid * copying. @@ -76,8 +76,8 @@ pub pure fn map_consume(+opt: Option, if opt.is_some() { Some(f(option::unwrap(move opt))) } else { None } } -pub pure fn chain(+opt: Option, - f: fn(+t: T) -> Option) -> Option { +pub pure fn chain(opt: Option, + f: fn(t: T) -> Option) -> Option { /*! * Update an optional value by optionally running its content through a * function that returns an option. @@ -101,7 +101,7 @@ pub pure fn chain_ref(opt: &Option, match *opt { Some(ref x) => f(x), None => None } } -pub pure fn or(+opta: Option, +optb: Option) -> Option { +pub pure fn or(opta: Option, optb: Option) -> Option { /*! * Returns the leftmost some() value, or none if both are none. */ @@ -112,7 +112,7 @@ pub pure fn or(+opta: Option, +optb: Option) -> Option { } #[inline(always)] -pub pure fn while_some(+x: Option, blk: fn(+v: T) -> Option) { +pub pure fn while_some(x: Option, blk: fn(v: T) -> Option) { //! Applies a function zero or more times until the result is none. let mut opt <- x; @@ -133,13 +133,13 @@ pub pure fn is_some(opt: &Option) -> bool { !is_none(opt) } -pub pure fn get_default(opt: &Option, +def: T) -> T { +pub pure fn get_default(opt: &Option, def: T) -> T { //! Returns the contained value or a default match *opt { Some(copy x) => x, None => def } } -pub pure fn map_default(opt: &Option, +def: U, +pub pure fn map_default(opt: &Option, def: U, f: fn(x: &T) -> U) -> U { //! Applies a function to the contained value or returns a default @@ -151,10 +151,8 @@ pub pure fn iter(opt: &Option, f: fn(x: &T)) { match *opt { None => (), Some(ref t) => f(t) } } -// tjc: shouldn't this be - instead of +? -// then could get rid of some superfluous moves #[inline(always)] -pub pure fn unwrap(+opt: Option) -> T { +pub pure fn unwrap(opt: Option) -> T { /*! * Moves a value out of an option type and returns it. * @@ -174,7 +172,7 @@ pub fn swap_unwrap(opt: &mut Option) -> T { unwrap(util::replace(opt, None)) } -pub pure fn unwrap_expect(+opt: Option, reason: &str) -> T { +pub pure fn unwrap_expect(opt: Option, reason: &str) -> T { //! As unwrap, but with a specified failure message. if opt.is_none() { fail reason.to_unique(); } unwrap(move opt) @@ -197,7 +195,7 @@ impl &Option { chain_ref(self, f) } /// Applies a function to the contained value or returns a default - pure fn map_default(+def: U, f: fn(x: &T) -> U) -> U + pure fn map_default(def: U, f: fn(x: &T) -> U) -> U { map_default(self, move def, f) } /// Performs an operation on the contained value by reference pure fn iter(f: fn(x: &T)) { iter(self, f) } @@ -216,7 +214,7 @@ impl Option { * Fails if the value equals `none` */ pure fn get() -> T { get(&self) } - pure fn get_default(+def: T) -> T { get_default(&self, def) } + pure fn get_default(def: T) -> T { get_default(&self, def) } /** * Gets the value out of an option, printing a specified message on * failure @@ -225,9 +223,9 @@ impl Option { * * Fails if the value equals `none` */ - pure fn expect(+reason: ~str) -> T { expect(&self, reason) } + pure fn expect(reason: ~str) -> T { expect(&self, reason) } /// Applies a function zero or more times until the result is none. - pure fn while_some(blk: fn(+v: T) -> Option) { while_some(self, blk) } + pure fn while_some(blk: fn(v: T) -> Option) { while_some(self, blk) } } impl Option : Eq { diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 1cf4fbab6c9..f178502f6a0 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid #[forbid(deprecated_pattern)]; /*! @@ -768,7 +768,7 @@ struct OverriddenArgs { val: ~[~str] } -fn overridden_arg_key(+_v: @OverriddenArgs) {} +fn overridden_arg_key(_v: @OverriddenArgs) {} pub fn args() -> ~[~str] { unsafe { @@ -779,7 +779,7 @@ pub fn args() -> ~[~str] { } } -pub fn set_args(+new_args: ~[~str]) { +pub fn set_args(new_args: ~[~str]) { unsafe { let overridden_args = @OverriddenArgs { val: copy new_args }; task::local_data::local_data_set(overridden_arg_key, overridden_args); diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 4d446df9cd5..e34c0db35e9 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -73,7 +73,7 @@ bounded and unbounded protocols allows for less code duplication. */ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use cmp::Eq; @@ -169,7 +169,7 @@ impl PacketHeader { reinterpret_cast(&self.buffer) } - fn set_buffer(+b: ~Buffer) unsafe { + fn set_buffer(b: ~Buffer) unsafe { self.buffer = reinterpret_cast(&b); } } @@ -227,7 +227,7 @@ pub fn packet() -> *Packet { #[doc(hidden)] pub fn entangle_buffer( - +buffer: ~Buffer, + buffer: ~Buffer, init: fn(*libc::c_void, x: &T) -> *Packet) -> (SendPacketBuffered, RecvPacketBuffered) { @@ -239,12 +239,12 @@ pub fn entangle_buffer( #[abi = "rust-intrinsic"] #[doc(hidden)] extern mod rusti { - fn atomic_xchg(dst: &mut int, +src: int) -> int; - fn atomic_xchg_acq(dst: &mut int, +src: int) -> int; - fn atomic_xchg_rel(dst: &mut int, +src: int) -> int; + fn atomic_xchg(dst: &mut int, src: int) -> int; + fn atomic_xchg_acq(dst: &mut int, src: int) -> int; + fn atomic_xchg_rel(dst: &mut int, src: int) -> int; - fn atomic_xadd_acq(dst: &mut int, +src: int) -> int; - fn atomic_xsub_rel(dst: &mut int, +src: int) -> int; + fn atomic_xadd_acq(dst: &mut int, src: int) -> int; + fn atomic_xsub_rel(dst: &mut int, src: int) -> int; } // If I call the rusti versions directly from a polymorphic function, @@ -265,7 +265,7 @@ pub fn atomic_sub_rel(dst: &mut int, src: int) -> int { } #[doc(hidden)] -pub fn swap_task(+dst: &mut *rust_task, src: *rust_task) -> *rust_task { +pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task { // It might be worth making both acquire and release versions of // this. unsafe { @@ -304,14 +304,14 @@ fn wait_event(this: *rust_task) -> *libc::c_void { } #[doc(hidden)] -fn swap_state_acq(+dst: &mut State, src: State) -> State { +fn swap_state_acq(dst: &mut State, src: State) -> State { unsafe { transmute(rusti::atomic_xchg_acq(transmute(move dst), src as int)) } } #[doc(hidden)] -fn swap_state_rel(+dst: &mut State, src: State) -> State { +fn swap_state_rel(dst: &mut State, src: State) -> State { unsafe { transmute(rusti::atomic_xchg_rel(transmute(move dst), src as int)) } @@ -343,7 +343,7 @@ struct BufferResource { } } -fn BufferResource(+b: ~Buffer) -> BufferResource { +fn BufferResource(b: ~Buffer) -> BufferResource { //let p = ptr::addr_of(*b); //error!("take %?", p); atomic_add_acq(&mut b.header.ref_count, 1); @@ -354,8 +354,8 @@ fn BufferResource(+b: ~Buffer) -> BufferResource { } #[doc(hidden)] -pub fn send(+p: SendPacketBuffered, - +payload: T) -> bool { +pub fn send(p: SendPacketBuffered, + payload: T) -> bool { let header = p.header(); let p_ = p.unwrap(); let p = unsafe { &*p_ }; @@ -398,7 +398,7 @@ pub fn send(+p: SendPacketBuffered, Fails if the sender closes the connection. */ -pub fn recv(+p: RecvPacketBuffered) -> T { +pub fn recv(p: RecvPacketBuffered) -> T { option::unwrap_expect(try_recv(move p), "connection closed") } @@ -408,7 +408,7 @@ Returns `none` if the sender has closed the connection without sending a message, or `Some(T)` if a message was received. */ -pub fn try_recv(+p: RecvPacketBuffered) +pub fn try_recv(p: RecvPacketBuffered) -> Option { let p_ = p.unwrap(); @@ -655,8 +655,8 @@ this case, `select2` may return either `left` or `right`. */ pub fn select2( - +a: RecvPacketBuffered, - +b: RecvPacketBuffered) + a: RecvPacketBuffered, + b: RecvPacketBuffered) -> Either<(Option, RecvPacketBuffered), (RecvPacketBuffered, Option)> { @@ -697,7 +697,7 @@ pub fn select2i(a: &A, b: &B) -> list of the remaining endpoints. */ -pub fn select(+endpoints: ~[RecvPacketBuffered]) +pub fn select(endpoints: ~[RecvPacketBuffered]) -> (uint, Option, ~[RecvPacketBuffered]) { let ready = wait_many(endpoints.map(|p| p.header())); @@ -859,7 +859,7 @@ endpoint is passed to the new task. pub fn spawn_service( init: extern fn() -> (SendPacketBuffered, RecvPacketBuffered), - +service: fn~(+v: RecvPacketBuffered)) + +service: fn~(v: RecvPacketBuffered)) -> SendPacketBuffered { let (client, server) = init(); @@ -883,7 +883,7 @@ receive state. pub fn spawn_service_recv( init: extern fn() -> (RecvPacketBuffered, SendPacketBuffered), - +service: fn~(+v: SendPacketBuffered)) + +service: fn~(v: SendPacketBuffered)) -> RecvPacketBuffered { let (client, server) = init(); @@ -914,10 +914,10 @@ pub trait Channel { // built in send kind. /// Sends a message. - fn send(+x: T); + fn send(x: T); /// Sends a message, or report if the receiver has closed the connection. - fn try_send(+x: T) -> bool; + fn try_send(x: T) -> bool; } /// A trait for things that can receive multiple messages. @@ -966,14 +966,14 @@ pub fn stream() -> (Chan, Port) { } impl Chan: Channel { - fn send(+x: T) { + fn send(x: T) { let mut endp = None; endp <-> self.endp; self.endp = Some( streamp::client::data(unwrap(move endp), move x)) } - fn try_send(+x: T) -> bool { + fn try_send(x: T) -> bool { let mut endp = None; endp <-> self.endp; match move streamp::client::try_data(unwrap(move endp), move x) { @@ -1041,7 +1041,7 @@ pub fn PortSet() -> PortSet{ impl PortSet : Recv { - fn add(+port: pipes::Port) { + fn add(port: pipes::Port) { self.ports.push(move port) } @@ -1091,7 +1091,7 @@ impl PortSet : Recv { pub type SharedChan = private::Exclusive>; impl SharedChan: Channel { - fn send(+x: T) { + fn send(x: T) { let mut xx = Some(move x); do self.with_imm |chan| { let mut x = None; @@ -1100,7 +1100,7 @@ impl SharedChan: Channel { } } - fn try_send(+x: T) -> bool { + fn try_send(x: T) -> bool { let mut xx = Some(move x); do self.with_imm |chan| { let mut x = None; @@ -1111,7 +1111,7 @@ impl SharedChan: Channel { } /// Converts a `chan` into a `shared_chan`. -pub fn SharedChan(+c: Chan) -> SharedChan { +pub fn SharedChan(c: Chan) -> SharedChan { private::exclusive(move c) } @@ -1165,13 +1165,13 @@ pub fn oneshot() -> (ChanOne, PortOne) { * Receive a message from a oneshot pipe, failing if the connection was * closed. */ -pub fn recv_one(+port: PortOne) -> T { +pub fn recv_one(port: PortOne) -> T { let oneshot::send(message) = recv(move port); move message } /// Receive a message from a oneshot pipe unless the connection was closed. -pub fn try_recv_one (+port: PortOne) -> Option { +pub fn try_recv_one (port: PortOne) -> Option { let message = try_recv(move port); if message.is_none() { None } @@ -1182,7 +1182,7 @@ pub fn try_recv_one (+port: PortOne) -> Option { } /// Send a message on a oneshot pipe, failing if the connection was closed. -pub fn send_one(+chan: ChanOne, +data: T) { +pub fn send_one(chan: ChanOne, data: T) { oneshot::client::send(move chan, move data); } @@ -1190,7 +1190,7 @@ pub fn send_one(+chan: ChanOne, +data: T) { * Send a message on a oneshot pipe, or return false if the connection was * closed. */ -pub fn try_send_one(+chan: ChanOne, +data: T) +pub fn try_send_one(chan: ChanOne, data: T) -> bool { oneshot::client::try_send(move chan, move data).is_some() } @@ -1198,7 +1198,7 @@ pub fn try_send_one(+chan: ChanOne, +data: T) pub mod rt { // These are used to hide the option constructors from the // compiler because their names are changing - pub fn make_some(+val: T) -> Option { Some(move val) } + pub fn make_some(val: T) -> Option { Some(move val) } pub fn make_none() -> Option { None } } diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 025a6f28976..c1b2b32edaf 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; #[doc(hidden)]; @@ -340,7 +340,7 @@ fn ArcDestruct(data: *libc::c_void) -> ArcDestruct { } } -pub unsafe fn unwrap_shared_mutable_state(+rc: SharedMutableState) +pub unsafe fn unwrap_shared_mutable_state(rc: SharedMutableState) -> T { struct DeathThroes { mut ptr: Option<~ArcData>, @@ -413,7 +413,7 @@ pub unsafe fn unwrap_shared_mutable_state(+rc: SharedMutableState) */ pub type SharedMutableState = ArcDestruct; -pub unsafe fn shared_mutable_state(+data: T) -> +pub unsafe fn shared_mutable_state(data: T) -> SharedMutableState { let data = ~ArcData { count: 1, unwrapper: 0, data: Some(move data) }; unsafe { @@ -502,7 +502,7 @@ struct ExData { lock: LittleLock, mut failed: bool, mut data: T, } */ pub struct Exclusive { x: SharedMutableState> } -pub fn exclusive(+user_data: T) -> Exclusive { +pub fn exclusive(user_data: T) -> Exclusive { let data = ExData { lock: LittleLock(), mut failed: false, mut data: user_data }; @@ -544,7 +544,7 @@ impl Exclusive { } // FIXME(#2585) make this a by-move method on the exclusive -pub fn unwrap_exclusive(+arc: Exclusive) -> T { +pub fn unwrap_exclusive(arc: Exclusive) -> T { let Exclusive { x: x } <- arc; let inner = unsafe { unwrap_shared_mutable_state(move x) }; let ExData { data: data, _ } <- inner; diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index af6a3f9b478..41006e1dfb5 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -27,7 +27,7 @@ fn align(size: uint, align: uint) -> uint { struct MovePtrAdaptor { inner: V } -pub fn MovePtrAdaptor(+v: V) -> MovePtrAdaptor { +pub fn MovePtrAdaptor(v: V) -> MovePtrAdaptor { MovePtrAdaptor { inner: move v } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index e454c068d47..e61690d5b2c 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1,7 +1,7 @@ //! A type representing either success or failure // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use cmp::Eq; @@ -102,7 +102,7 @@ pub pure fn to_either(res: &Result) * ok(parse_bytes(buf)) * } */ -pub fn chain(+res: Result, op: fn(+t: T) +pub fn chain(res: Result, op: fn(t: T) -> Result) -> Result { // XXX: Should be writable with move + match if res.is_ok() { @@ -121,8 +121,8 @@ pub fn chain(+res: Result, op: fn(+t: T) * successful result while handling an error. */ pub fn chain_err( - +res: Result, - op: fn(+t: V) -> Result) + res: Result, + op: fn(t: V) -> Result) -> Result { match move res { Ok(move t) => Ok(t), @@ -247,12 +247,12 @@ impl Result { } impl Result { - fn chain(op: fn(+t: T) -> Result) -> Result { + fn chain(op: fn(t: T) -> Result) -> Result { // XXX: Bad copy chain(copy self, op) } - fn chain_err(op: fn(+t: E) -> Result) -> Result { + fn chain_err(op: fn(t: E) -> Result) -> Result { // XXX: Bad copy chain_err(copy self, op) } @@ -348,7 +348,7 @@ pub fn iter_vec2(ss: &[S], ts: &[T], } /// Unwraps a result, assuming it is an `ok(T)` -pub fn unwrap(+res: Result) -> T { +pub fn unwrap(res: Result) -> T { match move res { Ok(move t) => move t, Err(_) => fail ~"unwrap called on an err result" @@ -356,7 +356,7 @@ pub fn unwrap(+res: Result) -> T { } /// Unwraps a result, assuming it is an `err(U)` -pub fn unwrap_err(+res: Result) -> U { +pub fn unwrap_err(res: Result) -> U { match move res { Err(move u) => move u, Ok(_) => fail ~"unwrap called on an ok result" @@ -389,7 +389,7 @@ mod tests { #[legacy_exports]; fn op1() -> result::Result { result::Ok(666) } - fn op2(+i: int) -> result::Result { + fn op2(i: int) -> result::Result { result::Ok(i as uint + 1u) } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 40c2bc83351..f3e98f6ba82 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; //! Process spawning @@ -224,7 +224,7 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program { drop { destroy_repr(&self.r); } } - fn ProgRes(+r: ProgRepr) -> ProgRes { + fn ProgRes(r: ProgRepr) -> ProgRes { ProgRes { r: r } @@ -328,7 +328,7 @@ pub fn program_output(prog: &str, args: &[~str]) -> return {status: status, out: move outs, err: move errs}; } -fn writeclose(fd: c_int, +s: ~str) { +fn writeclose(fd: c_int, s: ~str) { use io::WriterUtil; error!("writeclose %d, %s", fd as int, s); diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 1b219e16e09..4a56ee5b896 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -15,7 +15,7 @@ use to_bytes::IterBytes; pub trait SendMap { // FIXME(#3148) ^^^^ once find_ref() works, we can drop V:copy - fn insert(&mut self, +k: K, +v: V) -> bool; + fn insert(&mut self, k: K, +v: V) -> bool; fn remove(&mut self, k: &K) -> bool; fn clear(&mut self); pure fn len(&const self) -> uint; @@ -161,7 +161,7 @@ pub mod linear { } } - fn insert_opt_bucket(&mut self, +bucket: Option>) { + fn insert_opt_bucket(&mut self, bucket: Option>) { match move bucket { Some(Bucket {hash: move hash, key: move key, @@ -175,7 +175,7 @@ pub mod linear { /// Inserts the key value pair into the buckets. /// Assumes that there will be a bucket. /// True if there was no previous entry with that key - fn insert_internal(&mut self, hash: uint, +k: K, +v: V) -> bool { + fn insert_internal(&mut self, hash: uint, k: K, v: V) -> bool { match self.bucket_for_key_with_hash(self.buckets, hash, &k) { TableFull => { fail ~"Internal logic error"; } FoundHole(idx) => { @@ -206,7 +206,7 @@ pub mod linear { } impl LinearMap { - fn insert(&mut self, +k: K, +v: V) -> bool { + fn insert(&mut self, k: K, v: V) -> bool { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so // that we do not resize if this call to insert is diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index d0f8de136e2..09973148c8c 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -1,5 +1,7 @@ #[doc(hidden)]; // FIXME #3538 +#[legacy_modes]; // tjc: remove after snapshot + // NB: transitionary, de-mode-ing. // XXX: Can't do this because frame_address needs a deprecated mode. //#[forbid(deprecated_mode)]; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index e8a88f3bc1b..cf996a8b254 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -175,7 +175,7 @@ pub fn push_str(lhs: &const ~str, rhs: &str) { /// Concatenate two strings together #[inline(always)] -pub pure fn append(+lhs: ~str, rhs: &str) -> ~str { +pub pure fn append(lhs: ~str, rhs: &str) -> ~str { let mut v <- lhs; unsafe { push_str_no_overallocate(&mut v, rhs); diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 9f13a6c2207..12329616fbf 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -83,7 +83,7 @@ pub pure fn pref_align_of() -> uint { /// Returns the refcount of a shared box (as just before calling this) #[inline(always)] -pub pure fn refcount(+t: @T) -> uint { +pub pure fn refcount(t: @T) -> uint { unsafe { let ref_ptr: *uint = cast::reinterpret_cast(&t); *ref_ptr - 1 diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 912b7f712aa..5ca35a7f562 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; /*! @@ -232,7 +232,7 @@ pub enum TaskBuilder = { pub fn task() -> TaskBuilder { TaskBuilder({ opts: default_task_opts(), - gen_body: |body| move body, // Identity function + gen_body: |+body| move body, // Identity function can_not_copy: None, mut consumed: false, }) @@ -347,7 +347,7 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn future_result(blk: fn(+v: future::Future)) -> TaskBuilder { + fn future_result(blk: fn(v: future::Future)) -> TaskBuilder { // FIXME (#1087, #1857): Once linked failure and notification are // handled in the library, I can imagine implementing this by just // registering an arbitrary number of task::on_exit handlers and @@ -459,9 +459,9 @@ impl TaskBuilder { spawn::spawn_raw(move opts, x.gen_body(move f)); } /// Runs a task, while transfering ownership of one argument to the child. - fn spawn_with(+arg: A, +f: fn~(+v: A)) { + fn spawn_with(arg: A, +f: fn~(+v: A)) { let arg = ~mut Some(move arg); - do self.spawn |move arg, move f|{ + do self.spawn |move arg, move f| { f(option::swap_unwrap(arg)) } } @@ -473,7 +473,7 @@ impl TaskBuilder { * child task, passes the port to child's body, and returns a channel * linked to the port to the parent. * - * This encapsulates Some boilerplate handshaking logic that would + * This encapsulates some boilerplate handshaking logic that would * otherwise be required to establish communication from the parent * to the child. */ @@ -1149,7 +1149,7 @@ fn test_avoid_copying_the_body_spawn() { #[test] fn test_avoid_copying_the_body_spawn_listener() { - do avoid_copying_the_body |f| { + do avoid_copying_the_body |+f| { spawn_listener(fn~(move f, _po: comm::Port) { f(); }); @@ -1167,7 +1167,7 @@ fn test_avoid_copying_the_body_task_spawn() { #[test] fn test_avoid_copying_the_body_spawn_listener_1() { - do avoid_copying_the_body |f| { + do avoid_copying_the_body |+f| { task().spawn_listener(fn~(move f, _po: comm::Port) { f(); }); diff --git a/src/libcore/task/local_data.rs b/src/libcore/task/local_data.rs index eda76518001..2130354229a 100644 --- a/src/libcore/task/local_data.rs +++ b/src/libcore/task/local_data.rs @@ -37,7 +37,7 @@ use local_data_priv::{ * * These two cases aside, the interface is safe. */ -pub type LocalDataKey = &fn(+v: @T); +pub type LocalDataKey = &fn(v: @T); /** * Remove a task-local data value from the table, returning the @@ -62,7 +62,7 @@ pub unsafe fn local_data_get( * that value is overwritten (and its destructor is run). */ pub unsafe fn local_data_set( - key: LocalDataKey, +data: @T) { + key: LocalDataKey, data: @T) { local_set(rt::rust_get_task(), key, data) } @@ -79,7 +79,7 @@ pub unsafe fn local_data_modify( #[test] pub fn test_tls_multitask() unsafe { - fn my_key(+_x: @~str) { } + fn my_key(_x: @~str) { } local_data_set(my_key, @~"parent data"); do task::spawn unsafe { assert local_data_get(my_key).is_none(); // TLS shouldn't carry over. @@ -95,7 +95,7 @@ pub fn test_tls_multitask() unsafe { #[test] pub fn test_tls_overwrite() unsafe { - fn my_key(+_x: @~str) { } + fn my_key(_x: @~str) { } local_data_set(my_key, @~"first data"); local_data_set(my_key, @~"next data"); // Shouldn't leak. assert *(local_data_get(my_key).get()) == ~"next data"; @@ -103,7 +103,7 @@ pub fn test_tls_overwrite() unsafe { #[test] pub fn test_tls_pop() unsafe { - fn my_key(+_x: @~str) { } + fn my_key(_x: @~str) { } local_data_set(my_key, @~"weasel"); assert *(local_data_pop(my_key).get()) == ~"weasel"; // Pop must remove the data from the map. @@ -112,7 +112,7 @@ pub fn test_tls_pop() unsafe { #[test] pub fn test_tls_modify() unsafe { - fn my_key(+_x: @~str) { } + fn my_key(_x: @~str) { } local_data_modify(my_key, |data| { match data { Some(@ref val) => fail ~"unwelcome value: " + *val, @@ -136,7 +136,7 @@ pub fn test_tls_crust_automorestack_memorial_bug() unsafe { // jump over to the rust stack, which causes next_c_sp to get recorded as // Something within a rust stack segment. Then a subsequent upcall (esp. // for logging, think vsnprintf) would run on a stack smaller than 1 MB. - fn my_key(+_x: @~str) { } + fn my_key(_x: @~str) { } do task::spawn { unsafe { local_data_set(my_key, @~"hax"); } } @@ -144,9 +144,9 @@ pub fn test_tls_crust_automorestack_memorial_bug() unsafe { #[test] pub fn test_tls_multiple_types() unsafe { - fn str_key(+_x: @~str) { } - fn box_key(+_x: @@()) { } - fn int_key(+_x: @int) { } + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } do task::spawn unsafe { local_data_set(str_key, @~"string data"); local_data_set(box_key, @@()); @@ -156,9 +156,9 @@ pub fn test_tls_multiple_types() unsafe { #[test] pub fn test_tls_overwrite_multiple_types() { - fn str_key(+_x: @~str) { } - fn box_key(+_x: @@()) { } - fn int_key(+_x: @int) { } + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } do task::spawn unsafe { local_data_set(str_key, @~"string data"); local_data_set(int_key, @42); @@ -172,9 +172,9 @@ pub fn test_tls_overwrite_multiple_types() { #[should_fail] #[ignore(cfg(windows))] pub fn test_tls_cleanup_on_failure() unsafe { - fn str_key(+_x: @~str) { } - fn box_key(+_x: @@()) { } - fn int_key(+_x: @int) { } + fn str_key(_x: @~str) { } + fn box_key(_x: @@()) { } + fn int_key(_x: @int) { } local_data_set(str_key, @~"parent data"); local_data_set(box_key, @@()); do task::spawn unsafe { // spawn_linked diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 0d3007286c5..499dd073060 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -117,7 +117,7 @@ unsafe fn local_get( } unsafe fn local_set( - task: *rust_task, key: LocalDataKey, +data: @T) { + task: *rust_task, key: LocalDataKey, data: @T) { let map = get_task_local_map(task); // Store key+data as *voids. Data is invisibly referenced once; key isn't. diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 982679f9398..786255fe7fa 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -82,7 +82,7 @@ fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { let was_present = tasks.remove(&task); assert was_present; } -fn taskset_each(tasks: &TaskSet, blk: fn(+v: *rust_task) -> bool) { +fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { tasks.each_key(|k| blk(*k)) } @@ -303,8 +303,8 @@ struct TCB { } } -fn TCB(me: *rust_task, +tasks: TaskGroupArc, +ancestors: AncestorList, - is_main: bool, +notifier: Option) -> TCB { +fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, + is_main: bool, notifier: Option) -> TCB { let notifier = move notifier; notifier.iter(|x| { x.failed = false; }); @@ -327,7 +327,7 @@ struct AutoNotify { } } -fn AutoNotify(+chan: Chan) -> AutoNotify { +fn AutoNotify(chan: Chan) -> AutoNotify { AutoNotify { notify_chan: chan, failed: true // Un-set above when taskgroup successfully made. @@ -377,13 +377,13 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // see 'None' if Somebody already failed and we got a kill signal.) if newstate.is_some() { let group = option::unwrap(move newstate); - for taskset_each(&group.members) |+sibling| { + for taskset_each(&group.members) |sibling| { // Skip self - killing ourself won't do much good. if sibling != me { rt::rust_task_kill_other(sibling); } } - for taskset_each(&group.descendants) |+child| { + for taskset_each(&group.descendants) |child| { assert child != me; rt::rust_task_kill_other(child); } @@ -486,7 +486,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) } } -fn spawn_raw(+opts: TaskOpts, +f: fn~()) { +fn spawn_raw(opts: TaskOpts, +f: fn~()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); @@ -528,9 +528,9 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { // (3a) If any of those fails, it leaves all groups, and does nothing. // (3b) Otherwise it builds a task control structure and puts it in TLS, // (4) ...and runs the provided body function. - fn make_child_wrapper(child: *rust_task, +child_arc: TaskGroupArc, - +ancestors: AncestorList, is_main: bool, - +notify_chan: Option>, + fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc, + ancestors: AncestorList, is_main: bool, + notify_chan: Option>, +f: fn~()) -> fn~() { let child_data = ~mut Some((move child_arc, move ancestors)); return fn~(move notify_chan, move child_data, move f) { diff --git a/src/libcore/util.rs b/src/libcore/util.rs index 9ba8b52f5da..aa1fe14ba88 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -5,25 +5,25 @@ Miscellaneous helpers for common patterns. */ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: re-forbid deprecated modes after snapshot #[forbid(deprecated_pattern)]; use cmp::Eq; /// The identity function. #[inline(always)] -pub pure fn id(+x: T) -> T { move x } +pub pure fn id(x: T) -> T { move x } /// Ignores a value. #[inline(always)] -pub pure fn ignore(+_x: T) { } +pub pure fn ignore(_x: T) { } /// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the /// original value of `*ptr`. #[inline(always)] pub fn with( ptr: &mut T, - +new_value: T, + new_value: T, op: &fn() -> R) -> R { // NDM: if swap operator were defined somewhat differently, @@ -50,7 +50,7 @@ pub fn swap(x: &mut T, y: &mut T) { * value, without deinitialising or copying either one. */ #[inline(always)] -pub fn replace(dest: &mut T, +src: T) -> T { +pub fn replace(dest: &mut T, src: T) -> T { let mut tmp <- src; swap(dest, &mut tmp); move tmp diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ce82215a87c..0c822bd0a03 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -47,7 +47,7 @@ pub pure fn same_length(xs: &[const T], ys: &[const U]) -> bool { * * v - A vector * * n - The number of elements to reserve space for */ -pub fn reserve(+v: &mut ~[T], +n: uint) { +pub fn reserve(v: &mut ~[T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(v) < n { unsafe { @@ -119,7 +119,7 @@ pub pure fn from_fn(n_elts: uint, op: iter::InitOp) -> ~[T] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value `t`. */ -pub pure fn from_elem(n_elts: uint, +t: T) -> ~[T] { +pub pure fn from_elem(n_elts: uint, t: T) -> ~[T] { from_fn(n_elts, |_i| copy t) } @@ -148,9 +148,9 @@ pub pure fn with_capacity(capacity: uint) -> ~[T] { */ #[inline(always)] pub pure fn build_sized(size: uint, - builder: fn(push: pure fn(+v: A))) -> ~[A] { + builder: fn(push: pure fn(v: A))) -> ~[A] { let mut vec = with_capacity(size); - builder(|+x| unsafe { vec.push(move x) }); + builder(|x| unsafe { vec.push(move x) }); move vec } @@ -165,7 +165,7 @@ pub pure fn build_sized(size: uint, * onto the vector being constructed. */ #[inline(always)] -pub pure fn build(builder: fn(push: pure fn(+v: A))) -> ~[A] { +pub pure fn build(builder: fn(push: pure fn(v: A))) -> ~[A] { build_sized(4, builder) } @@ -183,17 +183,17 @@ pub pure fn build(builder: fn(push: pure fn(+v: A))) -> ~[A] { */ #[inline(always)] pub pure fn build_sized_opt(size: Option, - builder: fn(push: pure fn(+v: A))) -> ~[A] { + builder: fn(push: pure fn(v: A))) -> ~[A] { build_sized(size.get_default(4), builder) } /// Produces a mut vector from an immutable vector. -pub pure fn to_mut(+v: ~[T]) -> ~[mut T] { +pub pure fn to_mut(v: ~[T]) -> ~[mut T] { unsafe { ::cast::transmute(move v) } } /// Produces an immutable vector from a mut vector. -pub pure fn from_mut(+v: ~[mut T]) -> ~[T] { +pub pure fn from_mut(v: ~[mut T]) -> ~[T] { unsafe { ::cast::transmute(move v) } } @@ -412,13 +412,13 @@ pub fn shift(v: &mut ~[T]) -> T { } /// Prepend an element to the vector -pub fn unshift(v: &mut ~[T], +x: T) { +pub fn unshift(v: &mut ~[T], x: T) { let mut vv = ~[move x]; *v <-> vv; v.push_all_move(vv); } -pub fn consume(+v: ~[T], f: fn(uint, +v: T)) unsafe { +pub fn consume(v: ~[T], f: fn(uint, v: T)) unsafe { let mut v = move v; // FIXME(#3488) do as_imm_buf(v) |p, ln| { @@ -431,7 +431,7 @@ pub fn consume(+v: ~[T], f: fn(uint, +v: T)) unsafe { raw::set_len(&mut v, 0); } -pub fn consume_mut(+v: ~[mut T], f: fn(uint, +v: T)) { +pub fn consume_mut(v: ~[mut T], f: fn(uint, v: T)) { consume(vec::from_mut(v), f) } @@ -468,7 +468,7 @@ pub fn swap_remove(v: &mut ~[T], index: uint) -> T { /// Append an element to a vector #[inline(always)] -pub fn push(v: &mut ~[T], +initval: T) { +pub fn push(v: &mut ~[T], initval: T) { unsafe { let repr: **raw::VecRepr = ::cast::transmute(copy v); let fill = (**repr).unboxed.fill; @@ -483,7 +483,7 @@ pub fn push(v: &mut ~[T], +initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please -unsafe fn push_fast(+v: &mut ~[T], +initval: T) { +unsafe fn push_fast(v: &mut ~[T], initval: T) { let repr: **raw::VecRepr = ::cast::transmute(v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); @@ -493,13 +493,13 @@ unsafe fn push_fast(+v: &mut ~[T], +initval: T) { } #[inline(never)] -fn push_slow(+v: &mut ~[T], +initval: T) { +fn push_slow(v: &mut ~[T], initval: T) { reserve_at_least(v, v.len() + 1u); unsafe { push_fast(v, move initval) } } #[inline(always)] -pub fn push_all(+v: &mut ~[T], rhs: &[const T]) { +pub fn push_all(v: &mut ~[T], rhs: &[const T]) { reserve(v, v.len() + rhs.len()); for uint::range(0u, rhs.len()) |i| { @@ -508,7 +508,7 @@ pub fn push_all(+v: &mut ~[T], rhs: &[const T]) { } #[inline(always)] -pub fn push_all_move(v: &mut ~[T], +rhs: ~[T]) { +pub fn push_all_move(v: &mut ~[T], rhs: ~[T]) { let mut rhs = move rhs; // FIXME(#3488) reserve(v, v.len() + rhs.len()); unsafe { @@ -573,7 +573,7 @@ pub fn dedup(v: &mut ~[T]) unsafe { // Appending #[inline(always)] -pub pure fn append(+lhs: ~[T], rhs: &[const T]) -> ~[T] { +pub pure fn append(lhs: ~[T], rhs: &[const T]) -> ~[T] { let mut v <- lhs; unsafe { v.push_all(rhs); @@ -582,14 +582,14 @@ pub pure fn append(+lhs: ~[T], rhs: &[const T]) -> ~[T] { } #[inline(always)] -pub pure fn append_one(+lhs: ~[T], +x: T) -> ~[T] { +pub pure fn append_one(lhs: ~[T], x: T) -> ~[T] { let mut v <- lhs; unsafe { v.push(move x); } move v } #[inline(always)] -pure fn append_mut(+lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] { +pure fn append_mut(lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] { to_mut(append(from_mut(lhs), rhs)) } @@ -642,7 +642,7 @@ pub fn grow_fn(v: &mut ~[T], n: uint, op: iter::InitOp) { * of the vector, expands the vector by replicating `initval` to fill the * intervening space. */ -pub fn grow_set(v: &mut ~[T], index: uint, initval: &T, +val: T) { +pub fn grow_set(v: &mut ~[T], index: uint, initval: &T, val: T) { let l = v.len(); if index >= l { grow(v, index - l + 1u, initval); } v[index] = move val; @@ -661,7 +661,7 @@ pub pure fn map(v: &[T], f: fn(t: &T) -> U) -> ~[U] { move result } -pub fn map_consume(+v: ~[T], f: fn(+v: T) -> U) -> ~[U] { +pub fn map_consume(v: ~[T], f: fn(v: T) -> U) -> ~[U] { let mut result = ~[]; do consume(move v) |_i, x| { result.push(f(move x)); @@ -758,7 +758,7 @@ pub pure fn connect(v: &[~[T]], sep: &T) -> ~[T] { } /// Reduce a vector from left to right -pub pure fn foldl(+z: T, v: &[U], p: fn(+t: T, u: &U) -> T) -> T { +pub pure fn foldl(z: T, v: &[U], p: fn(t: T, u: &U) -> T) -> T { let mut accum = z; for each(v) |elt| { // it should be possible to move accum in, but the liveness analysis @@ -769,7 +769,7 @@ pub pure fn foldl(+z: T, v: &[U], p: fn(+t: T, u: &U) -> T) -> T { } /// Reduce a vector from right to left -pub pure fn foldr(v: &[T], +z: U, p: fn(t: &T, +u: U) -> U) -> U { +pub pure fn foldr(v: &[T], z: U, p: fn(t: &T, u: U) -> U) -> U { let mut accum = z; for rev_each(v) |elt| { accum = p(elt, accum); @@ -992,7 +992,7 @@ pure fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { * and the i-th element of the second vector contains the second element * of the i-th tuple of the input vector. */ -pub pure fn unzip(+v: ~[(T, U)]) -> (~[T], ~[U]) { +pub pure fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { let mut ts = ~[], us = ~[]; unsafe { do consume(move v) |_i, p| { @@ -1023,7 +1023,7 @@ pub pure fn zip_slice(v: &[const T], u: &[const U]) * Returns a vector of tuples, where the i-th tuple contains contains the * i-th elements from each of the input vectors. */ -pub pure fn zip(+v: ~[T], +u: ~[U]) -> ~[(T, U)] { +pub pure fn zip(v: ~[T], u: ~[U]) -> ~[(T, U)] { let mut v = move v, u = move u; // FIXME(#3488) let mut i = len(v); assert i == len(u); @@ -1190,7 +1190,7 @@ pub fn each2(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) { * The total number of permutations produced is `len(v)!`. If `v` contains * repeated elements, then some permutations are repeated. */ -pure fn each_permutation(+v: &[T], put: fn(ts: &[T]) -> bool) { +pure fn each_permutation(v: &[T], put: fn(ts: &[T]) -> bool) { let ln = len(v); if ln <= 1 { put(v); @@ -1435,7 +1435,7 @@ impl &[const T]: CopyableVector { pub trait ImmutableVector { pure fn view(start: uint, end: uint) -> &self/[T]; - pure fn foldr(+z: U, p: fn(t: &T, +u: U) -> U) -> U; + pure fn foldr(z: U, p: fn(t: &T, u: U) -> U) -> U; pure fn map(f: fn(t: &T) -> U) -> ~[U]; pure fn mapi(f: fn(uint, t: &T) -> U) -> ~[U]; fn map_r(f: fn(x: &T) -> U) -> ~[U]; @@ -1459,7 +1459,7 @@ impl &[T]: ImmutableVector { } /// Reduce a vector from right to left #[inline] - pure fn foldr(+z: U, p: fn(t: &T, +u: U) -> U) -> U { + pure fn foldr(z: U, p: fn(t: &T, u: U) -> U) -> U { foldr(self, z, p) } /// Apply a function to each element of a vector and return the results @@ -1582,11 +1582,11 @@ impl &[T]: ImmutableCopyableVector { } pub trait MutableVector { - fn push(&mut self, +t: T); - fn push_all_move(&mut self, +rhs: ~[T]); + fn push(&mut self, t: T); + fn push_all_move(&mut self, rhs: ~[T]); fn pop(&mut self) -> T; fn shift(&mut self) -> T; - fn unshift(&mut self, +x: T); + fn unshift(&mut self, x: T); fn swap_remove(&mut self, index: uint) -> T; fn truncate(&mut self, newlen: uint); } @@ -1595,7 +1595,7 @@ pub trait MutableCopyableVector { fn push_all(&mut self, rhs: &[const T]); fn grow(&mut self, n: uint, initval: &T); fn grow_fn(&mut self, n: uint, op: iter::InitOp); - fn grow_set(&mut self, index: uint, initval: &T, +val: T); + fn grow_set(&mut self, index: uint, initval: &T, val: T); } trait MutableEqVector { @@ -1603,11 +1603,11 @@ trait MutableEqVector { } impl ~[T]: MutableVector { - fn push(&mut self, +t: T) { + fn push(&mut self, t: T) { push(self, move t); } - fn push_all_move(&mut self, +rhs: ~[T]) { + fn push_all_move(&mut self, rhs: ~[T]) { push_all_move(self, move rhs); } @@ -1619,7 +1619,7 @@ impl ~[T]: MutableVector { shift(self) } - fn unshift(&mut self, +x: T) { + fn unshift(&mut self, x: T) { unshift(self, x) } @@ -1645,7 +1645,7 @@ impl ~[T]: MutableCopyableVector { grow_fn(self, n, op); } - fn grow_set(&mut self, index: uint, initval: &T, +val: T) { + fn grow_set(&mut self, index: uint, initval: &T, val: T) { grow_set(self, index, initval, val); } } @@ -1717,21 +1717,21 @@ pub mod raw { * would also make any pointers to it invalid. */ #[inline(always)] - pub unsafe fn to_ptr(+v: &[T]) -> *T { + pub unsafe fn to_ptr(v: &[T]) -> *T { let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of(&((**repr).data))); } /** see `to_ptr()` */ #[inline(always)] - pub unsafe fn to_const_ptr(+v: &[const T]) -> *const T { + pub unsafe fn to_const_ptr(v: &[const T]) -> *const T { let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of(&((**repr).data))); } /** see `to_ptr()` */ #[inline(always)] - pub unsafe fn to_mut_ptr(+v: &[mut T]) -> *mut T { + pub unsafe fn to_mut_ptr(v: &[mut T]) -> *mut T { let repr: **SliceRepr = ::cast::transmute(&v); return ::cast::reinterpret_cast(&addr_of(&((**repr).data))); } @@ -1764,7 +1764,7 @@ pub mod raw { * is newly allocated. */ #[inline(always)] - pub unsafe fn init_elem(v: &[mut T], i: uint, +val: T) { + pub unsafe fn init_elem(v: &[mut T], i: uint, val: T) { let mut box = Some(move val); do as_mut_buf(v) |p, _len| { let mut box2 = None; @@ -1896,7 +1896,7 @@ impl &[A]: iter::ExtendedIter { } pub pure fn all(blk: fn(&A) -> bool) -> bool { iter::all(&self, blk) } pub pure fn any(blk: fn(&A) -> bool) -> bool { iter::any(&self, blk) } - pub pure fn foldl(+b0: B, blk: fn(&B, &A) -> B) -> B { + pub pure fn foldl(b0: B, blk: fn(&B, &A) -> B) -> B { iter::foldl(&self, move b0, blk) } pub pure fn position(f: fn(&A) -> bool) -> Option { @@ -1910,10 +1910,10 @@ impl &[A]: iter::EqIter { } impl &[A]: iter::CopyableIter { - pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A] { + pure fn filter_to_vec(pred: fn(a: A) -> bool) -> ~[A] { iter::filter_to_vec(&self, pred) } - pure fn map_to_vec(op: fn(+v: A) -> B) -> ~[B] { + pure fn map_to_vec(op: fn(v: A) -> B) -> ~[B] { iter::map_to_vec(&self, op) } pure fn to_vec() -> ~[A] { iter::to_vec(&self) } @@ -1923,7 +1923,7 @@ impl &[A]: iter::CopyableIter { // iter::flat_map_to_vec(self, op) // } - pub pure fn find(p: fn(+a: A) -> bool) -> Option { + pub pure fn find(p: fn(a: A) -> bool) -> Option { iter::find(&self, p) } } @@ -1951,7 +1951,7 @@ mod tests { return if *n % 2u == 1u { Some(*n * *n) } else { None }; } - fn add(+x: uint, y: &uint) -> uint { return x + *y; } + fn add(x: uint, y: &uint) -> uint { return x + *y; } #[test] fn test_unsafe_ptrs() { @@ -2193,7 +2193,7 @@ mod tests { #[test] fn test_dedup() { - fn case(+a: ~[uint], +b: ~[uint]) { + fn case(a: ~[uint], b: ~[uint]) { let mut v = a; v.dedup(); assert(v == b); @@ -2323,7 +2323,7 @@ mod tests { #[test] fn test_foldl2() { - fn sub(+a: int, b: &int) -> int { + fn sub(a: int, b: &int) -> int { a - *b } let mut v = ~[1, 2, 3, 4]; @@ -2333,7 +2333,7 @@ mod tests { #[test] fn test_foldr() { - fn sub(a: &int, +b: int) -> int { + fn sub(a: &int, b: int) -> int { *a - b } let mut v = ~[1, 2, 3, 4]; diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index a04eadb7732..67bbff7fb6a 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -232,7 +232,7 @@ type Result = result::Result; */ fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { let n_opts = vec::len::(opts); - fn f(_x: uint) -> ~[Optval] { return ~[]; } + fn f(+_x: uint) -> ~[Optval] { return ~[]; } let vals = vec::to_mut(vec::from_fn(n_opts, f)); let mut free: ~[~str] = ~[]; let l = vec::len(args); diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index aedd53d41cc..59cb0d36f77 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -763,7 +763,7 @@ impl TcpSocket { /// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket` impl TcpSocketBuf: io::Reader { - fn read(buf: &[mut u8], len: uint) -> uint { + fn read(buf: &[mut u8], +len: uint) -> uint { // Loop until our buffer has enough data in it for us to read from. while self.data.buf.len() < len { let read_result = read(&self.data.sock, 0u); @@ -799,13 +799,13 @@ impl TcpSocketBuf: io::Reader { let mut bytes = ~[0]; if self.read(bytes, 1u) == 0 { fail } else { bytes[0] as int } } - fn unread_byte(amt: int) { + fn unread_byte(+amt: int) { self.data.buf.unshift(amt as u8); } fn eof() -> bool { false // noop } - fn seek(dist: int, seek: io::SeekStyle) { + fn seek(+dist: int, +seek: io::SeekStyle) { log(debug, fmt!("tcp_socket_buf seek stub %? %?", dist, seek)); // noop } @@ -827,7 +827,7 @@ impl TcpSocketBuf: io::Writer { err_data.err_name, err_data.err_msg)); } } - fn seek(dist: int, seek: io::SeekStyle) { + fn seek(+dist: int, +seek: io::SeekStyle) { log(debug, fmt!("tcp_socket_buf seek stub %? %?", dist, seek)); // noop } diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 00226c4e81e..920751d690f 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -735,7 +735,7 @@ impl Url : Eq { } impl Url: IterBytes { - pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { + pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) { unsafe { self.to_str() }.iter_bytes(lsb0, f) } } diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 647560099e9..d14a4854555 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -379,7 +379,7 @@ Section: Iterating * `true` If execution proceeded correctly, `false` if it was interrupted, * that is if `it` returned `false` at any point. */ -pub fn loop_chars(rope: Rope, it: fn(char) -> bool) -> bool { +pub fn loop_chars(rope: Rope, it: fn(+c: char) -> bool) -> bool { match (rope) { node::Empty => return true, node::Content(x) => return node::loop_chars(x, it) @@ -1037,7 +1037,7 @@ mod node { return result; } - pub fn loop_chars(node: @Node, it: fn(char) -> bool) -> bool { + pub fn loop_chars(node: @Node, it: fn(+c: char) -> bool) -> bool { return loop_leaves(node,|leaf| { str::all_between(*leaf.content, leaf.byte_offset, diff --git a/src/libstd/std.rc b/src/libstd/std.rc index aa26c4af29c..95af018e35a 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -18,6 +18,9 @@ not required in or otherwise suitable for the core library. #[no_core]; +// tjc: Added legacy_modes back in because it still uses + mode. +// Remove once + mode gets expunged from std. +#[legacy_modes]; #[legacy_exports]; #[allow(vecs_implicitly_copyable)]; diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs index ebdc66156e3..0f31f2056a1 100644 --- a/src/rustc/middle/lint.rs +++ b/src/rustc/middle/lint.rs @@ -683,8 +683,12 @@ fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl, mode_to_str(arg_ast.mode)); match arg_ast.mode { ast::expl(ast::by_copy) => { - // This should warn, but we can't yet - // since it's still used. -- tjc + if !tcx.legacy_modes { + tcx.sess.span_lint( + deprecated_mode, id, id, span, + fmt!("argument %d uses by-copy mode", + counter)); + } } ast::expl(_) => { diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index a34fcc89c04..f35a3ce735f 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -251,7 +251,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { colors = do par::mapi_factory(*color_vec) { let colors = arc::clone(&color); let graph = arc::clone(&graph); - fn~(+i: uint, +c: color) -> color { + fn~(i: uint, c: color) -> color { let c : color = c; let colors = arc::get(&colors); let graph = arc::get(&graph); -- cgit 1.4.1-3-g733a5 From c31a88c7f4fddb217c022ac214c0a49501d9ded3 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 2 Oct 2012 16:31:52 -0700 Subject: De-export the submodules of task. Part of #3583. --- src/libcore/core.rc | 12 ++------ src/libcore/rt.rs | 15 +++++----- src/libcore/task/local_data_priv.rs | 24 ++++++++-------- src/libcore/task/rt.rs | 8 +++--- src/libcore/task/spawn.rs | 55 +++++++++++++++++++------------------ src/test/run-pass/issue-783.rs | 2 +- 6 files changed, 55 insertions(+), 61 deletions(-) (limited to 'src/test') diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 6cada58fa02..818e1e890ec 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -216,17 +216,11 @@ mod send_map; // Concurrency mod comm; -#[legacy_exports] mod task { - #[legacy_exports]; - #[legacy_exports] - mod local_data; - #[legacy_exports] + pub mod local_data; mod local_data_priv; - #[legacy_exports] - mod spawn; - #[legacy_exports] - mod rt; + pub mod spawn; + pub mod rt; } mod future; mod pipes; diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs index da598fc3e7f..9bc83a5f904 100644 --- a/src/libcore/rt.rs +++ b/src/libcore/rt.rs @@ -11,10 +11,9 @@ use libc::uintptr_t; use gc::{cleanup_stack_for_failure, gc, Word}; #[allow(non_camel_case_types)] -type rust_task = c_void; +pub type rust_task = c_void; extern mod rustrt { - #[legacy_exports]; #[rust_stack] fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t); @@ -35,13 +34,13 @@ extern mod rustrt { // 'rt_', otherwise the compiler won't find it. To fix this, see // gather_rust_rtcalls. #[rt(fail_)] -fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) { +pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) { cleanup_stack_for_failure(); rustrt::rust_upcall_fail(expr, file, line); } #[rt(fail_bounds_check)] -fn rt_fail_bounds_check(file: *c_char, line: size_t, +pub fn rt_fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t) { let msg = fmt!("index out of bounds: the len is %d but the index is %d", len as int, index as int); @@ -51,7 +50,7 @@ fn rt_fail_bounds_check(file: *c_char, line: size_t, } #[rt(exchange_malloc)] -fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { +pub fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_exchange_malloc(td, size); } @@ -59,12 +58,12 @@ fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. #[rt(exchange_free)] -fn rt_exchange_free(ptr: *c_char) { +pub fn rt_exchange_free(ptr: *c_char) { rustrt::rust_upcall_exchange_free(ptr); } #[rt(malloc)] -fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { +pub fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_malloc(td, size); } @@ -72,7 +71,7 @@ fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char { // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. #[rt(free)] -fn rt_free(ptr: *c_char) { +pub fn rt_free(ptr: *c_char) { rustrt::rust_upcall_free(ptr); } diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 499dd073060..9849ce7b68c 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -3,7 +3,7 @@ use local_data::LocalDataKey; use rt::rust_task; -trait LocalData { } +pub trait LocalData { } impl @T: LocalData { } impl LocalData: Eq { @@ -17,11 +17,11 @@ impl LocalData: Eq { // We use dvec because it's the best data structure in core. If TLS is used // heavily in future, this could be made more efficient with a proper map. -type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); +pub type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); // Has to be a pointer at outermost layer; the foreign call returns void *. -type TaskLocalMap = @dvec::DVec>; +pub type TaskLocalMap = @dvec::DVec>; -extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { +pub extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); // Get and keep the single reference that was created at the beginning. let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr); @@ -29,7 +29,7 @@ extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { } // Gets the map from the runtime. Lazily initialises if not done so already. -unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { +pub unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { // Relies on the runtime initialising the pointer to null. // NOTE: The map's box lives in TLS invisibly referenced once. Each time @@ -52,7 +52,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { } } -unsafe fn key_to_key_value( +pub unsafe fn key_to_key_value( key: LocalDataKey) -> *libc::c_void { // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. @@ -62,7 +62,7 @@ unsafe fn key_to_key_value( } // If returning Some(..), returns with @T with the map's reference. Careful! -unsafe fn local_data_lookup( +pub unsafe fn local_data_lookup( map: TaskLocalMap, key: LocalDataKey) -> Option<(uint, *libc::c_void)> { @@ -80,7 +80,7 @@ unsafe fn local_data_lookup( } } -unsafe fn local_get_helper( +pub unsafe fn local_get_helper( task: *rust_task, key: LocalDataKey, do_pop: bool) -> Option<@T> { @@ -102,21 +102,21 @@ unsafe fn local_get_helper( } -unsafe fn local_pop( +pub unsafe fn local_pop( task: *rust_task, key: LocalDataKey) -> Option<@T> { local_get_helper(task, key, true) } -unsafe fn local_get( +pub unsafe fn local_get( task: *rust_task, key: LocalDataKey) -> Option<@T> { local_get_helper(task, key, false) } -unsafe fn local_set( +pub unsafe fn local_set( task: *rust_task, key: LocalDataKey, data: @T) { let map = get_task_local_map(task); @@ -148,7 +148,7 @@ unsafe fn local_set( } } -unsafe fn local_modify( +pub unsafe fn local_modify( task: *rust_task, key: LocalDataKey, modify_fn: fn(Option<@T>) -> Option<@T>) { diff --git a/src/libcore/task/rt.rs b/src/libcore/task/rt.rs index b1f7b99bd07..db3d1ec9f70 100644 --- a/src/libcore/task/rt.rs +++ b/src/libcore/task/rt.rs @@ -7,16 +7,16 @@ The task interface to the runtime #[doc(hidden)]; // FIXME #3538 #[allow(non_camel_case_types)] // runtime type -type sched_id = int; +pub type sched_id = int; #[allow(non_camel_case_types)] // runtime type -type task_id = int; +pub type task_id = int; // These are both opaque runtime/compiler types that we don't know the // structure of and should only deal with via unsafe pointer #[allow(non_camel_case_types)] // runtime type -type rust_task = libc::c_void; +pub type rust_task = libc::c_void; #[allow(non_camel_case_types)] // runtime type -type rust_closure = libc::c_void; +pub type rust_closure = libc::c_void; extern { #[rust_stack] diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 786255fe7fa..0e1284da3bc 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -69,25 +69,25 @@ macro_rules! move_it ( { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } } ) -type TaskSet = send_map::linear::LinearMap<*rust_task,()>; +pub type TaskSet = send_map::linear::LinearMap<*rust_task,()>; -fn new_taskset() -> TaskSet { +pub fn new_taskset() -> TaskSet { send_map::linear::LinearMap() } -fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { +pub fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { let didnt_overwrite = tasks.insert(task, ()); assert didnt_overwrite; } -fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { +pub fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { let was_present = tasks.remove(&task); assert was_present; } -fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { +pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { tasks.each_key(|k| blk(*k)) } // One of these per group of linked-failure tasks. -type TaskGroupData = { +pub type TaskGroupData = { // All tasks which might kill this group. When this is empty, the group // can be "GC"ed (i.e., its link in the ancestor list can be removed). mut members: TaskSet, @@ -95,12 +95,12 @@ type TaskGroupData = { // tasks in this group. mut descendants: TaskSet, }; -type TaskGroupArc = private::Exclusive>; +pub type TaskGroupArc = private::Exclusive>; -type TaskGroupInner = &mut Option; +pub type TaskGroupInner = &mut Option; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. -pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { +pub pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { (&tg.members).is_empty() } @@ -111,7 +111,7 @@ pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { // taskgroup which was spawned-unlinked. Tasks from intermediate generations // have references to the middle of the list; when intermediate generations // die, their node in the list will be collected at a descendant's spawn-time. -type AncestorNode = { +pub type AncestorNode = { // Since the ancestor list is recursive, we end up with references to // exclusives within other exclusives. This is dangerous business (if // circular references arise, deadlock and memory leaks are imminent). @@ -124,16 +124,16 @@ type AncestorNode = { // Recursive rest of the list. mut ancestors: AncestorList, }; -enum AncestorList = Option>; +pub enum AncestorList = Option>; // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline(always)] -fn access_group(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { +pub fn access_group(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { unsafe { x.with(blk) } } #[inline(always)] -fn access_ancestors(x: &private::Exclusive, +pub fn access_ancestors(x: &private::Exclusive, blk: fn(x: &mut AncestorNode) -> U) -> U { unsafe { x.with(blk) } } @@ -146,9 +146,9 @@ fn access_ancestors(x: &private::Exclusive, // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. // FIXME(#2190): Change Option to Option, to save on // allocations. Once that bug is fixed, changing the sigil should suffice. -fn each_ancestor(list: &mut AncestorList, - bail_opt: Option, - forward_blk: fn(TaskGroupInner) -> bool) +pub fn each_ancestor(list: &mut AncestorList, + bail_opt: Option, + forward_blk: fn(TaskGroupInner) -> bool) -> bool { // "Kickoff" call - there was no last generation. return !coalesce(list, bail_opt, forward_blk, uint::max_value); @@ -271,7 +271,7 @@ fn each_ancestor(list: &mut AncestorList, } // One of these per task. -struct TCB { +pub struct TCB { me: *rust_task, // List of tasks with whose fates this one's is intertwined. tasks: TaskGroupArc, // 'none' means the group has failed. @@ -303,7 +303,7 @@ struct TCB { } } -fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, +pub fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, is_main: bool, notifier: Option) -> TCB { let notifier = move notifier; @@ -318,7 +318,7 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, } } -struct AutoNotify { +pub struct AutoNotify { notify_chan: Chan, mut failed: bool, drop { @@ -327,15 +327,15 @@ struct AutoNotify { } } -fn AutoNotify(chan: Chan) -> AutoNotify { +pub fn AutoNotify(chan: Chan) -> AutoNotify { AutoNotify { notify_chan: chan, failed: true // Un-set above when taskgroup successfully made. } } -fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, - is_member: bool) -> bool { +pub fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, + is_member: bool) -> bool { let newstate = util::replace(state, None); // If 'None', the group was failing. Can't enlist. if newstate.is_some() { @@ -350,7 +350,8 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, } // NB: Runs in destructor/post-exit context. Can't 'fail'. -fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { +pub fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, + is_member: bool) { let newstate = util::replace(state, None); // If 'None', already failing and we've already gotten a kill signal. if newstate.is_some() { @@ -362,7 +363,7 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { } // NB: Runs in destructor/post-exit context. Can't 'fail'. -fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { +pub fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // NB: We could do the killing iteration outside of the group arc, by // having "let mut newstate" here, swapping inside, and iterating after. // But that would let other exiting tasks fall-through and exit while we @@ -404,8 +405,8 @@ macro_rules! taskgroup_key ( () => (cast::transmute((-2 as uint, 0u))) ) -fn gen_child_taskgroup(linked: bool, supervised: bool) - -> (TaskGroupArc, AncestorList, bool) { +pub fn gen_child_taskgroup(linked: bool, supervised: bool) + -> (TaskGroupArc, AncestorList, bool) { let spawner = rt::rust_get_task(); /*######################################################################* * Step 1. Get spawner's taskgroup info. @@ -486,7 +487,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) } } -fn spawn_raw(opts: TaskOpts, +f: fn~()) { +pub fn spawn_raw(opts: TaskOpts, +f: fn~()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); diff --git a/src/test/run-pass/issue-783.rs b/src/test/run-pass/issue-783.rs index 752101e651b..a9c6fed8eca 100644 --- a/src/test/run-pass/issue-783.rs +++ b/src/test/run-pass/issue-783.rs @@ -1,6 +1,6 @@ extern mod std; use comm::*; -use task::*; +use task::spawn; fn a() { fn doit() { -- cgit 1.4.1-3-g733a5 From f33539e446d6f41d4a3296ed50a8f968e7950483 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 3 Oct 2012 12:21:48 -0700 Subject: Remove uses of + mode from libstd More or less the same as my analogous commit for libcore. Had to remove the forbid(deprecated_modes) pragma from some files -- will restore it after the snapshot. --- src/libstd/arc.rs | 22 +++++++++--------- src/libstd/bitv.rs | 4 ++-- src/libstd/cell.rs | 6 ++--- src/libstd/dbg.rs | 8 +++---- src/libstd/deque.rs | 14 ++++++------ src/libstd/getopts.rs | 25 ++++++++++---------- src/libstd/json.rs | 4 ++-- src/libstd/list.rs | 2 +- src/libstd/map.rs | 52 +++++++++++++++++++++--------------------- src/libstd/net_tcp.rs | 14 ++++++------ src/libstd/net_url.rs | 12 +++++----- src/libstd/rope.rs | 4 ++-- src/libstd/smallintmap.rs | 20 ++++++++-------- src/libstd/std.rc | 3 --- src/libstd/sync.rs | 14 ++++++------ src/libstd/test.rs | 4 ++-- src/libstd/time.rs | 4 ++-- src/libstd/timer.rs | 4 ++-- src/libstd/uv_iotask.rs | 4 ++-- src/libstd/uv_ll.rs | 6 ++--- src/test/bench/graph500-bfs.rs | 2 +- 21 files changed, 113 insertions(+), 115 deletions(-) (limited to 'src/test') diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 9d15deab660..60db62ce01a 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap /** * Concurrency-enabled mechanisms for sharing mutable and/or immutable state * between tasks. @@ -66,7 +66,7 @@ impl &Condvar { struct ARC { x: SharedMutableState } /// Create an atomically reference counted wrapper. -pub fn ARC(+data: T) -> ARC { +pub fn ARC(data: T) -> ARC { ARC { x: unsafe { shared_mutable_state(move data) } } } @@ -98,7 +98,7 @@ pub fn clone(rc: &ARC) -> ARC { * unwrap from a task that holds another reference to the same ARC; it is * guaranteed to deadlock. */ -fn unwrap(+rc: ARC) -> T { +fn unwrap(rc: ARC) -> T { let ARC { x: x } <- rc; unsafe { unwrap_shared_mutable_state(move x) } } @@ -113,14 +113,14 @@ struct MutexARCInner { lock: Mutex, failed: bool, data: T } struct MutexARC { x: SharedMutableState> } /// Create a mutex-protected ARC with the supplied data. -pub fn MutexARC(+user_data: T) -> MutexARC { +pub fn MutexARC(user_data: T) -> MutexARC { mutex_arc_with_condvars(move user_data, 1) } /** * Create a mutex-protected ARC with the supplied data and a specified number * of condvars (as sync::mutex_with_condvars). */ -pub fn mutex_arc_with_condvars(+user_data: T, +pub fn mutex_arc_with_condvars(user_data: T, num_condvars: uint) -> MutexARC { let data = MutexARCInner { lock: mutex_with_condvars(num_condvars), @@ -191,7 +191,7 @@ impl &MutexARC { * Will additionally fail if another task has failed while accessing the arc. */ // FIXME(#2585) make this a by-move method on the arc -pub fn unwrap_mutex_arc(+arc: MutexARC) -> T { +pub fn unwrap_mutex_arc(arc: MutexARC) -> T { let MutexARC { x: x } <- arc; let inner = unsafe { unwrap_shared_mutable_state(move x) }; let MutexARCInner { failed: failed, data: data, _ } <- inner; @@ -247,14 +247,14 @@ struct RWARC { } /// Create a reader/writer ARC with the supplied data. -pub fn RWARC(+user_data: T) -> RWARC { +pub fn RWARC(user_data: T) -> RWARC { rw_arc_with_condvars(move user_data, 1) } /** * Create a reader/writer ARC with the supplied data and a specified number * of condvars (as sync::rwlock_with_condvars). */ -pub fn rw_arc_with_condvars(+user_data: T, +pub fn rw_arc_with_condvars(user_data: T, num_condvars: uint) -> RWARC { let data = RWARCInner { lock: rwlock_with_condvars(num_condvars), @@ -334,7 +334,7 @@ impl &RWARC { * } * ~~~ */ - fn write_downgrade(blk: fn(+v: RWWriteMode) -> U) -> U { + fn write_downgrade(blk: fn(v: RWWriteMode) -> U) -> U { let state = unsafe { get_shared_mutable_state(&self.x) }; do borrow_rwlock(state).write_downgrade |write_mode| { check_poison(false, state.failed); @@ -344,7 +344,7 @@ impl &RWARC { } /// To be called inside of the write_downgrade block. - fn downgrade(+token: RWWriteMode/&a) -> RWReadMode/&a { + fn downgrade(token: RWWriteMode/&a) -> RWReadMode/&a { // The rwlock should assert that the token belongs to us for us. let state = unsafe { get_shared_immutable_state(&self.x) }; let RWWriteMode((data, t, _poison)) <- token; @@ -369,7 +369,7 @@ impl &RWARC { * in write mode. */ // FIXME(#2585) make this a by-move method on the arc -pub fn unwrap_rw_arc(+arc: RWARC) -> T { +pub fn unwrap_rw_arc(arc: RWARC) -> T { let RWARC { x: x, _ } <- arc; let inner = unsafe { unwrap_shared_mutable_state(move x) }; let RWARCInner { failed: failed, data: data, _ } <- inner; diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index bb556ed2ca3..77f0d39c338 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -1,4 +1,4 @@ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap use vec::{to_mut, from_elem}; @@ -95,7 +95,7 @@ struct BigBitv { mut storage: ~[mut uint] } -fn BigBitv(+storage: ~[mut uint]) -> BigBitv { +fn BigBitv(storage: ~[mut uint]) -> BigBitv { BigBitv {storage: storage} } diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 43e47e1e1a9..866dbce1c08 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -1,4 +1,4 @@ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap /// A dynamic, mutable location. /// /// Similar to a mutable option type, but friendlier. @@ -8,7 +8,7 @@ pub struct Cell { } /// Creates a new full cell with the given value. -pub fn Cell(+value: T) -> Cell { +pub fn Cell(value: T) -> Cell { Cell { value: Some(move value) } } @@ -29,7 +29,7 @@ impl Cell { } /// Returns the value, failing if the cell is full. - fn put_back(+value: T) { + fn put_back(value: T) { if !self.is_empty() { fail ~"attempt to put a value back into a full cell"; } diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index df97df51643..f85d4655ad1 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -1,4 +1,4 @@ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap //! Unsafe debugging functions for inspecting values. use cast::reinterpret_cast; @@ -20,7 +20,7 @@ pub fn debug_tydesc() { rustrt::debug_tydesc(sys::get_type_desc::()); } -pub fn debug_opaque(+x: T) { +pub fn debug_opaque(x: T) { rustrt::debug_opaque(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } @@ -28,11 +28,11 @@ pub fn debug_box(x: @T) { rustrt::debug_box(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } -pub fn debug_tag(+x: T) { +pub fn debug_tag(x: T) { rustrt::debug_tag(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } -pub fn debug_fn(+x: T) { +pub fn debug_fn(x: T) { rustrt::debug_fn(sys::get_type_desc::(), ptr::addr_of(&x) as *()); } diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index da05174a6f5..f4fbc11c4f7 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -1,5 +1,5 @@ //! A deque. Untested as of yet. Likely buggy -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap #[forbid(non_camel_case_types)]; use option::{Some, None}; @@ -8,8 +8,8 @@ use core::cmp::{Eq}; pub trait Deque { fn size() -> uint; - fn add_front(+v: T); - fn add_back(+v: T); + fn add_front(v: T); + fn add_back(v: T); fn pop_front() -> T; fn pop_back() -> T; fn peek_front() -> T; @@ -27,7 +27,7 @@ pub fn create() -> Deque { * Grow is only called on full elts, so nelts is also len(elts), unlike * elsewhere. */ - fn grow(nelts: uint, lo: uint, +elts: ~[Cell]) + fn grow(nelts: uint, lo: uint, elts: ~[Cell]) -> ~[Cell] { let mut elts = move elts; assert (nelts == vec::len(elts)); @@ -55,7 +55,7 @@ pub fn create() -> Deque { impl Repr: Deque { fn size() -> uint { return self.nelts; } - fn add_front(+t: T) { + fn add_front(t: T) { let oldlo: uint = self.lo; if self.lo == 0u { self.lo = self.elts.len() - 1u; @@ -68,7 +68,7 @@ pub fn create() -> Deque { self.elts.set_elt(self.lo, Some(t)); self.nelts += 1u; } - fn add_back(+t: T) { + fn add_back(t: T) { if self.lo == self.hi && self.nelts != 0u { self.elts.swap(|v| grow(self.nelts, self.lo, move v)); self.lo = 0u; @@ -200,7 +200,7 @@ mod tests { assert (deq.get(3) == d); } - fn test_parameterized(+a: T, +b: T, +c: T, +d: T) { + fn test_parameterized(a: T, +b: T, +c: T, +d: T) { let deq: deque::Deque = deque::create::(); assert (deq.size() == 0u); deq.add_front(a); diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 9d127f5db47..8fd775c4773 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -62,7 +62,7 @@ * } */ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap use core::cmp::Eq; use core::result::{Err, Ok}; @@ -179,7 +179,7 @@ pub enum Fail_ { } /// Convert a `fail_` enum into an error string -pub fn fail_str(+f: Fail_) -> ~str { +pub fn fail_str(f: Fail_) -> ~str { return match f { ArgumentMissing(ref nm) => { ~"Argument to option '" + *nm + ~"' missing." @@ -335,7 +335,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result unsafe { free: free}); } -fn opt_vals(+mm: Matches, nm: &str) -> ~[Optval] { +fn opt_vals(mm: Matches, nm: &str) -> ~[Optval] { return match find_opt(mm.opts, mkname(nm)) { Some(id) => mm.vals[id], None => { @@ -345,15 +345,15 @@ fn opt_vals(+mm: Matches, nm: &str) -> ~[Optval] { }; } -fn opt_val(+mm: Matches, nm: &str) -> Optval { return opt_vals(mm, nm)[0]; } +fn opt_val(mm: Matches, nm: &str) -> Optval { return opt_vals(mm, nm)[0]; } /// Returns true if an option was matched -pub fn opt_present(+mm: Matches, nm: &str) -> bool { +pub fn opt_present(mm: Matches, nm: &str) -> bool { return vec::len::(opt_vals(mm, nm)) > 0u; } /// Returns true if any of several options were matched -pub fn opts_present(+mm: Matches, names: &[~str]) -> bool { +pub fn opts_present(mm: Matches, names: &[~str]) -> bool { for vec::each(names) |nm| { match find_opt(mm.opts, mkname(*nm)) { Some(_) => return true, @@ -370,7 +370,7 @@ pub fn opts_present(+mm: Matches, names: &[~str]) -> bool { * Fails if the option was not matched or if the match did not take an * argument */ -pub fn opt_str(+mm: Matches, nm: &str) -> ~str { +pub fn opt_str(mm: Matches, nm: &str) -> ~str { return match opt_val(mm, nm) { Val(copy s) => s, _ => fail }; } @@ -380,7 +380,8 @@ pub fn opt_str(+mm: Matches, nm: &str) -> ~str { * Fails if the no option was provided from the given list, or if the no such * option took an argument */ -pub fn opts_str(+mm: Matches, names: &[~str]) -> ~str { +pub fn opts_str(mm: Matches, names: &[~str]) -> ~str { +>>>>>>> Remove uses of + mode from libstd for vec::each(names) |nm| { match opt_val(mm, *nm) { Val(copy s) => return s, @@ -397,7 +398,7 @@ pub fn opts_str(+mm: Matches, names: &[~str]) -> ~str { * * Used when an option accepts multiple values. */ -pub fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { +pub fn opt_strs(mm: Matches, nm: &str) -> ~[~str] { let mut acc: ~[~str] = ~[]; for vec::each(opt_vals(mm, nm)) |v| { match *v { Val(copy s) => acc.push(s), _ => () } @@ -406,7 +407,7 @@ pub fn opt_strs(+mm: Matches, nm: &str) -> ~[~str] { } /// Returns the string argument supplied to a matching option or none -pub fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { +pub fn opt_maybe_str(mm: Matches, nm: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::(vals) == 0u { return None::<~str>; } return match vals[0] { @@ -423,7 +424,7 @@ pub fn opt_maybe_str(+mm: Matches, nm: &str) -> Option<~str> { * present but no argument was provided, and the argument if the option was * present and an argument was provided. */ -pub fn opt_default(+mm: Matches, nm: &str, def: &str) -> Option<~str> { +pub fn opt_default(mm: Matches, nm: &str, def: &str) -> Option<~str> { let vals = opt_vals(mm, nm); if vec::len::(vals) == 0u { return None::<~str>; } return match vals[0] { Val(copy s) => Some::<~str>(s), @@ -451,7 +452,7 @@ mod tests { use opt = getopts; use result::{Err, Ok}; - fn check_fail_type(+f: Fail_, ft: FailType) { + fn check_fail_type(f: Fail_, ft: FailType) { match f { ArgumentMissing(_) => assert ft == ArgumentMissing_, UnrecognizedOption(_) => assert ft == UnrecognizedOption_, diff --git a/src/libstd/json.rs b/src/libstd/json.rs index d3713bdb29d..f244f2869a6 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -1,6 +1,6 @@ // Rust JSON serialization library // Copyright (c) 2011 Google Inc. -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap #[forbid(non_camel_case_types)]; //! json serialization @@ -370,7 +370,7 @@ priv impl Parser { self.ch } - fn error(+msg: ~str) -> Result { + fn error(msg: ~str) -> Result { Err(Error { line: self.line, col: self.col, msg: @msg }) } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 5b0931ebdee..4ff493f5ab9 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -29,7 +29,7 @@ pub fn from_vec(v: &[T]) -> @List { * * z - The initial value * * f - The function to apply */ -pub fn foldl(+z: T, ls: @List, f: fn((&T), (&U)) -> T) -> T { +pub fn foldl(z: T, ls: @List, f: fn((&T), (&U)) -> T) -> T { let mut accum: T = z; do iter(ls) |elt| { accum = f(&accum, elt);} accum diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 84fee092562..cc42c562376 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -1,6 +1,6 @@ //! A map type -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap use io::WriterUtil; use to_str::ToStr; @@ -28,10 +28,10 @@ pub trait Map { * * Returns true if the key did not already exist in the map */ - fn insert(+v: K, +v: V) -> bool; + fn insert(v: K, +v: V) -> bool; /// Returns true if the map contains a value for the specified key - fn contains_key(+key: K) -> bool; + fn contains_key(key: K) -> bool; /// Returns true if the map contains a value for the specified /// key, taking the key by reference. @@ -41,31 +41,31 @@ pub trait Map { * Get the value for the specified key. Fails if the key does not exist in * the map. */ - fn get(+key: K) -> V; + fn get(key: K) -> V; /** * Get the value for the specified key. If the key does not exist in * the map then returns none. */ - pure fn find(+key: K) -> Option; + pure fn find(key: K) -> Option; /** * Remove and return a value from the map. Returns true if the * key was present in the map, otherwise false. */ - fn remove(+key: K) -> bool; + fn remove(key: K) -> bool; /// Clear the map, removing all key/value pairs. fn clear(); /// Iterate over all the key/value pairs in the map by value - pure fn each(fn(+key: K, +value: V) -> bool); + pure fn each(fn(key: K, +value: V) -> bool); /// Iterate over all the keys in the map by value - pure fn each_key(fn(+key: K) -> bool); + pure fn each_key(fn(key: K) -> bool); /// Iterate over all the values in the map by value - pure fn each_value(fn(+value: V) -> bool); + pure fn each_value(fn(value: V) -> bool); /// Iterate over all the key/value pairs in the map by reference pure fn each_ref(fn(key: &K, value: &V) -> bool); @@ -201,7 +201,7 @@ pub mod chained { impl T: Map { pure fn size() -> uint { self.count } - fn contains_key(+k: K) -> bool { + fn contains_key(k: K) -> bool { self.contains_key_ref(&k) } @@ -213,7 +213,7 @@ pub mod chained { } } - fn insert(+k: K, +v: V) -> bool { + fn insert(k: K, +v: V) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(&k, hash) { NotFound => { @@ -255,7 +255,7 @@ pub mod chained { } } - pure fn find(+k: K) -> Option { + pure fn find(k: K) -> Option { unsafe { match self.search_tbl(&k, k.hash_keyed(0,0) as uint) { NotFound => None, @@ -265,7 +265,7 @@ pub mod chained { } } - fn get(+k: K) -> V { + fn get(k: K) -> V { let opt_v = self.find(k); if opt_v.is_none() { fail fmt!("Key not found in table: %?", k); @@ -273,7 +273,7 @@ pub mod chained { option::unwrap(move opt_v) } - fn remove(+k: K) -> bool { + fn remove(k: K) -> bool { match self.search_tbl(&k, k.hash_keyed(0,0) as uint) { NotFound => false, FoundFirst(idx, entry) => { @@ -294,15 +294,15 @@ pub mod chained { self.chains = chains(initial_capacity); } - pure fn each(blk: fn(+key: K, +value: V) -> bool) { + pure fn each(blk: fn(key: K, +value: V) -> bool) { self.each_ref(|k, v| blk(*k, *v)) } - pure fn each_key(blk: fn(+key: K) -> bool) { + pure fn each_key(blk: fn(key: K) -> bool) { self.each_key_ref(|p| blk(*p)) } - pure fn each_value(blk: fn(+value: V) -> bool) { + pure fn each_value(blk: fn(value: V) -> bool) { self.each_value_ref(|p| blk(*p)) } @@ -377,7 +377,7 @@ pub fn HashMap() } /// Convenience function for adding keys to a hashmap with nil type keys -pub fn set_add(set: Set, +key: K) -> bool { +pub fn set_add(set: Set, key: K) -> bool { set.insert(key, ()) } @@ -415,13 +415,13 @@ impl @Mut>: } } - fn insert(+key: K, +value: V) -> bool { + fn insert(key: K, value: V) -> bool { do self.borrow_mut |p| { p.insert(key, value) } } - fn contains_key(+key: K) -> bool { + fn contains_key(key: K) -> bool { do self.borrow_const |p| { p.contains_key(&key) } @@ -433,13 +433,13 @@ impl @Mut>: } } - fn get(+key: K) -> V { + fn get(key: K) -> V { do self.borrow_const |p| { p.get(&key) } } - pure fn find(+key: K) -> Option { + pure fn find(key: K) -> Option { unsafe { do self.borrow_const |p| { p.find(&key) @@ -447,7 +447,7 @@ impl @Mut>: } } - fn remove(+key: K) -> bool { + fn remove(key: K) -> bool { do self.borrow_mut |p| { p.remove(&key) } @@ -459,7 +459,7 @@ impl @Mut>: } } - pure fn each(op: fn(+key: K, +value: V) -> bool) { + pure fn each(op: fn(key: K, +value: V) -> bool) { unsafe { do self.borrow_imm |p| { p.each(|k, v| op(*k, *v)) @@ -467,7 +467,7 @@ impl @Mut>: } } - pure fn each_key(op: fn(+key: K) -> bool) { + pure fn each_key(op: fn(key: K) -> bool) { unsafe { do self.borrow_imm |p| { p.each_key(|k| op(*k)) @@ -475,7 +475,7 @@ impl @Mut>: } } - pure fn each_value(op: fn(+value: V) -> bool) { + pure fn each_value(op: fn(value: V) -> bool) { unsafe { do self.borrow_imm |p| { p.each_value(|v| op(*v)) diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 59cb0d36f77..be38f16aff7 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -129,7 +129,7 @@ enum TcpConnectErrData { * the remote host. In the event of failure, a * `net::tcp::tcp_connect_err_data` instance will be returned */ -fn connect(+input_ip: ip::IpAddr, port: uint, +fn connect(input_ip: ip::IpAddr, port: uint, iotask: IoTask) -> result::Result unsafe { let result_po = core::comm::Port::(); @@ -570,7 +570,7 @@ fn accept(new_conn: TcpNewConnection) * successful/normal shutdown, and a `tcp_listen_err_data` enum in the event * of listen exiting because of an error */ -fn listen(+host_ip: ip::IpAddr, port: uint, backlog: uint, +fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint, iotask: IoTask, +on_establish_cb: fn~(comm::Chan>), +new_connect_cb: fn~(TcpNewConnection, @@ -587,7 +587,7 @@ fn listen(+host_ip: ip::IpAddr, port: uint, backlog: uint, } } -fn listen_common(+host_ip: ip::IpAddr, port: uint, backlog: uint, +fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint, iotask: IoTask, +on_establish_cb: fn~(comm::Chan>), +on_connect_cb: fn~(*uv::ll::uv_tcp_t)) @@ -728,7 +728,7 @@ fn listen_common(+host_ip: ip::IpAddr, port: uint, backlog: uint, * * A buffered wrapper that you can cast as an `io::reader` or `io::writer` */ -fn socket_buf(+sock: TcpSocket) -> TcpSocketBuf { +fn socket_buf(sock: TcpSocket) -> TcpSocketBuf { TcpSocketBuf(@{ sock: move sock, mut buf: ~[] }) } @@ -738,7 +738,7 @@ impl TcpSocket { result::Result<~[u8], TcpErrData>>, TcpErrData> { read_start(&self) } - fn read_stop(+read_port: + fn read_stop(read_port: comm::Port>) -> result::Result<(), TcpErrData> { read_stop(&self, move read_port) @@ -1476,7 +1476,7 @@ mod test { */ } - fn buf_write(+w: &W, val: &str) { + fn buf_write(w: &W, val: &str) { log(debug, fmt!("BUF_WRITE: val len %?", str::len(val))); do str::byte_slice(val) |b_slice| { log(debug, fmt!("BUF_WRITE: b_slice len %?", @@ -1485,7 +1485,7 @@ mod test { } } - fn buf_read(+r: &R, len: uint) -> ~str { + fn buf_read(r: &R, len: uint) -> ~str { let new_bytes = (*r).read_bytes(len); log(debug, fmt!("in buf_read.. new_bytes len: %?", vec::len(new_bytes))); diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 920751d690f..6dca075405b 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -1,5 +1,5 @@ //! Types/fns concerning URLs (see RFC 3986) -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after a snapshot use core::cmp::Eq; use map::HashMap; @@ -36,7 +36,7 @@ type UserInfo = { type Query = ~[(~str, ~str)]; -fn Url(+scheme: ~str, +user: Option, +host: ~str, +fn Url(scheme: ~str, +user: Option, +host: ~str, +port: Option<~str>, +path: ~str, +query: Query, +fragment: Option<~str>) -> Url { Url { scheme: move scheme, user: move user, host: move host, @@ -44,7 +44,7 @@ fn Url(+scheme: ~str, +user: Option, +host: ~str, fragment: move fragment } } -fn UserInfo(+user: ~str, +pass: Option<~str>) -> UserInfo { +fn UserInfo(user: ~str, +pass: Option<~str>) -> UserInfo { {user: move user, pass: move pass} } @@ -306,7 +306,7 @@ fn userinfo_from_str(uinfo: &str) -> UserInfo { return UserInfo(user, pass); } -fn userinfo_to_str(+userinfo: UserInfo) -> ~str { +fn userinfo_to_str(userinfo: UserInfo) -> ~str { if option::is_some(&userinfo.pass) { return str::concat(~[copy userinfo.user, ~":", option::unwrap(copy userinfo.pass), @@ -334,7 +334,7 @@ fn query_from_str(rawquery: &str) -> Query { return query; } -fn query_to_str(+query: Query) -> ~str { +fn query_to_str(query: Query) -> ~str { let mut strvec = ~[]; for query.each |kv| { let (k, v) = copy *kv; @@ -681,7 +681,7 @@ impl Url : FromStr { * result in just "http://somehost.com". * */ -fn to_str(+url: Url) -> ~str { +fn to_str(url: Url) -> ~str { let user = if url.user.is_some() { userinfo_to_str(option::unwrap(copy url.user)) } else { diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index d14a4854555..5df4fc10a03 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -379,7 +379,7 @@ Section: Iterating * `true` If execution proceeded correctly, `false` if it was interrupted, * that is if `it` returned `false` at any point. */ -pub fn loop_chars(rope: Rope, it: fn(+c: char) -> bool) -> bool { +pub fn loop_chars(rope: Rope, it: fn(c: char) -> bool) -> bool { match (rope) { node::Empty => return true, node::Content(x) => return node::loop_chars(x, it) @@ -1037,7 +1037,7 @@ mod node { return result; } - pub fn loop_chars(node: @Node, it: fn(+c: char) -> bool) -> bool { + pub fn loop_chars(node: @Node, it: fn(c: char) -> bool) -> bool { return loop_leaves(node,|leaf| { str::all_between(*leaf.content, leaf.byte_offset, diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 2e7f47e0af0..58ecbb0d6c3 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -2,7 +2,7 @@ * A simple map based on a vector for small integer keys. Space requirements * are O(highest integer key). */ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap use core::option; use core::option::{Some, None}; @@ -28,7 +28,7 @@ pub fn mk() -> SmallIntMap { * the specified key then the original value is replaced. */ #[inline(always)] -pub fn insert(self: SmallIntMap, key: uint, +val: T) { +pub fn insert(self: SmallIntMap, key: uint, val: T) { //io::println(fmt!("%?", key)); self.v.grow_set_elt(key, &None, Some(val)); } @@ -77,12 +77,12 @@ impl SmallIntMap: map::Map { sz } #[inline(always)] - fn insert(+key: uint, +value: V) -> bool { + fn insert(key: uint, value: V) -> bool { let exists = contains_key(self, key); insert(self, key, value); return !exists; } - fn remove(+key: uint) -> bool { + fn remove(key: uint) -> bool { if key >= self.v.len() { return false; } @@ -93,23 +93,23 @@ impl SmallIntMap: map::Map { fn clear() { self.v.set(~[]); } - fn contains_key(+key: uint) -> bool { + fn contains_key(key: uint) -> bool { contains_key(self, key) } fn contains_key_ref(key: &uint) -> bool { contains_key(self, *key) } - fn get(+key: uint) -> V { get(self, key) } - pure fn find(+key: uint) -> Option { find(self, key) } + fn get(key: uint) -> V { get(self, key) } + pure fn find(key: uint) -> Option { find(self, key) } fn rehash() { fail } - pure fn each(it: fn(+key: uint, +value: V) -> bool) { + pure fn each(it: fn(key: uint, +value: V) -> bool) { self.each_ref(|k, v| it(*k, *v)) } - pure fn each_key(it: fn(+key: uint) -> bool) { + pure fn each_key(it: fn(key: uint) -> bool) { self.each_ref(|k, _v| it(*k)) } - pure fn each_value(it: fn(+value: V) -> bool) { + pure fn each_value(it: fn(value: V) -> bool) { self.each_ref(|_k, v| it(*v)) } pure fn each_ref(it: fn(key: &uint, value: &V) -> bool) { diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 202cb4932db..683ea589b91 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -18,9 +18,6 @@ not required in or otherwise suitable for the core library. #[no_core]; -// tjc: Added legacy_modes back in because it still uses + mode. -// Remove once + mode gets expunged from std. -#[legacy_modes]; #[legacy_exports]; #[allow(vecs_implicitly_copyable)]; diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index f66f2f5b5d3..f66134d3892 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap /** * The concurrency primitives you know and love. * @@ -69,7 +69,7 @@ struct SemInner { enum Sem = Exclusive>; #[doc(hidden)] -fn new_sem(count: int, +q: Q) -> Sem { +fn new_sem(count: int, q: Q) -> Sem { Sem(exclusive(SemInner { mut count: count, waiters: new_waitqueue(), blocked: q })) } @@ -535,7 +535,7 @@ impl &RWlock { * } * ~~~ */ - fn write_downgrade(blk: fn(+v: RWlockWriteMode) -> U) -> U { + fn write_downgrade(blk: fn(v: RWlockWriteMode) -> U) -> U { // Implementation slightly different from the slicker 'write's above. // The exit path is conditional on whether the caller downgrades. let mut _release = None; @@ -551,7 +551,7 @@ impl &RWlock { } /// To be called inside of the write_downgrade block. - fn downgrade(+token: RWlockWriteMode/&a) -> RWlockReadMode/&a { + fn downgrade(token: RWlockWriteMode/&a) -> RWlockReadMode/&a { if !ptr::ref_eq(self, token.lock) { fail ~"Can't downgrade() with a different rwlock's write_mode!"; } @@ -957,7 +957,7 @@ mod tests { drop { self.c.send(()); } } - fn SendOnFailure(+c: pipes::Chan<()>) -> SendOnFailure { + fn SendOnFailure(c: pipes::Chan<()>) -> SendOnFailure { SendOnFailure { c: c } @@ -1038,7 +1038,7 @@ mod tests { } } #[cfg(test)] - fn test_rwlock_exclusion(+x: ~RWlock, mode1: RWlockMode, + fn test_rwlock_exclusion(x: ~RWlock, mode1: RWlockMode, mode2: RWlockMode) { // Test mutual exclusion between readers and writers. Just like the // mutex mutual exclusion test, a ways above. @@ -1083,7 +1083,7 @@ mod tests { test_rwlock_exclusion(~RWlock(), Downgrade, Downgrade); } #[cfg(test)] - fn test_rwlock_handshake(+x: ~RWlock, mode1: RWlockMode, + fn test_rwlock_handshake(x: ~RWlock, mode1: RWlockMode, mode2: RWlockMode, make_mode2_go_first: bool) { // Much like sem_multi_resource. let x2 = ~x.clone(); diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 1df10a4d799..c5d9dd343fa 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -270,7 +270,7 @@ enum TestEvent { type MonitorMsg = (TestDesc, TestResult); fn run_tests(opts: &TestOpts, tests: &[TestDesc], - callback: fn@(+e: TestEvent)) { + callback: fn@(e: TestEvent)) { let mut filtered_tests = filter_tests(opts, tests); callback(TeFiltered(copy filtered_tests)); @@ -379,7 +379,7 @@ fn filter_tests(opts: &TestOpts, type TestFuture = {test: TestDesc, wait: fn@() -> TestResult}; -fn run_test(+test: TestDesc, monitor_ch: comm::Chan) { +fn run_test(test: TestDesc, monitor_ch: comm::Chan) { if test.ignore { core::comm::send(monitor_ch, (copy test, TrIgnored)); return; diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 43cbc6da9bd..aef3bb2ac0a 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -1,4 +1,4 @@ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap use core::cmp::Eq; use libc::{c_char, c_int, c_long, size_t, time_t}; @@ -589,7 +589,7 @@ pub fn strptime(s: &str, format: &str) -> Result { } } -fn strftime(format: &str, +tm: Tm) -> ~str { +fn strftime(format: &str, tm: Tm) -> ~str { fn parse_type(ch: char, tm: &Tm) -> ~str { //FIXME (#2350): Implement missing types. let die = || #fmt("strftime: can't understand this format %c ", diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 8aaf7d3fd87..2aca87b942e 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -1,6 +1,6 @@ //! Utilities that leverage libuv's `uv_timer_*` API -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after snap use uv = uv; use uv::iotask; @@ -24,7 +24,7 @@ use comm = core::comm; * * val - a value of type T to send over the provided `ch` */ pub fn delayed_send(iotask: IoTask, - msecs: uint, ch: comm::Chan, +val: T) { + msecs: uint, ch: comm::Chan, val: T) { unsafe { let timer_done_po = core::comm::Port::<()>(); let timer_done_ch = core::comm::Chan(timer_done_po); diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 876aa6f4af0..4a4a34704be 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -5,7 +5,7 @@ * `interact` function you can execute code in a uv callback. */ -#[forbid(deprecated_mode)]; +// tjc: forbid deprecated modes again after a snapshot use libc::c_void; use ptr::p2::addr_of; @@ -22,7 +22,7 @@ pub enum IoTask { }) } -pub fn spawn_iotask(+task: task::TaskBuilder) -> IoTask { +pub fn spawn_iotask(task: task::TaskBuilder) -> IoTask { do listen |iotask_ch| { diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index f0594475d04..50636054821 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -642,7 +642,7 @@ extern mod rustrt { fn rust_uv_addrinfo_as_sockaddr_in(input: *addrinfo) -> *sockaddr_in; fn rust_uv_addrinfo_as_sockaddr_in6(input: *addrinfo) -> *sockaddr_in6; fn rust_uv_malloc_buf_base_of(sug_size: libc::size_t) -> *u8; - fn rust_uv_free_base_of_buf(++buf: uv_buf_t); + fn rust_uv_free_base_of_buf(+buf: uv_buf_t); fn rust_uv_get_stream_handle_from_connect_req( connect_req: *uv_connect_t) -> *uv_stream_t; @@ -661,8 +661,8 @@ extern mod rustrt { fn rust_uv_get_data_for_req(req: *libc::c_void) -> *libc::c_void; fn rust_uv_set_data_for_req(req: *libc::c_void, data: *libc::c_void); - fn rust_uv_get_base_from_buf(++buf: uv_buf_t) -> *u8; - fn rust_uv_get_len_from_buf(++buf: uv_buf_t) -> libc::size_t; + fn rust_uv_get_base_from_buf(+buf: uv_buf_t) -> *u8; + fn rust_uv_get_len_from_buf(+buf: uv_buf_t) -> libc::size_t; // sizeof testing helpers fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint; diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index f35a3ce735f..a34fcc89c04 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -251,7 +251,7 @@ fn pbfs(&&graph: arc::ARC, key: node_id) -> bfs_result { colors = do par::mapi_factory(*color_vec) { let colors = arc::clone(&color); let graph = arc::clone(&graph); - fn~(i: uint, c: color) -> color { + fn~(+i: uint, +c: color) -> color { let c : color = c; let colors = arc::get(&colors); let graph = arc::get(&graph); -- cgit 1.4.1-3-g733a5 From 72b7a7707f7baead4e569c9d3ec2fe28b9486ac9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 3 Oct 2012 14:29:39 -0700 Subject: test: Use println instead of debug in hello.rs --- src/test/run-pass/hello.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/test') diff --git a/src/test/run-pass/hello.rs b/src/test/run-pass/hello.rs index 5f61c554992..5b0664f400b 100644 --- a/src/test/run-pass/hello.rs +++ b/src/test/run-pass/hello.rs @@ -1,5 +1,5 @@ - - - // -*- rust -*- -fn main() { debug!("hello, world."); } + +fn main() { + io::println("hello, world"); +} -- cgit 1.4.1-3-g733a5 From d936773e56a2dc450bb620a8bab45b6a17fd12cd Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 3 Oct 2012 15:18:28 -0700 Subject: test: Add a test case for "pub use a::*" --- src/test/run-pass/reexport-star.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/test/run-pass/reexport-star.rs (limited to 'src/test') diff --git a/src/test/run-pass/reexport-star.rs b/src/test/run-pass/reexport-star.rs new file mode 100644 index 00000000000..1709ddc70f2 --- /dev/null +++ b/src/test/run-pass/reexport-star.rs @@ -0,0 +1,14 @@ +mod a { + pub fn f() {} + pub fn g() {} +} + +mod b { + pub use a::*; +} + +fn main() { + b::f(); + b::g(); +} + -- cgit 1.4.1-3-g733a5