From 49c74524e2c5a2a81ce4cbe2c50a507c0be9f24e Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 17 Jun 2013 19:43:22 -0400 Subject: vec: rm old_iter implementations, except BaseIter The removed test for issue #2611 is well covered by the `std::iterator` module itself. This adds the `count` method to `IteratorUtil` to replace `EqIter`. --- src/libstd/task/local_data_priv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libstd/task/local_data_priv.rs b/src/libstd/task/local_data_priv.rs index f6b14a51539..0956b76c970 100644 --- a/src/libstd/task/local_data_priv.rs +++ b/src/libstd/task/local_data_priv.rs @@ -142,7 +142,7 @@ unsafe fn local_data_lookup( -> Option<(uint, *libc::c_void)> { let key_value = key_to_key_value(key); - let map_pos = (*map).position(|entry| + let map_pos = (*map).iter().position_(|entry| match *entry { Some((k,_,_)) => k == key_value, None => false @@ -215,7 +215,7 @@ pub unsafe fn local_set( } None => { // Find an empty slot. If not, grow the vector. - match (*map).position(|x| x.is_none()) { + match (*map).iter().position_(|x| x.is_none()) { Some(empty_index) => { map[empty_index] = new_entry; } None => { map.push(new_entry); } } -- cgit 1.4.1-3-g733a5 From e67c48a5912b85c286113e0d039aae85f18da1d7 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 24 Jun 2013 18:34:20 -0400 Subject: remove `each` from vec, HashMap and HashSet --- doc/tutorial.md | 57 +++++++--- src/compiletest/runtest.rs | 2 +- src/libextra/arc.rs | 11 +- src/libextra/getopts.rs | 5 +- src/libextra/json.rs | 8 +- src/libextra/net_url.rs | 2 +- src/libextra/serialize.rs | 4 +- src/libextra/sync.rs | 3 +- src/libextra/workcache.rs | 4 +- src/librustc/metadata/cstore.rs | 2 +- src/librustc/middle/kind.rs | 3 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/lint.rs | 7 +- src/librustc/middle/region.rs | 2 +- src/librustc/middle/resolve.rs | 24 ++-- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/trans/callee.rs | 4 +- src/librustc/middle/trans/type_use.rs | 3 +- .../middle/typeck/infer/region_inference.rs | 2 +- src/librustc/rustc.rs | 2 +- src/librusti/program.rs | 8 +- src/libstd/hashmap.rs | 11 -- src/libstd/task/spawn.rs | 2 +- src/libstd/vec.rs | 122 ++------------------- src/test/bench/graph500-bfs.rs | 4 +- src/test/bench/msgsend-pipes-shared.rs | 2 +- src/test/bench/msgsend-pipes.rs | 2 +- src/test/bench/shootout-chameneos-redux.rs | 4 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- .../compile-fail/block-must-not-have-result-for.rs | 4 +- .../compile-fail/borrowck-insert-during-each.rs | 2 +- src/test/compile-fail/issue-2151.rs | 7 +- src/test/compile-fail/liveness-issue-2163.rs | 2 +- src/test/run-pass/assignability-trait.rs | 6 +- src/test/run-pass/auto-loop.rs | 5 +- src/test/run-pass/block-arg.rs | 2 +- src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs | 6 +- src/test/run-pass/break.rs | 6 +- src/test/run-pass/const-vec-of-fns.rs | 4 +- src/test/run-pass/for-destruct.rs | 3 +- src/test/run-pass/rcvr-borrowed-to-slice.rs | 2 +- src/test/run-pass/trait-generic.rs | 5 +- 43 files changed, 139 insertions(+), 223 deletions(-) (limited to 'src/libstd/task') diff --git a/doc/tutorial.md b/doc/tutorial.md index 9c61a04930a..9e54622688b 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1552,13 +1552,6 @@ fn each(v: &[int], op: &fn(v: &int)) { } ~~~~ -As an aside, the reason we pass in a *pointer* to an integer rather -than the integer itself is that this is how the actual `each()` -function for vectors works. `vec::each` though is a -[generic](#generics) function, so must be efficient to use for all -types. Passing the elements by pointer avoids copying potentially -large objects. - As a caller, if we use a closure to provide the final operator argument, we can write it in a way that has a pleasant, block-like structure. @@ -1616,6 +1609,9 @@ To enable `debug!` logging, set the RUST_LOG environment variable to the name of ## For loops +> ***Note:*** The closure-based protocol used `for` loop is on the way out. The `for` loop will +> use iterator objects in the future instead. + The most common way to express iteration in Rust is with a `for` loop. Like `do`, `for` is a nice syntax for describing control flow with closures. Additionally, within a `for` loop, `break`, `loop`, @@ -1640,7 +1636,16 @@ fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { And using this function to iterate over a vector: ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } each([2, 4, 8, 5, 16], |n| { if *n % 2 != 0 { println("found odd number!"); @@ -1656,7 +1661,16 @@ out of the loop, you just write `break`. To skip ahead to the next iteration, write `loop`. ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } for each([2, 4, 8, 5, 16]) |n| { if *n % 2 != 0 { println("found odd number!"); @@ -1671,7 +1685,16 @@ normally allowed in closures, in a block that appears as the body of a the enclosing function, not just the loop body. ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } fn contains(v: &[int], elt: int) -> bool { for each(v) |x| { if (*x == elt) { return true; } @@ -1686,7 +1709,16 @@ In these situations it can be convenient to lean on Rust's argument patterns to bind `x` to the actual value, not the pointer. ~~~~ -# use each = std::vec::each; +# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool { +# let mut n = 0; +# while n < v.len() { +# if !op(&v[n]) { +# return false; +# } +# n += 1; +# } +# return true; +# } # fn contains(v: &[int], elt: int) -> bool { for each(v) |&x| { if (x == elt) { return true; } @@ -1841,10 +1873,9 @@ vector consisting of the result of applying `function` to each element of `vector`: ~~~~ -# use std::vec; fn map(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] { let mut accumulator = ~[]; - for vec::each(vector) |element| { + for vector.iter().advance |element| { accumulator.push(function(element)); } return accumulator; diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index fd56031ccf9..3e2f484ee53 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -529,7 +529,7 @@ fn compose_and_run_compiler( let extra_link_args = ~[~"-L", aux_output_dir_name(config, testfile).to_str()]; - for vec::each(props.aux_builds) |rel_ab| { + for props.aux_builds.iter().advance |rel_ab| { let abs_ab = config.aux_base.push_rel(&Path(*rel_ab)); let aux_args = make_compile_args(config, props, ~[~"--lib"] + extra_link_args, diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 32114f4037e..c5fe07f2187 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -521,6 +521,7 @@ mod tests { use core::cell::Cell; use core::comm; use core::task; + use core::uint; #[test] fn manually_share_arc() { @@ -790,18 +791,20 @@ mod tests { } assert_eq!(*state, 42); *state = 31337; + // FIXME: #7372: hits type inference bug with iterators // send to other readers - for vec::each(reader_convos) |x| { - match *x { + for uint::range(0, reader_convos.len()) |i| { + match reader_convos[i] { (ref rc, _) => rc.send(()), } } } let read_mode = arc.downgrade(write_mode); do (&read_mode).read |state| { + // FIXME: #7372: hits type inference bug with iterators // complete handshake with other readers - for vec::each(reader_convos) |x| { - match *x { + for uint::range(0, reader_convos.len()) |i| { + match reader_convos[i] { (_, ref rp) => rp.recv(), } } diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index d97804722f2..9c416550eb7 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -418,10 +418,11 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str { */ pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] { let mut acc: ~[~str] = ~[]; - for vec::each(opt_vals(mm, nm)) |v| { + let r = opt_vals(mm, nm); + for r.iter().advance |v| { match *v { Val(ref s) => acc.push(copy *s), _ => () } } - return acc; + acc } /// Returns the string argument supplied to a matching option or none diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 24c4c5b27c4..15553b035f6 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -1123,7 +1123,7 @@ impl Eq for Json { &Object(ref d1) => { if d0.len() == d1.len() { let mut equal = true; - for d0.each |k, v0| { + for d0.iter().advance |(k, v0)| { match d1.find(k) { Some(v1) if v0 == v1 => { }, _ => { equal = false; break } @@ -1186,12 +1186,12 @@ impl Ord for Json { let mut d1_flat = ~[]; // FIXME #4430: this is horribly inefficient... - for d0.each |k, v| { + for d0.iter().advance |(k, v)| { d0_flat.push((@copy *k, @copy *v)); } d0_flat.qsort(); - for d1.each |k, v| { + for d1.iter().advance |(k, v)| { d1_flat.push((@copy *k, @copy *v)); } d1_flat.qsort(); @@ -1326,7 +1326,7 @@ impl ToJson for ~[A] { impl ToJson for HashMap<~str, A> { fn to_json(&self) -> Json { let mut d = HashMap::new(); - for self.each |key, value| { + for self.iter().advance |(key, value)| { d.insert(copy *key, value.to_json()); } Object(~d) diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index dda4b85df4b..5d3d31fdec4 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -207,7 +207,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str { let mut out = ~""; let mut first = true; - for m.each |key, values| { + for m.iter().advance |(key, values)| { let key = encode_plus(*key); for values.iter().advance |value| { diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 34fd7e9f1ec..345b217871c 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -710,7 +710,7 @@ impl< fn encode(&self, e: &mut E) { do e.emit_map(self.len()) |e| { let mut i = 0; - for self.each |key, val| { + for self.iter().advance |(key, val)| { e.emit_map_elt_key(i, |e| key.encode(e)); e.emit_map_elt_val(i, |e| val.encode(e)); i += 1; @@ -744,7 +744,7 @@ impl< fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { let mut i = 0; - for self.each |e| { + for self.iter().advance |e| { s.emit_seq_elt(i, |s| e.encode(s)); i += 1; } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 6990d35f061..5cb52a7b9df 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -1094,7 +1094,8 @@ mod tests { }; assert!(result.is_err()); // child task must have finished by the time try returns - for vec::each(p.recv()) |p| { p.recv(); } // wait on all its siblings + let r = p.recv(); + for r.iter().advance |p| { p.recv(); } // wait on all its siblings do m.lock_cond |cond| { let woken = cond.broadcast(); assert_eq!(woken, 0); diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index ed675bf99e9..a014293f063 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -146,7 +146,7 @@ impl WorkMap { impl Encodable for WorkMap { fn encode(&self, s: &mut S) { let mut d = ~[]; - for self.each |k, v| { + for self.iter().advance |(k, v)| { d.push((copy *k, copy *v)) } sort::tim_sort(d); @@ -320,7 +320,7 @@ impl TPrep for Prep { } fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool { - for map.each |k, v| { + for map.iter().advance |(k, v)| { if ! self.is_fresh(cat, k.kind, k.name, *v) { return false; } diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index c6c1ac720e8..b0a955fef8f 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool { pub fn iter_crate_data(cstore: &CStore, i: &fn(ast::crate_num, @crate_metadata)) { - for cstore.metas.each |&k, &v| { + for cstore.metas.iter().advance |(&k, &v)| { i(k, v); } } diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 7f7a81fa974..b0b2a16cf89 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -240,7 +240,8 @@ fn check_fn( // Check kinds on free variables: do with_appropriate_checker(cx, fn_id) |chk| { - for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) |fv| { + let r = freevars::get_freevars(cx.tcx, fn_id); + for r.iter().advance |fv| { chk(cx, *fv); } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index d73b019c1ea..9d4064e99bd 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -436,7 +436,7 @@ impl LanguageItemCollector { } pub fn check_completeness(&self) { - for self.item_refs.each |&key, &item_ref| { + for self.item_refs.iter().advance |(&key, &item_ref)| { match self.items.items[item_ref] { None => { self.session.err(fmt!("no item found for `%s`", key)); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 5c36ab7750c..6da10b7c277 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -361,7 +361,7 @@ impl Context { } fn lint_to_str(&self, lint: lint) -> &'static str { - for self.dict.each |k, v| { + for self.dict.iter().advance |(k, v)| { if v.lint == lint { return *k; } @@ -742,7 +742,8 @@ fn check_item_ctypes(cx: &Context, it: @ast::item) { fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) { let tys = vec::map(decl.inputs, |a| a.ty ); - for vec::each(vec::append_one(tys, decl.output)) |ty| { + let r = vec::append_one(tys, decl.output); + for r.iter().advance |ty| { check_ty(cx, *ty); } } @@ -1171,7 +1172,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) { // If we missed any lints added to the session, then there's a bug somewhere // in the iteration code. - for tcx.sess.lints.each |_, v| { + for tcx.sess.lints.iter().advance |(_, v)| { for v.iter().advance |t| { match *t { (lint, span, ref msg) => diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 0e6d8617ba4..7d3e895a0ed 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -948,7 +948,7 @@ pub fn determine_rp_in_crate(sess: Session, debug!("%s", { debug!("Region variance results:"); let region_paramd_items = cx.region_paramd_items; - for region_paramd_items.each |&key, &value| { + for region_paramd_items.iter().advance |(&key, &value)| { debug!("item %? (%s) is parameterized with variance %?", key, ast_map::node_id_to_str(ast_map, key, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3a54c224b52..096ab71e424 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1386,7 +1386,7 @@ impl Resolver { } let def_id = local_def(item.id); - for method_names.each |name, _| { + for method_names.iter().advance |(name, _)| { if !self.method_map.contains_key(name) { self.method_map.insert(*name, HashSet::new()); } @@ -1704,7 +1704,7 @@ impl Resolver { interned_method_names.insert(method_name); } } - for interned_method_names.each |name| { + for interned_method_names.iter().advance |name| { if !self.method_map.contains_key(name) { self.method_map.insert(*name, HashSet::new()); } @@ -2470,8 +2470,8 @@ impl Resolver { assert_eq!(containing_module.glob_count, 0); // Add all resolved imports from the containing module. - for containing_module.import_resolutions.each - |ident, target_import_resolution| { + for containing_module.import_resolutions.iter().advance + |(ident, target_import_resolution)| { debug!("(resolving glob import) writing module resolution \ %? into `%s`", @@ -2555,13 +2555,13 @@ impl Resolver { }; // Add all children from the containing module. - for containing_module.children.each |&ident, name_bindings| { + for containing_module.children.iter().advance |(&ident, name_bindings)| { merge_import_resolution(ident, *name_bindings); } // Add external module children from the containing module. - for containing_module.external_module_children.each - |&ident, module| { + for containing_module.external_module_children.iter().advance + |(&ident, module)| { let name_bindings = @mut Resolver::create_name_bindings_from_module(*module); merge_import_resolution(ident, name_bindings); @@ -3251,7 +3251,7 @@ impl Resolver { pub fn add_exports_for_module(@mut self, exports2: &mut ~[Export2], module_: @mut Module) { - for module_.children.each |ident, namebindings| { + for module_.children.iter().advance |(ident, namebindings)| { debug!("(computing exports) maybe export '%s'", self.session.str_of(*ident)); self.add_exports_of_namebindings(&mut *exports2, @@ -3266,7 +3266,7 @@ impl Resolver { false); } - for module_.import_resolutions.each |ident, importresolution| { + for module_.import_resolutions.iter().advance |(ident, importresolution)| { if importresolution.privacy != Public { debug!("(computing exports) not reexporting private `%s`", self.session.str_of(*ident)); @@ -4039,7 +4039,7 @@ impl Resolver { for arm.pats.iter().enumerate().advance |(i, p)| { let map_i = self.binding_mode_map(*p); - for map_0.each |&key, &binding_0| { + for map_0.iter().advance |(&key, &binding_0)| { match map_i.find(&key) { None => { self.session.span_err( @@ -4060,7 +4060,7 @@ impl Resolver { } } - for map_i.each |&key, &binding| { + for map_i.iter().advance |(&key, &binding)| { if !map_0.contains_key(&key) { self.session.span_err( binding.span, @@ -5355,7 +5355,7 @@ impl Resolver { } debug!("Import resolutions:"); - for module_.import_resolutions.each |name, import_resolution| { + for module_.import_resolutions.iter().advance |(name, import_resolution)| { let value_repr; match import_resolution.target_for_namespace(ValueNS) { None => { value_repr = ~""; } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 71b416ffe85..63b39b8fe76 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1673,7 +1673,7 @@ pub fn trans_match_inner(scope_cx: block, let mut arm_datas = ~[]; let mut matches = ~[]; - for vec::each(arms) |arm| { + for arms.iter().advance |arm| { let body = scope_block(bcx, arm.body.info(), "case_body"); let bindings_map = create_bindings_map(bcx, arm.pats[0]); let arm_data = @ArmData {bodycx: body, diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0e322c187af..5bf0e596ca0 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2945,7 +2945,7 @@ pub fn trans_crate(sess: session::Session, } if ccx.sess.count_llvm_insns() { - for ccx.stats.llvm_insns.each |&k, &v| { + for ccx.stats.llvm_insns.iter().advance |(&k, &v)| { io::println(fmt!("%-7u %s", v, k)); } } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 593d0beb88c..cb475550638 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -704,11 +704,11 @@ pub fn trans_args(cx: block, // now that all arguments have been successfully built, we can revoke any // temporary cleanups, as they are only needed if argument construction // should fail (for example, cleanup of copy mode args). - for vec::each(temp_cleanups) |c| { + for temp_cleanups.iter().advance |c| { revoke_clean(bcx, *c) } - return bcx; + bcx } pub enum AutorefArg { diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index f2446d1a115..8cd776c99d6 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -213,7 +213,8 @@ pub fn type_needs_inner(cx: Context, ty::ty_enum(did, ref substs) => { if list::find(enums_seen, |id| *id == did).is_none() { let seen = @Cons(did, enums_seen); - for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| { + let r = ty::enum_variants(cx.ccx.tcx, did); + for r.iter().advance |v| { for v.args.iter().advance |aty| { let t = ty::subst(cx.ccx.tcx, &(*substs), *aty); type_needs_inner(cx, use_, t, seen); diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index d9add22479c..0aad161a678 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -1285,7 +1285,7 @@ impl RegionVarBindings { // It would be nice to write this using map(): let mut edges = vec::with_capacity(num_edges); - for self.constraints.each |constraint, span| { + for self.constraints.iter().advance |(constraint, span)| { edges.push(GraphEdge { next_edge: [uint::max_value, uint::max_value], constraint: *constraint, diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 20705b3d797..ca49d143d48 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -166,7 +166,7 @@ Available lint options: padded(max_key, "name"), "default", "meaning")); io::println(fmt!(" %s %7.7s %s\n", padded(max_key, "----"), "-------", "-------")); - for lint_dict.each |k, v| { + for lint_dict.iter().advance |(k, v)| { let k = k.replace("_", "-"); io::println(fmt!(" %s %7.7s %s", padded(max_key, k), diff --git a/src/librusti/program.rs b/src/librusti/program.rs index 91fde3e21ae..f17777559de 100644 --- a/src/librusti/program.rs +++ b/src/librusti/program.rs @@ -96,7 +96,7 @@ impl Program { code.push_str("fn main() {\n"); // It's easy to initialize things if we don't run things... - for self.local_vars.each |name, var| { + for self.local_vars.iter().advance |(name, var)| { let mt = var.mt(); code.push_str(fmt!("let%s %s: %s = fail!();\n", mt, *name, var.ty)); var.alter(*name, &mut code); @@ -149,7 +149,7 @@ impl Program { // Using this __tls_map handle, deserialize each variable binding that // we know about - for self.local_vars.each |name, var| { + for self.local_vars.iter().advance |(name, var)| { let mt = var.mt(); code.push_str(fmt!("let%s %s: %s = { let data = __tls_map.get_copy(&~\"%s\"); @@ -175,7 +175,7 @@ impl Program { // After the input code is run, we can re-serialize everything back out // into tls map (to be read later on by this task) - for self.local_vars.each |name, var| { + for self.local_vars.iter().advance |(name, var)| { code.push_str(fmt!("{ let local: %s = %s; let bytes = do ::std::io::with_bytes_writer |io| { @@ -237,7 +237,7 @@ impl Program { /// program starts pub fn set_cache(&self) { let map = @mut HashMap::new(); - for self.local_vars.each |name, value| { + for self.local_vars.iter().advance |(name, value)| { map.insert(copy *name, @copy value.data); } unsafe { diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 962025915d2..bfa0f2fa124 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -488,11 +488,6 @@ impl HashMap { } } - /// Visit all key-value pairs - pub fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool { - self.iter().advance(|(k, v)| blk(k, v)) - } - /// Visit all keys pub fn each_key(&self, blk: &fn(k: &K) -> bool) -> bool { self.iter().advance(|(k, _)| blk(k)) @@ -718,12 +713,6 @@ impl HashSet { self.map.contains_key_equiv(value) } - /// Visit all elements in arbitrary order - /// FIXME: #6978: Remove when all callers are converted - pub fn each(&self, f: &fn(&T) -> bool) -> bool { - self.iter().advance(f) - } - /// An iterator visiting all elements in arbitrary order. /// Iterator element type is &'a T. pub fn iter<'a>(&'a self) -> HashSetIterator<'a, T> { diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 77053f39677..04c0dd79ded 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -111,7 +111,7 @@ fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { assert!(was_present); } pub fn taskset_each(tasks: &TaskSet, blk: &fn(v: *rust_task) -> bool) -> bool { - tasks.each(|k| blk(*k)) + tasks.iter().advance(|k| blk(*k)) } // One of these per group of linked-failure tasks. diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 72b58307849..2e18a588fae 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -444,7 +444,7 @@ pub fn partitioned(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; - for each(v) |elt| { + for v.iter().advance |elt| { if f(elt) { lefts.push(copy *elt); } else { @@ -850,7 +850,7 @@ pub fn grow_set(v: &mut ~[T], index: uint, initval: &T, val: T) { /// Apply a function to each element of a vector and return the results pub fn map(v: &[T], f: &fn(t: &T) -> U) -> ~[U] { let mut result = with_capacity(v.len()); - for each(v) |elem| { + for v.iter().advance |elem| { result.push(f(elem)); } result @@ -886,7 +886,7 @@ pub fn mapi(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] { */ pub fn flat_map(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] { let mut result = ~[]; - for each(v) |elem| { result.push_all_move(f(elem)); } + for v.iter().advance |elem| { result.push_all_move(f(elem)); } result } @@ -939,7 +939,7 @@ pub fn filter_mapped( */ let mut result = ~[]; - for each(v) |elem| { + for v.iter().advance |elem| { match f(elem) { None => {/* no-op */ } Some(result_elem) => { result.push(result_elem); } @@ -974,7 +974,7 @@ pub fn filter(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] { */ pub fn filtered(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; - for each(v) |elem| { + for v.iter().advance |elem| { if f(elem) { result.push(copy *elem); } } result @@ -1058,7 +1058,7 @@ impl<'self, T:Copy> VectorVector for &'self [&'self [T]] { /// Return true if a vector contains an element with the given value pub fn contains(v: &[T], x: &T) -> bool { - for each(v) |elt| { if *x == *elt { return true; } } + for v.iter().advance |elt| { if *x == *elt { return true; } } false } @@ -1209,7 +1209,7 @@ pub fn bsearch_elem(v: &[T], x: &T) -> Option { */ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { let mut (ts, us) = (~[], ~[]); - for each(v) |p| { + for v.iter().advance |p| { let (t, u) = copy *p; ts.push(t); us.push(u); @@ -1347,69 +1347,6 @@ pub fn reversed(v: &const [T]) -> ~[T] { rs } -/** - * Iterates over a vector, yielding each element to a closure. - * - * # Arguments - * - * * `v` - A vector, to be iterated over - * * `f` - A closure to do the iterating. Within this closure, return true to - * * continue iterating, false to break. - * - * # Examples - * - * ~~~ {.rust} - * [1,2,3].each(|&i| { - * io::println(int::str(i)); - * true - * }); - * ~~~ - * - * ~~~ {.rust} - * [1,2,3,4,5].each(|&i| { - * if i < 4 { - * io::println(int::str(i)); - * true - * } - * else { - * false - * } - * }); - * ~~~ - * - * You probably will want to use each with a `for`/`do` expression, depending - * on your iteration needs: - * - * ~~~ {.rust} - * for [1,2,3].each |&i| { - * io::println(int::str(i)); - * } - * ~~~ - */ -#[inline] -pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool { - // ^^^^ - // NB---this CANNOT be &const [T]! The reason - // is that you are passing it to `f()` using - // an immutable. - - let mut broke = false; - do as_imm_buf(v) |p, n| { - let mut n = n; - let mut p = p; - while n > 0u { - unsafe { - let q = cast::copy_lifetime_vec(v, &*p); - if !f(q) { break; } - p = ptr::offset(p, 1u); - } - n -= 1u; - } - broke = n > 0; - } - return !broke; -} - /** * Iterate over all permutations of vector `v`. * @@ -3069,36 +3006,6 @@ mod tests { assert_eq!(v, ~[1, 3, 5]); } - #[test] - fn test_each_empty() { - for each::([]) |_v| { - fail!(); // should never be executed - } - } - - #[test] - fn test_each_nonempty() { - let mut i = 0; - for each([1, 2, 3]) |v| { - i += *v; - } - assert_eq!(i, 6); - } - - #[test] - fn test_each_ret_len0() { - let a0 : [int, .. 0] = []; - assert_eq!(each(a0, |_p| fail!()), true); - } - - #[test] - fn test_each_ret_len1() { - let a1 = [17]; - assert_eq!(each(a1, |_p| true), true); - assert_eq!(each(a1, |_p| false), false); - } - - #[test] fn test_each_permutation() { let mut results: ~[~[int]]; @@ -3854,21 +3761,6 @@ mod tests { }; } - #[test] - #[ignore(windows)] - #[should_fail] - fn test_each_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do each(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - #[test] #[ignore(windows)] #[should_fail] diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 14aa65219cd..d21888f12ec 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -86,7 +86,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph { HashSet::new() }; - for vec::each(edges) |e| { + for edges.iter().advance |e| { match *e { (i, j) => { graph[i].insert(j); @@ -441,7 +441,7 @@ fn main() { let stop = time::precise_time_s(); let mut total_edges = 0; - vec::each(graph, |edges| { total_edges += edges.len(); true }); + for graph.iter().advance |edges| { total_edges += edges.len(); } io::stdout().write_line(fmt!("Generated graph with %? edges in %? seconds.", total_edges / 2, diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 7a9be754884..102f7f17065 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -83,7 +83,7 @@ fn run(args: &[~str]) { server(&from_parent, &to_parent); } - for vec::each(worker_results) |r| { + for worker_results.iter().advance |r| { r.recv(); } diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 796072c8485..b8d91bb93e2 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -79,7 +79,7 @@ fn run(args: &[~str]) { server(&from_parent, &to_parent); } - for vec::each(worker_results) |r| { + for worker_results.iter().advance |r| { r.recv(); } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 3ff123b027a..96c7e4e9b37 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -188,7 +188,7 @@ fn rendezvous(nn: uint, set: ~[color]) { // save each creature's meeting stats let mut report = ~[]; - for vec::each(to_creature) |_to_one| { + for to_creature.iter().advance |_to_one| { report.push(from_creatures_log.recv()); } @@ -196,7 +196,7 @@ fn rendezvous(nn: uint, set: ~[color]) { io::println(show_color_list(set)); // print each creature's stats - for vec::each(report) |rep| { + for report.iter().advance |rep| { io::println(*rep); } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index c33c2258864..20042aa0e91 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -56,7 +56,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { let mut pairs = ~[]; // map -> [(k,%)] - for mm.each |&key, &val| { + for mm.iter().advance |(&key, &val)| { pairs.push((key, pct(val, total))); } diff --git a/src/test/compile-fail/block-must-not-have-result-for.rs b/src/test/compile-fail/block-must-not-have-result-for.rs index 778309122cb..1aa05a9477d 100644 --- a/src/test/compile-fail/block-must-not-have-result-for.rs +++ b/src/test/compile-fail/block-must-not-have-result-for.rs @@ -8,10 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - fn main() { - for vec::each(~[0]) |_i| { //~ ERROR A for-loop body must return (), but + for 2.times { //~ ERROR A for-loop body must return (), but true } } diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index 1a0bec7d723..189a0ef9d70 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -16,7 +16,7 @@ struct Foo { impl Foo { pub fn foo(&mut self, fun: &fn(&int)) { - for self.n.each |f| { + for self.n.iter().advance |f| { fun(f); } } diff --git a/src/test/compile-fail/issue-2151.rs b/src/test/compile-fail/issue-2151.rs index 8f4bbe4eabc..5559ba344ed 100644 --- a/src/test/compile-fail/issue-2151.rs +++ b/src/test/compile-fail/issue-2151.rs @@ -8,10 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - fn main() { - for vec::each(fail!()) |i| { - let _ = i * 2; //~ ERROR the type of this value must be known - }; + let x = fail!(); + x.clone(); //~ ERROR the type of this value must be known in this context } diff --git a/src/test/compile-fail/liveness-issue-2163.rs b/src/test/compile-fail/liveness-issue-2163.rs index ec4f3f9a3fd..fbb6d03b220 100644 --- a/src/test/compile-fail/liveness-issue-2163.rs +++ b/src/test/compile-fail/liveness-issue-2163.rs @@ -12,7 +12,7 @@ use std::vec; fn main() { let a: ~[int] = ~[]; - vec::each(a, |_| -> bool { + a.iter().advance(|_| -> bool { //~^ ERROR mismatched types }); } diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 5d2341ae42d..b65b18e1ab3 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -12,21 +12,19 @@ // making method calls, but only if there aren't any matches without // it. -use std::vec; - trait iterable { fn iterate(&self, blk: &fn(x: &A) -> bool) -> bool; } impl<'self,A> iterable for &'self [A] { fn iterate(&self, f: &fn(x: &A) -> bool) -> bool { - vec::each(*self, f) + self.iter().advance(f) } } impl iterable for ~[A] { fn iterate(&self, f: &fn(x: &A) -> bool) -> bool { - vec::each(*self, f) + self.iter().advance(f) } } diff --git a/src/test/run-pass/auto-loop.rs b/src/test/run-pass/auto-loop.rs index f148c509d4d..185a5a6407c 100644 --- a/src/test/run-pass/auto-loop.rs +++ b/src/test/run-pass/auto-loop.rs @@ -8,11 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - pub fn main() { let mut sum = 0; - for vec::each(~[1, 2, 3, 4, 5]) |x| { + let xs = ~[1, 2, 3, 4, 5]; + for xs.iter().advance |x| { sum += *x; } assert_eq!(sum, 15); diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index d860c84dfce..ff5d0e9f05c 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -15,7 +15,7 @@ pub fn main() { let v = ~[-1f, 0f, 1f, 2f, 3f]; // Statement form does not require parentheses: - for vec::each(v) |i| { + for v.iter().advance |i| { info!("%?", *i); } diff --git a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs index d63ebf7d24d..8f74e6cdc29 100644 --- a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs +++ b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs @@ -8,12 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::vec; - fn want_slice(v: &[int]) -> int { let mut sum = 0; - for vec::each(v) |i| { sum += *i; } - return sum; + for v.iter().advance |i| { sum += *i; } + sum } fn has_mut_vec(v: ~[int]) -> int { diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs index 2edb270762c..85c6f90a742 100644 --- a/src/test/run-pass/break.rs +++ b/src/test/run-pass/break.rs @@ -16,7 +16,8 @@ pub fn main() { assert_eq!(i, 10); loop { i += 1; if i == 20 { break; } } assert_eq!(i, 20); - for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { + let xs = [1, 2, 3, 4, 5, 6]; + for xs.iter().advance |x| { if *x == 3 { break; } assert!((*x <= 3)); } i = 0; @@ -26,7 +27,8 @@ pub fn main() { i += 1; if i % 2 == 0 { loop; } assert!((i % 2 != 0)); if i >= 10 { break; } } - for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { + let ys = ~[1, 2, 3, 4, 5, 6]; + for ys.iter().advance |x| { if *x % 2 == 0 { loop; } assert!((*x % 2 != 0)); } diff --git a/src/test/run-pass/const-vec-of-fns.rs b/src/test/run-pass/const-vec-of-fns.rs index 9fc68cd1127..a87d8f30e3a 100644 --- a/src/test/run-pass/const-vec-of-fns.rs +++ b/src/test/run-pass/const-vec-of-fns.rs @@ -23,6 +23,6 @@ struct S<'self>(&'self fn()); static closures: &'static [S<'static>] = &[S(f), S(f)]; pub fn main() { - for std::vec::each(bare_fns) |&bare_fn| { bare_fn() } - for std::vec::each(closures) |&closure| { (*closure)() } + for bare_fns.iter().advance |&bare_fn| { bare_fn() } + for closures.iter().advance |&closure| { (*closure)() } } diff --git a/src/test/run-pass/for-destruct.rs b/src/test/run-pass/for-destruct.rs index 4926dbd0086..dd1cda22e65 100644 --- a/src/test/run-pass/for-destruct.rs +++ b/src/test/run-pass/for-destruct.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// xfail-test: #3511: does not currently compile, due to rvalue issues + use std::vec; struct Pair { x: int, y: int } - pub fn main() { for vec::each(~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]) |elt| { assert_eq!(elt.x + elt.y, 30); diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index 5eaf12f6a51..b62475ded54 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -18,7 +18,7 @@ trait sum { impl<'self> sum for &'self [int] { fn sum(self) -> int { let mut sum = 0; - for vec::each(self) |e| { sum += *e; } + for self.iter().advance |e| { sum += *e; } return sum; } } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index c25cdc85cb6..dc6bdbf5c1a 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -31,7 +31,10 @@ trait map { impl map for ~[T] { fn map(&self, f: &fn(&T) -> U) -> ~[U] { let mut r = ~[]; - for std::vec::each(*self) |x| { r += ~[f(x)]; } + // FIXME: #7355 generates bad code with Iterator + for std::uint::range(0, self.len()) |i| { + r += ~[f(&self[i])]; + } r } } -- cgit 1.4.1-3-g733a5 From c109bed15b79c81fed4277abd0f4a71a221224c1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 25 Jun 2013 17:02:03 -0700 Subject: Deny common lints by default for lib{std,extra} --- mk/target.mk | 13 +++++++++++-- src/libextra/term.rs | 14 +++++++------- src/libstd/libc.rs | 2 +- src/libstd/os.rs | 21 ++++++++------------- src/libstd/rt/thread_local_storage.rs | 4 ++-- src/libstd/run.rs | 5 ++--- src/libstd/task/spawn.rs | 2 +- src/libstd/to_str.rs | 4 ++-- src/libstd/unstable/dynamic_lib.rs | 3 +-- 9 files changed, 35 insertions(+), 33 deletions(-) (limited to 'src/libstd/task') diff --git a/mk/target.mk b/mk/target.mk index 737b3b82c00..47ab7c86728 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -13,6 +13,15 @@ # this exists can be found on issue #2400 export CFG_COMPILER_TRIPLE +# The standard libraries should be held up to a higher standard than any old +# code, make sure that these common warnings are denied by default. These can +# be overridden during development temporarily. For stage0, we allow all these +# to suppress warnings which may be bugs in stage0 (should be fixed in stage1+) +# NOTE: add "-A warnings" after snapshot to WFLAGS_ST0 +WFLAGS_ST0 = -A unrecognized-lint +WFLAGS_ST1 = -D warnings +WFLAGS_ST2 = -D warnings + # TARGET_STAGE_N template: This defines how target artifacts are built # for all stage/target architecture combinations. The arguments: # $(1) is the stage @@ -39,7 +48,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)): \ $$(TSREQ$(1)_T_$(2)_H_$(3)) \ | $$(TLIB$(1)_T_$(2)_H_$(3))/ @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \ $$(EXTRALIB_CRATE) $$(EXTRALIB_INPUTS) \ @@ -47,7 +56,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \ $$(TSREQ$(1)_T_$(2)_H_$(3)) \ | $$(TLIB$(1)_T_$(2)_H_$(3))/ @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@ + $$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) -o $$@ $$< && touch $$@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \ $$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \ diff --git a/src/libextra/term.rs b/src/libextra/term.rs index 17d80ded47f..782a73deadf 100644 --- a/src/libextra/term.rs +++ b/src/libextra/term.rs @@ -15,12 +15,12 @@ use core::prelude::*; use core::io; -use core::os; -use terminfo::*; -use terminfo::searcher::open; -use terminfo::parser::compiled::parse; -use terminfo::parm::{expand, Number, Variables}; +#[cfg(not(target_os = "win32"))] use core::os; +#[cfg(not(target_os = "win32"))] use terminfo::*; +#[cfg(not(target_os = "win32"))] use terminfo::searcher::open; +#[cfg(not(target_os = "win32"))] use terminfo::parser::compiled::parse; +#[cfg(not(target_os = "win32"))] use terminfo::parm::{expand, Number, Variables}; // FIXME (#2807): Windows support. @@ -122,10 +122,10 @@ impl Terminal { return Ok(Terminal {out: out, color_supported: false}); } - pub fn fg(&self, color: u8) { + pub fn fg(&self, _color: u8) { } - pub fn bg(&self, color: u8) { + pub fn bg(&self, _color: u8) { } pub fn reset(&self) { diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 523645e69a5..3c2ae93b656 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -568,7 +568,7 @@ pub mod types { pub mod os { pub mod common { pub mod posix01 { - use libc::types::os::arch::c95::{c_int, c_short}; + use libc::types::os::arch::c95::c_short; use libc::types::os::arch::extra::{int64, time64_t}; use libc::types::os::arch::posix88::{dev_t, ino_t}; use libc::types::os::arch::posix88::mode_t; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index e6b92c0ccc3..112540c405d 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -33,9 +33,8 @@ use io; use iterator::IteratorUtil; use libc; use libc::{c_char, c_void, c_int, size_t}; -use libc::{mode_t, FILE}; +use libc::FILE; use local_data; -use option; use option::{Some, None}; use os; use prelude::*; @@ -181,7 +180,6 @@ pub fn env() -> ~[(~str,~str)] { unsafe { #[cfg(windows)] unsafe fn get_env_pairs() -> ~[~str] { - use libc::types::os::arch::extra::LPTCH; use libc::funcs::extra::kernel32::{ GetEnvironmentStringsA, FreeEnvironmentStringsA @@ -248,10 +246,10 @@ pub fn getenv(n: &str) -> Option<~str> { do with_env_lock { let s = str::as_c_str(n, |s| libc::getenv(s)); if ptr::null::() == cast::transmute(s) { - option::None::<~str> + None::<~str> } else { let s = cast::transmute(s); - option::Some::<~str>(str::raw::from_buf(s)) + Some::<~str>(str::raw::from_buf(s)) } } } @@ -540,7 +538,7 @@ pub fn homedir() -> Option { #[cfg(windows)] fn secondary() -> Option { - do getenv(~"USERPROFILE").chain |p| { + do getenv("USERPROFILE").chain |p| { if !p.is_empty() { Some(Path(p)) } else { @@ -647,9 +645,7 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool { use os::win32::as_utf16_p; // FIXME: turn mode into something useful? #2623 do as_utf16_p(p.to_str()) |buf| { - libc::CreateDirectoryW(buf, unsafe { - cast::transmute(0) - }) + libc::CreateDirectoryW(buf, cast::transmute(0)) != (0 as libc::BOOL) } } @@ -659,7 +655,7 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool { fn mkdir(p: &Path, mode: c_int) -> bool { unsafe { do as_c_charp(p.to_str()) |c| { - libc::mkdir(c, mode as mode_t) == (0 as c_int) + libc::mkdir(c, mode as libc::mode_t) == (0 as c_int) } } } @@ -732,7 +728,6 @@ pub fn list_dir(p: &Path) -> ~[~str] { } #[cfg(windows)] unsafe fn get_list(p: &Path) -> ~[~str] { - use libc::types::os::arch::extra::{LPCTSTR, HANDLE, BOOL}; use libc::consts::os::extra::INVALID_HANDLE_VALUE; use libc::wcslen; use libc::funcs::extra::kernel32::{ @@ -961,7 +956,7 @@ pub fn copy_file(from: &Path, to: &Path) -> bool { // Give the new file the old file's permissions if do str::as_c_str(to.to_str()) |to_buf| { - libc::chmod(to_buf, from_mode as mode_t) + libc::chmod(to_buf, from_mode as libc::mode_t) } != 0 { return false; // should be a condition... } @@ -1329,7 +1324,7 @@ pub fn glob(pattern: &str) -> ~[Path] { /// Returns a vector of Path objects that match the given glob pattern #[cfg(target_os = "win32")] -pub fn glob(pattern: &str) -> ~[Path] { +pub fn glob(_pattern: &str) -> ~[Path] { fail!("glob() is unimplemented on Windows") } diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs index 7187d2db41c..5041b559ecb 100644 --- a/src/libstd/rt/thread_local_storage.rs +++ b/src/libstd/rt/thread_local_storage.rs @@ -60,13 +60,13 @@ pub type Key = DWORD; #[cfg(windows)] pub unsafe fn create(key: &mut Key) { static TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF; - *key = unsafe { TlsAlloc() }; + *key = TlsAlloc(); assert!(*key != TLS_OUT_OF_INDEXES); } #[cfg(windows)] pub unsafe fn set(key: Key, value: *mut c_void) { - unsafe { assert!(0 != TlsSetValue(key, value)) } + assert!(0 != TlsSetValue(key, value)) } #[cfg(windows)] diff --git a/src/libstd/run.rs b/src/libstd/run.rs index c965af7c10c..32368312e15 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -12,11 +12,10 @@ #[allow(missing_doc)]; -use iterator::IteratorUtil; use cast; use comm::{stream, SharedChan, GenericChan, GenericPort}; -use int; use io; +use iterator::IteratorUtil; use libc::{pid_t, c_void, c_int}; use libc; use option::{Some, None}; @@ -465,7 +464,6 @@ fn spawn_process_os(prog: &str, args: &[~str], use libc::funcs::extra::msvcrt::get_osfhandle; use sys; - use uint; unsafe { @@ -638,6 +636,7 @@ fn spawn_process_os(prog: &str, args: &[~str], use libc::funcs::posix88::unistd::{fork, dup2, close, chdir, execvp}; use libc::funcs::bsd44::getdtablesize; + use int; mod rustrt { use libc::c_void; diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 77053f39677..94349c75af9 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -91,7 +91,7 @@ use uint; use util; use unstable::sync::{Exclusive, exclusive}; use rt::local::Local; -use iterator::{IteratorUtil}; +use iterator::IteratorUtil; #[cfg(test)] use task::default_task_opts; #[cfg(test)] use comm; diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 4d5bc0f8842..ea0e212b14f 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -17,8 +17,8 @@ The `ToStr` trait for converting to strings use str::OwnedStr; use hashmap::HashMap; use hashmap::HashSet; -use iterator::IteratorUtil; use hash::Hash; +use iterator::IteratorUtil; use cmp::Eq; use vec::ImmutableVector; @@ -177,7 +177,7 @@ impl ToStr for @[A] { mod tests { use hashmap::HashMap; use hashmap::HashSet; - use container::{Set,Map}; + use container::{Set, Map}; #[test] fn test_simple_types() { assert_eq!(1i.to_str(), ~"1"); diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index 64dd5bba6bc..61793977e7a 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -164,7 +164,6 @@ mod dl { use libc; use path; use ptr; - use str; use task; use result::*; @@ -175,7 +174,7 @@ mod dl { } pub unsafe fn open_internal() -> *libc::c_void { - let mut handle = ptr::null(); + let handle = ptr::null(); GetModuleHandleExW(0 as libc::DWORD, ptr::null(), &handle as **libc::c_void); handle } -- cgit 1.4.1-3-g733a5 From ca2966c6d04958241f13e61310298a5ff69061e2 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 20 Jun 2013 21:06:13 -0400 Subject: Change finalize -> drop. --- doc/tutorial-ffi.md | 2 +- doc/tutorial.md | 6 +++--- src/etc/vim/syntax/rust.vim | 2 +- src/libextra/arc.rs | 2 +- src/libextra/arena.rs | 2 +- src/libextra/c_vec.rs | 2 +- src/libextra/future.rs | 2 +- src/libextra/net_tcp.rs | 2 +- src/libextra/rc.rs | 4 ++-- src/libextra/sort.rs | 2 +- src/libextra/sync.rs | 16 ++++++++-------- src/libextra/task_pool.rs | 2 +- src/librustc/back/passes.rs | 2 +- src/librustc/lib/llvm.rs | 8 ++++---- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/trans/common.rs | 2 +- src/librustc/middle/trans/context.rs | 2 +- src/librustc/rustc.rs | 2 +- src/librustc/util/common.rs | 2 +- src/librustdoc/demo.rs | 2 +- src/libstd/condition.rs | 2 +- src/libstd/io.rs | 6 +++--- src/libstd/ops.rs | 2 +- src/libstd/option.rs | 2 +- src/libstd/pipes.rs | 6 +++--- src/libstd/rt/comm.rs | 4 ++-- src/libstd/rt/local_heap.rs | 2 +- src/libstd/rt/rc.rs | 2 +- src/libstd/rt/stack.rs | 2 +- src/libstd/rt/task.rs | 2 +- src/libstd/rt/thread.rs | 2 +- src/libstd/rt/uv/uvio.rs | 6 +++--- src/libstd/rt/uvio.rs | 6 +++--- src/libstd/run.rs | 2 +- src/libstd/task/spawn.rs | 4 ++-- src/libstd/unstable/atomics.rs | 2 +- src/libstd/unstable/dynamic_lib.rs | 2 +- src/libstd/unstable/finally.rs | 2 +- src/libstd/unstable/global.rs | 2 +- src/libstd/unstable/sync.rs | 4 ++-- src/libstd/util.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/test/auxiliary/issue-2526.rs | 4 ++-- src/test/auxiliary/issue-3012-1.rs | 2 +- src/test/auxiliary/issue2170lib.rs | 2 +- src/test/auxiliary/moves_based_on_type_lib.rs | 2 +- src/test/bench/task-perf-alloc-unwind.rs | 2 +- ...y-move-neither-can-live-while-the-other-survives-1.rs | 2 +- ...y-move-neither-can-live-while-the-other-survives-2.rs | 2 +- ...y-move-neither-can-live-while-the-other-survives-3.rs | 2 +- ...y-move-neither-can-live-while-the-other-survives-4.rs | 2 +- src/test/compile-fail/bind-by-move-no-lvalues-1.rs | 2 +- src/test/compile-fail/bind-by-move-no-lvalues-2.rs | 2 +- src/test/compile-fail/bind-by-move-no-sub-bindings.rs | 2 +- src/test/compile-fail/block-must-not-have-result-res.rs | 2 +- src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs | 2 +- src/test/compile-fail/copy-a-resource.rs | 2 +- .../disallowed-deconstructing-destructing-struct-let.rs | 2 +- ...disallowed-deconstructing-destructing-struct-match.rs | 2 +- src/test/compile-fail/drop-on-non-struct.rs | 2 +- src/test/compile-fail/explicit-call-to-dtor.rs | 4 ++-- .../compile-fail/explicit-call-to-supertrait-dtor.rs | 4 ++-- src/test/compile-fail/issue-2548.rs | 2 +- src/test/compile-fail/issue-2823.rs | 2 +- src/test/compile-fail/issue-3214.rs | 2 +- src/test/compile-fail/kindck-destructor-owned.rs | 2 +- src/test/compile-fail/no-send-res-ports.rs | 2 +- src/test/compile-fail/noncopyable-class.rs | 2 +- src/test/compile-fail/pinned-deep-copy.rs | 2 +- src/test/compile-fail/repeat-to-run-dtor-twice.rs | 2 +- src/test/compile-fail/unique-object-noncopyable.rs | 2 +- src/test/compile-fail/unique-pinned-nocopy.rs | 2 +- src/test/compile-fail/unique-vec-res.rs | 2 +- .../compile-fail/use-after-move-self-based-on-type.rs | 2 +- src/test/compile-fail/vec-res-add.rs | 2 +- src/test/run-fail/issue-2061.rs | 2 +- src/test/run-fail/morestack2.rs | 2 +- src/test/run-fail/morestack3.rs | 2 +- src/test/run-fail/morestack4.rs | 2 +- src/test/run-fail/rt-set-exit-status-fail2.rs | 2 +- src/test/run-fail/too-much-recursion-unwinding.rs | 2 +- src/test/run-fail/unwind-box-res.rs | 2 +- src/test/run-fail/unwind-resource-fail.rs | 2 +- src/test/run-fail/unwind-resource-fail2.rs | 2 +- src/test/run-fail/unwind-resource-fail3.rs | 2 +- src/test/run-pass/attr-no-drop-flag-size.rs | 2 +- src/test/run-pass/borrowck-unary-move-2.rs | 2 +- src/test/run-pass/class-attributes-1.rs | 2 +- src/test/run-pass/class-attributes-2.rs | 2 +- src/test/run-pass/class-dtor.rs | 2 +- src/test/run-pass/drop-trait-generic.rs | 2 +- src/test/run-pass/drop-trait.rs | 2 +- src/test/run-pass/init-res-into-things.rs | 2 +- src/test/run-pass/issue-2487-a.rs | 2 +- src/test/run-pass/issue-2708.rs | 2 +- src/test/run-pass/issue-2718.rs | 4 ++-- src/test/run-pass/issue-2735-2.rs | 2 +- src/test/run-pass/issue-2735-3.rs | 2 +- src/test/run-pass/issue-2895.rs | 2 +- src/test/run-pass/issue-3220.rs | 2 +- src/test/run-pass/issue-3563-3.rs | 2 +- src/test/run-pass/issue-4252.rs | 2 +- src/test/run-pass/issue-4735.rs | 2 +- src/test/run-pass/issue-6341.rs | 2 +- src/test/run-pass/issue-6344-let.rs | 2 +- src/test/run-pass/issue-6344-match.rs | 2 +- src/test/run-pass/issue-979.rs | 2 +- src/test/run-pass/newtype-struct-drop-run.rs | 2 +- src/test/run-pass/newtype-struct-with-dtor.rs | 2 +- src/test/run-pass/option-unwrap.rs | 2 +- src/test/run-pass/pipe-presentation-examples.rs | 2 +- src/test/run-pass/resource-assign-is-not-copy.rs | 2 +- src/test/run-pass/resource-cycle.rs | 2 +- src/test/run-pass/resource-cycle2.rs | 2 +- src/test/run-pass/resource-cycle3.rs | 2 +- src/test/run-pass/resource-destruct.rs | 2 +- src/test/run-pass/resource-generic.rs | 2 +- src/test/run-pass/resource-in-struct.rs | 2 +- src/test/run-pass/send-resource.rs | 2 +- src/test/run-pass/struct-literal-dtor.rs | 2 +- src/test/run-pass/task-killjoin-rsrc.rs | 2 +- src/test/run-pass/type-param-constraints.rs | 2 +- src/test/run-pass/unique-pinned-nocopy-2.rs | 2 +- src/test/run-pass/unit-like-struct-drop-run.rs | 2 +- src/test/run-pass/unwind-resource.rs | 2 +- src/test/run-pass/unwind-resource2.rs | 2 +- src/test/run-pass/vec-slice-drop.rs | 2 +- 127 files changed, 155 insertions(+), 155 deletions(-) (limited to 'src/libstd/task') diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index d3c682ce1ad..346112e655b 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -183,7 +183,7 @@ impl Unique { #[unsafe_destructor] impl Drop for Unique { - fn finalize(&self) { + fn drop(&self) { unsafe { let x = intrinsics::init(); // dummy value to swap in // moving the object out is needed to call the destructor diff --git a/doc/tutorial.md b/doc/tutorial.md index 9c61a04930a..c18cca8d5a2 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1979,7 +1979,7 @@ types by the compiler, and may not be overridden: > iterations of the language, and often still are. Additionally, the `Drop` trait is used to define destructors. This -trait defines one method called `finalize`, which is automatically +trait defines one method called `drop`, which is automatically called when a value of the type that implements this trait is destroyed, either because the value went out of scope or because the garbage collector reclaimed it. @@ -1990,7 +1990,7 @@ struct TimeBomb { } impl Drop for TimeBomb { - fn finalize(&self) { + fn drop(&self) { for self.explosivity.times { println("blam!"); } @@ -1998,7 +1998,7 @@ impl Drop for TimeBomb { } ~~~ -It is illegal to call `finalize` directly. Only code inserted by the compiler +It is illegal to call `drop` directly. Only code inserted by the compiler may call it. ## Declaring and implementing traits diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 625424ac870..db64e0eb719 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -15,7 +15,7 @@ syn keyword rustOperator as syn match rustAssert "\ (), option::Some(f) => f() diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 4652e1d6477..19e4d221d33 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -44,7 +44,7 @@ pub struct Future { // over ~fn's that have pipes and so forth within! #[unsafe_destructor] impl Drop for Future { - fn finalize(&self) {} + fn drop(&self) {} } priv enum FutureState { diff --git a/src/libextra/net_tcp.rs b/src/libextra/net_tcp.rs index d4434012178..6ad51931c67 100644 --- a/src/libextra/net_tcp.rs +++ b/src/libextra/net_tcp.rs @@ -57,7 +57,7 @@ pub struct TcpSocket { #[unsafe_destructor] impl Drop for TcpSocket { - fn finalize(&self) { + fn drop(&self) { tear_down_socket_data(self.socket_data) } } diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index 555cceb5b44..8ef58a188d9 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -68,7 +68,7 @@ impl Rc { #[unsafe_destructor] impl Drop for Rc { - fn finalize(&self) { + fn drop(&self) { unsafe { if self.ptr.is_not_null() { (*self.ptr).count -= 1; @@ -220,7 +220,7 @@ impl RcMut { #[unsafe_destructor] impl Drop for RcMut { - fn finalize(&self) { + fn drop(&self) { unsafe { if self.ptr.is_not_null() { (*self.ptr).count -= 1; diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index ae2a5c01993..3c872d64ca0 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -1207,7 +1207,7 @@ mod big_tests { #[unsafe_destructor] impl<'self> Drop for LVal<'self> { - fn finalize(&self) { + fn drop(&self) { let x = unsafe { local_data::local_data_get(self.key) }; match x { Some(@y) => { diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 6990d35f061..63fde546047 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -176,7 +176,7 @@ struct SemReleaseGeneric<'self, Q> { sem: &'self Sem } #[doc(hidden)] #[unsafe_destructor] impl<'self, Q:Owned> Drop for SemReleaseGeneric<'self, Q> { - fn finalize(&self) { + fn drop(&self) { self.sem.release(); } } @@ -219,7 +219,7 @@ pub struct Condvar<'self> { } #[unsafe_destructor] -impl<'self> Drop for Condvar<'self> { fn finalize(&self) {} } +impl<'self> Drop for Condvar<'self> { fn drop(&self) {} } impl<'self> Condvar<'self> { /** @@ -295,7 +295,7 @@ impl<'self> Condvar<'self> { #[unsafe_destructor] impl<'self> Drop for CondvarReacquire<'self> { - fn finalize(&self) { + fn drop(&self) { unsafe { // Needs to succeed, instead of itself dying. do task::unkillable { @@ -689,7 +689,7 @@ struct RWlockReleaseRead<'self> { #[doc(hidden)] #[unsafe_destructor] impl<'self> Drop for RWlockReleaseRead<'self> { - fn finalize(&self) { + fn drop(&self) { unsafe { do task::unkillable { let state = &mut *self.lock.state.get(); @@ -726,7 +726,7 @@ struct RWlockReleaseDowngrade<'self> { #[doc(hidden)] #[unsafe_destructor] impl<'self> Drop for RWlockReleaseDowngrade<'self> { - fn finalize(&self) { + fn drop(&self) { unsafe { do task::unkillable { let writer_or_last_reader; @@ -769,12 +769,12 @@ fn RWlockReleaseDowngrade<'r>(lock: &'r RWlock) /// The "write permission" token used for rwlock.write_downgrade(). pub struct RWlockWriteMode<'self> { priv lock: &'self RWlock } #[unsafe_destructor] -impl<'self> Drop for RWlockWriteMode<'self> { fn finalize(&self) {} } +impl<'self> Drop for RWlockWriteMode<'self> { fn drop(&self) {} } /// The "read permission" token used for rwlock.write_downgrade(). pub struct RWlockReadMode<'self> { priv lock: &'self RWlock } #[unsafe_destructor] -impl<'self> Drop for RWlockReadMode<'self> { fn finalize(&self) {} } +impl<'self> Drop for RWlockReadMode<'self> { fn drop(&self) {} } impl<'self> RWlockWriteMode<'self> { /// Access the pre-downgrade rwlock in write mode. @@ -1104,7 +1104,7 @@ mod tests { } impl Drop for SendOnFailure { - fn finalize(&self) { + fn drop(&self) { self.c.send(()); } } diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index 643081d4a7a..6a715d7b481 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -35,7 +35,7 @@ pub struct TaskPool { #[unsafe_destructor] impl Drop for TaskPool { - fn finalize(&self) { + fn drop(&self) { for self.channels.iter().advance |channel| { channel.send(Quit); } diff --git a/src/librustc/back/passes.rs b/src/librustc/back/passes.rs index 2c994fbc3fc..fa261a977f5 100644 --- a/src/librustc/back/passes.rs +++ b/src/librustc/back/passes.rs @@ -23,7 +23,7 @@ pub struct PassManager { } impl Drop for PassManager { - fn finalize(&self) { + fn drop(&self) { unsafe { llvm::LLVMDisposePassManager(self.llpm); } diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 4bc96117ff5..d7f33dcf0d0 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -2216,7 +2216,7 @@ pub struct target_data_res { } impl Drop for target_data_res { - fn finalize(&self) { + fn drop(&self) { unsafe { llvm::LLVMDisposeTargetData(self.TD); } @@ -2253,7 +2253,7 @@ pub struct pass_manager_res { } impl Drop for pass_manager_res { - fn finalize(&self) { + fn drop(&self) { unsafe { llvm::LLVMDisposePassManager(self.PM); } @@ -2289,7 +2289,7 @@ pub struct object_file_res { } impl Drop for object_file_res { - fn finalize(&self) { + fn drop(&self) { unsafe { llvm::LLVMDisposeObjectFile(self.ObjectFile); } @@ -2326,7 +2326,7 @@ pub struct section_iter_res { } impl Drop for section_iter_res { - fn finalize(&self) { + fn drop(&self) { unsafe { llvm::LLVMDisposeSectionIterator(self.SI); } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0e322c187af..6b826a9b940 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -110,7 +110,7 @@ pub struct _InsnCtxt { _x: () } #[unsafe_destructor] impl Drop for _InsnCtxt { - fn finalize(&self) { + fn drop(&self) { unsafe { do local_data::local_data_modify(task_local_insn_key) |c| { do c.map_consume |@ctx| { diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 7baa3ec068b..442ab475046 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -110,7 +110,7 @@ pub struct BuilderRef_res { } impl Drop for BuilderRef_res { - fn finalize(&self) { + fn drop(&self) { unsafe { llvm::LLVMDisposeBuilder(self.B); } diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 715b1c88327..57cfb1474df 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -241,7 +241,7 @@ impl CrateContext { #[unsafe_destructor] impl Drop for CrateContext { - fn finalize(&self) { + fn drop(&self) { unsafe { unset_task_llcx(); } diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 20705b3d797..899dc85bb8a 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -328,7 +328,7 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) { } impl Drop for finally { - fn finalize(&self) { self.ch.send(done); } + fn drop(&self) { self.ch.send(done); } } let _finally = finally { ch: ch }; diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 0839c2b963b..351519975ad 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -41,7 +41,7 @@ pub struct _indenter { } impl Drop for _indenter { - fn finalize(&self) { debug!("<<"); } + fn drop(&self) { debug!("<<"); } } pub fn _indenter(_i: ()) -> _indenter { diff --git a/src/librustdoc/demo.rs b/src/librustdoc/demo.rs index c5fb8f289f6..9cac958a113 100644 --- a/src/librustdoc/demo.rs +++ b/src/librustdoc/demo.rs @@ -128,7 +128,7 @@ struct Bored { } impl Drop for Bored { - fn finalize(&self) { } + fn drop(&self) { } } /** diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 2f150a0d1b2..04f2d815d08 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -90,7 +90,7 @@ struct Guard<'self, T, U> { #[unsafe_destructor] impl<'self, T, U> Drop for Guard<'self, T, U> { - fn finalize(&self) { + fn drop(&self) { unsafe { debug!("Guard: popping handler from TLS"); let curr = local_data_pop(self.cond.key); diff --git a/src/libstd/io.rs b/src/libstd/io.rs index fc0b4da79bd..71a0dd6b9b2 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -989,7 +989,7 @@ impl FILERes { } impl Drop for FILERes { - fn finalize(&self) { + fn drop(&self) { unsafe { libc::fclose(self.f); } @@ -1234,7 +1234,7 @@ impl FdRes { } impl Drop for FdRes { - fn finalize(&self) { + fn drop(&self) { unsafe { libc::close(self.fd); } @@ -1772,7 +1772,7 @@ pub mod fsync { #[unsafe_destructor] impl Drop for Res { - fn finalize(&self) { + fn drop(&self) { match self.arg.opt_level { None => (), Some(level) => { diff --git a/src/libstd/ops.rs b/src/libstd/ops.rs index 77cfe62e495..020131ab119 100644 --- a/src/libstd/ops.rs +++ b/src/libstd/ops.rs @@ -14,7 +14,7 @@ #[lang="drop"] pub trait Drop { - fn finalize(&self); // FIXME(#4332): Rename to "drop"? --pcwalton + fn drop(&self); } #[lang="add"] diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 88a66249c96..f3ea81f1ae5 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -416,7 +416,7 @@ fn test_unwrap_resource() { #[unsafe_destructor] impl ::ops::Drop for R { - fn finalize(&self) { *(self.i) += 1; } + fn drop(&self) { *(self.i) += 1; } } fn R(i: @mut int) -> R { diff --git a/src/libstd/pipes.rs b/src/libstd/pipes.rs index 26dd4af45d6..661dc2a659f 100644 --- a/src/libstd/pipes.rs +++ b/src/libstd/pipes.rs @@ -309,7 +309,7 @@ struct BufferResource { #[unsafe_destructor] impl Drop for BufferResource { - fn finalize(&self) { + fn drop(&self) { unsafe { // FIXME(#4330) Need self by value to get mutability. let this: &mut BufferResource = transmute_mut(self); @@ -672,7 +672,7 @@ pub struct SendPacketBuffered { #[unsafe_destructor] impl Drop for SendPacketBuffered { - fn finalize(&self) { + fn drop(&self) { unsafe { let this: &mut SendPacketBuffered = transmute(self); if this.p != None { @@ -730,7 +730,7 @@ pub struct RecvPacketBuffered { #[unsafe_destructor] impl Drop for RecvPacketBuffered { - fn finalize(&self) { + fn drop(&self) { unsafe { let this: &mut RecvPacketBuffered = transmute(self); if this.p != None { diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 5d85e292861..75b1d8f3810 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -222,7 +222,7 @@ impl Peekable for PortOne { #[unsafe_destructor] impl Drop for ChanOneHack { - fn finalize(&self) { + fn drop(&self) { if self.suppress_finalize { return } unsafe { @@ -249,7 +249,7 @@ impl Drop for ChanOneHack { #[unsafe_destructor] impl Drop for PortOneHack { - fn finalize(&self) { + fn drop(&self) { if self.suppress_finalize { return } unsafe { diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 6bf228a1b22..c5c22f45159 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -57,7 +57,7 @@ impl LocalHeap { } impl Drop for LocalHeap { - fn finalize(&self) { + fn drop(&self) { unsafe { rust_delete_boxed_region(self.boxed_region); rust_delete_memory_region(self.memory_region); diff --git a/src/libstd/rt/rc.rs b/src/libstd/rt/rc.rs index 2977d081508..18a5dd4a114 100644 --- a/src/libstd/rt/rc.rs +++ b/src/libstd/rt/rc.rs @@ -74,7 +74,7 @@ impl RC { #[unsafe_destructor] impl Drop for RC { - fn finalize(&self) { + fn drop(&self) { assert!(self.refcount() > 0); unsafe { diff --git a/src/libstd/rt/stack.rs b/src/libstd/rt/stack.rs index b0e87a62c8b..fbb516b2df4 100644 --- a/src/libstd/rt/stack.rs +++ b/src/libstd/rt/stack.rs @@ -49,7 +49,7 @@ impl StackSegment { } impl Drop for StackSegment { - fn finalize(&self) { + fn drop(&self) { unsafe { // XXX: Using the FFI to call a C macro. Slow rust_valgrind_stack_deregister(self.valgrind_id); diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 41390aec80c..f5f5aca71f5 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -103,7 +103,7 @@ impl Task { } impl Drop for Task { - fn finalize(&self) { assert!(self.destroyed) } + fn drop(&self) { assert!(self.destroyed) } } // Just a sanity check to make sure we are catching a Rust-thrown exception diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index bc290191310..98d08c060e0 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -33,7 +33,7 @@ impl Thread { } impl Drop for Thread { - fn finalize(&self) { + fn drop(&self) { unsafe { rust_raw_thread_join_delete(self.raw_thread) } } } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 964ee460c1d..15c405bae69 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -47,7 +47,7 @@ impl UvEventLoop { } impl Drop for UvEventLoop { - fn finalize(&self) { + fn drop(&self) { // XXX: Need mutable finalizer let this = unsafe { transmute::<&UvEventLoop, &mut UvEventLoop>(self) @@ -200,7 +200,7 @@ impl UvTcpListener { } impl Drop for UvTcpListener { - fn finalize(&self) { + fn drop(&self) { let watcher = self.watcher(); let scheduler = Local::take::(); do scheduler.deschedule_running_task_and_then |task| { @@ -261,7 +261,7 @@ impl UvTcpStream { } impl Drop for UvTcpStream { - fn finalize(&self) { + fn drop(&self) { rtdebug!("closing tcp stream"); let watcher = self.watcher(); let scheduler = Local::take::(); diff --git a/src/libstd/rt/uvio.rs b/src/libstd/rt/uvio.rs index f4a79934e7e..0187ad3abf5 100644 --- a/src/libstd/rt/uvio.rs +++ b/src/libstd/rt/uvio.rs @@ -42,7 +42,7 @@ impl UvEventLoop { } impl Drop for UvEventLoop { - fn finalize(&self) { + fn drop(&self) { // XXX: Need mutable finalizer let this = unsafe { transmute::<&UvEventLoop, &mut UvEventLoop>(self) @@ -164,7 +164,7 @@ impl UvTcpListener { } impl Drop for UvTcpListener { - fn finalize(&self) { + fn drop(&self) { // XXX: Again, this never gets called. Use .close() instead //self.watcher().as_stream().close(||()); } @@ -230,7 +230,7 @@ impl UvStream { } impl Drop for UvStream { - fn finalize(&self) { + fn drop(&self) { rtdebug!("closing stream"); //self.watcher().close(||()); } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index c965af7c10c..08bb7ee7281 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -428,7 +428,7 @@ impl Process { } impl Drop for Process { - fn finalize(&self) { + fn drop(&self) { // FIXME(#4330) Need self by value to get mutability. let mut_self: &mut Process = unsafe { cast::transmute(self) }; diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 77053f39677..f0e3bda34ea 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -317,7 +317,7 @@ struct TCB { impl Drop for TCB { // Runs on task exit. - fn finalize(&self) { + fn drop(&self) { unsafe { // FIXME(#4330) Need self by value to get mutability. let this: &mut TCB = transmute(self); @@ -372,7 +372,7 @@ struct AutoNotify { } impl Drop for AutoNotify { - fn finalize(&self) { + fn drop(&self) { let result = if self.failed { Failure } else { Success }; self.notify_chan.send(result); } diff --git a/src/libstd/unstable/atomics.rs b/src/libstd/unstable/atomics.rs index 7a3a5f51d35..45eced9846c 100644 --- a/src/libstd/unstable/atomics.rs +++ b/src/libstd/unstable/atomics.rs @@ -276,7 +276,7 @@ impl AtomicOption { #[unsafe_destructor] impl Drop for AtomicOption { - fn finalize(&self) { + fn drop(&self) { // This will ensure that the contained data is // destroyed, unless it's null. unsafe { diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index 64dd5bba6bc..9ea35396915 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -25,7 +25,7 @@ use result::*; pub struct DynamicLibrary { priv handle: *libc::c_void } impl Drop for DynamicLibrary { - fn finalize(&self) { + fn drop(&self) { match do dl::check_for_errors_in { unsafe { dl::close(self.handle) diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs index b15bceddb1c..10db664450e 100644 --- a/src/libstd/unstable/finally.rs +++ b/src/libstd/unstable/finally.rs @@ -64,7 +64,7 @@ struct Finallyalizer<'self> { #[unsafe_destructor] impl<'self> Drop for Finallyalizer<'self> { - fn finalize(&self) { + fn drop(&self) { (self.dtor)(); } } diff --git a/src/libstd/unstable/global.rs b/src/libstd/unstable/global.rs index f81252274c4..4fde8f704b9 100644 --- a/src/libstd/unstable/global.rs +++ b/src/libstd/unstable/global.rs @@ -147,7 +147,7 @@ struct GlobalState { } impl Drop for GlobalState { - fn finalize(&self) { + fn drop(&self) { for self.map.each_value |v| { match v { &(_, ref dtor) => (*dtor)() diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index 235dfa01849..0f9298595ee 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -75,7 +75,7 @@ impl Clone for UnsafeAtomicRcBox { #[unsafe_destructor] impl Drop for UnsafeAtomicRcBox{ - fn finalize(&self) { + fn drop(&self) { unsafe { do task::unkillable { let mut data: ~AtomicRcBoxData = cast::transmute(self.data); @@ -102,7 +102,7 @@ struct LittleLock { } impl Drop for LittleLock { - fn finalize(&self) { + fn drop(&self) { unsafe { rust_destroy_little_lock(self.l); } diff --git a/src/libstd/util.rs b/src/libstd/util.rs index 2a5d44c9ce2..6eddae17ce6 100644 --- a/src/libstd/util.rs +++ b/src/libstd/util.rs @@ -83,7 +83,7 @@ impl NonCopyable { } impl Drop for NonCopyable { - fn finalize(&self) { } + fn drop(&self) { } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d8aab1f68ee..d8829da3b31 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -268,7 +268,7 @@ pub struct Parser { #[unsafe_destructor] impl Drop for Parser { /* do not copy the parser; its state is tied to outside state */ - fn finalize(&self) {} + fn drop(&self) {} } impl Parser { diff --git a/src/test/auxiliary/issue-2526.rs b/src/test/auxiliary/issue-2526.rs index bbc0f1ad3e5..d4f6a1ec404 100644 --- a/src/test/auxiliary/issue-2526.rs +++ b/src/test/auxiliary/issue-2526.rs @@ -21,7 +21,7 @@ struct arc_destruct { #[unsafe_destructor] impl Drop for arc_destruct { - fn finalize(&self) {} + fn drop(&self) {} } fn arc_destruct(data: int) -> arc_destruct { @@ -45,7 +45,7 @@ struct context_res { } impl Drop for context_res { - fn finalize(&self) {} + fn drop(&self) {} } fn context_res() -> context_res { diff --git a/src/test/auxiliary/issue-3012-1.rs b/src/test/auxiliary/issue-3012-1.rs index ce40afff3ae..9c9b3d9f243 100644 --- a/src/test/auxiliary/issue-3012-1.rs +++ b/src/test/auxiliary/issue-3012-1.rs @@ -19,7 +19,7 @@ pub mod socket { } impl Drop for socket_handle { - fn finalize(&self) { + fn drop(&self) { /* c::close(self.sockfd); */ } } diff --git a/src/test/auxiliary/issue2170lib.rs b/src/test/auxiliary/issue2170lib.rs index 0690a017449..ec5d8baf259 100644 --- a/src/test/auxiliary/issue2170lib.rs +++ b/src/test/auxiliary/issue2170lib.rs @@ -16,7 +16,7 @@ pub struct rsrc { } impl Drop for rsrc { - fn finalize(&self) { + fn drop(&self) { foo(self.x); } } diff --git a/src/test/auxiliary/moves_based_on_type_lib.rs b/src/test/auxiliary/moves_based_on_type_lib.rs index b3a9b3e1ee9..cd72468511e 100644 --- a/src/test/auxiliary/moves_based_on_type_lib.rs +++ b/src/test/auxiliary/moves_based_on_type_lib.rs @@ -15,7 +15,7 @@ pub struct S { } impl Drop for S { - fn finalize(&self) { + fn drop(&self) { println("goodbye"); } } diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 7a04a06d6a6..e245ab894f5 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -60,7 +60,7 @@ struct r { #[unsafe_destructor] impl Drop for r { - fn finalize(&self) {} + fn drop(&self) {} } fn r(l: @nillist) -> r { diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs index e9bc4a5e195..6353d7c6581 100644 --- a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs @@ -11,7 +11,7 @@ struct X { x: () } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs index 6548adddf19..6ea5f85797f 100644 --- a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs @@ -11,7 +11,7 @@ struct X { x: (), } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs index aaa9d9f920a..8f0642896f1 100644 --- a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs @@ -11,7 +11,7 @@ struct X { x: (), } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-4.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-4.rs index b5686b64c81..859bf7bd26d 100644 --- a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-4.rs +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-4.rs @@ -11,7 +11,7 @@ struct X { x: (), } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/bind-by-move-no-lvalues-1.rs b/src/test/compile-fail/bind-by-move-no-lvalues-1.rs index c8537afa190..3f96d568a55 100644 --- a/src/test/compile-fail/bind-by-move-no-lvalues-1.rs +++ b/src/test/compile-fail/bind-by-move-no-lvalues-1.rs @@ -13,7 +13,7 @@ struct X { x: (), } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/bind-by-move-no-lvalues-2.rs b/src/test/compile-fail/bind-by-move-no-lvalues-2.rs index 26b1084c091..c17a444ce6e 100644 --- a/src/test/compile-fail/bind-by-move-no-lvalues-2.rs +++ b/src/test/compile-fail/bind-by-move-no-lvalues-2.rs @@ -13,7 +13,7 @@ struct X { x: (), } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/bind-by-move-no-sub-bindings.rs b/src/test/compile-fail/bind-by-move-no-sub-bindings.rs index c86158be5ea..a1243dd01d9 100644 --- a/src/test/compile-fail/bind-by-move-no-sub-bindings.rs +++ b/src/test/compile-fail/bind-by-move-no-sub-bindings.rs @@ -11,7 +11,7 @@ struct X { x: (), } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("destructor runs"); } } diff --git a/src/test/compile-fail/block-must-not-have-result-res.rs b/src/test/compile-fail/block-must-not-have-result-res.rs index 8b8bb04c08b..c9b627f55f8 100644 --- a/src/test/compile-fail/block-must-not-have-result-res.rs +++ b/src/test/compile-fail/block-must-not-have-result-res.rs @@ -13,7 +13,7 @@ struct r; impl Drop for r { - fn finalize(&self) { + fn drop(&self) { true } } diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs index 1e5c4c5cc41..98099360f3c 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs @@ -14,7 +14,7 @@ struct defer<'self> { #[unsafe_destructor] impl<'self> Drop for defer<'self> { - fn finalize(&self) { + fn drop(&self) { unsafe { error!("%?", self.x); } diff --git a/src/test/compile-fail/copy-a-resource.rs b/src/test/compile-fail/copy-a-resource.rs index 2767447d819..f709ddc0e0d 100644 --- a/src/test/compile-fail/copy-a-resource.rs +++ b/src/test/compile-fail/copy-a-resource.rs @@ -13,7 +13,7 @@ struct foo { } impl Drop for foo { - fn finalize(&self) {} + fn drop(&self) {} } fn foo(i:int) -> foo { diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs index c363f172d2f..e550475d64f 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs @@ -14,7 +14,7 @@ struct X { } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("value: %s", self.x); } } diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs index 478a56c0301..748114a4f12 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs @@ -13,7 +13,7 @@ struct X { } impl Drop for X { - fn finalize(&self) { + fn drop(&self) { error!("value: %s", self.x); } } diff --git a/src/test/compile-fail/drop-on-non-struct.rs b/src/test/compile-fail/drop-on-non-struct.rs index 5e422d26753..2eb58d49612 100644 --- a/src/test/compile-fail/drop-on-non-struct.rs +++ b/src/test/compile-fail/drop-on-non-struct.rs @@ -12,7 +12,7 @@ type Foo = @[u8]; impl Drop for Foo { //~ ERROR the Drop trait may only be implemented //~^ ERROR cannot provide an extension implementation - fn finalize(&self) { + fn drop(&self) { println("kaboom"); } } diff --git a/src/test/compile-fail/explicit-call-to-dtor.rs b/src/test/compile-fail/explicit-call-to-dtor.rs index ce2942c3146..5ffc9ea08ed 100644 --- a/src/test/compile-fail/explicit-call-to-dtor.rs +++ b/src/test/compile-fail/explicit-call-to-dtor.rs @@ -13,12 +13,12 @@ struct Foo { } impl Drop for Foo { - fn finalize(&self) { + fn drop(&self) { println("kaboom"); } } fn main() { let x = Foo { x: 3 }; - x.finalize(); //~ ERROR explicit call to destructor + x.drop(); //~ ERROR explicit call to destructor } diff --git a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs index 1a5eb696fa2..ace31183d76 100644 --- a/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs +++ b/src/test/compile-fail/explicit-call-to-supertrait-dtor.rs @@ -17,14 +17,14 @@ trait Bar : Drop { } impl Drop for Foo { - fn finalize(&self) { + fn drop(&self) { println("kaboom"); } } impl Bar for Foo { fn blah(&self) { - self.finalize(); //~ ERROR explicit call to destructor + self.drop(); //~ ERROR explicit call to destructor } } diff --git a/src/test/compile-fail/issue-2548.rs b/src/test/compile-fail/issue-2548.rs index 2f690008440..314f282355d 100644 --- a/src/test/compile-fail/issue-2548.rs +++ b/src/test/compile-fail/issue-2548.rs @@ -18,7 +18,7 @@ struct foo { #[unsafe_destructor] impl Drop for foo { - fn finalize(&self) { + fn drop(&self) { unsafe { println("Goodbye, World!"); *self.x += 1; diff --git a/src/test/compile-fail/issue-2823.rs b/src/test/compile-fail/issue-2823.rs index b29b19b406f..7d1f64b9dd2 100644 --- a/src/test/compile-fail/issue-2823.rs +++ b/src/test/compile-fail/issue-2823.rs @@ -13,7 +13,7 @@ struct C { } impl Drop for C { - fn finalize(&self) { + fn drop(&self) { error!("dropping: %?", self.x); } } diff --git a/src/test/compile-fail/issue-3214.rs b/src/test/compile-fail/issue-3214.rs index 2dd58906ddb..8eb110e6ce9 100644 --- a/src/test/compile-fail/issue-3214.rs +++ b/src/test/compile-fail/issue-3214.rs @@ -15,7 +15,7 @@ fn foo() { } impl Drop for foo { - fn finalize(&self) {} + fn drop(&self) {} } } fn main() { } diff --git a/src/test/compile-fail/kindck-destructor-owned.rs b/src/test/compile-fail/kindck-destructor-owned.rs index faad36a15d2..551b50c94f2 100644 --- a/src/test/compile-fail/kindck-destructor-owned.rs +++ b/src/test/compile-fail/kindck-destructor-owned.rs @@ -3,7 +3,7 @@ struct Foo { } impl Drop for Foo { //~ ERROR cannot implement a destructor on a struct that is not Owned - fn finalize(&self) { + fn drop(&self) { *self.f = 10; } } diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 5e18a40a99c..1f5b600157f 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -20,7 +20,7 @@ fn main() { #[unsafe_destructor] impl Drop for foo { - fn finalize(&self) {} + fn drop(&self) {} } fn foo(x: Port<()>) -> foo { diff --git a/src/test/compile-fail/noncopyable-class.rs b/src/test/compile-fail/noncopyable-class.rs index 77e62497d07..aa7100f0aad 100644 --- a/src/test/compile-fail/noncopyable-class.rs +++ b/src/test/compile-fail/noncopyable-class.rs @@ -15,7 +15,7 @@ struct bar { } impl Drop for bar { - fn finalize(&self) {} + fn drop(&self) {} } fn bar(x:int) -> bar { diff --git a/src/test/compile-fail/pinned-deep-copy.rs b/src/test/compile-fail/pinned-deep-copy.rs index 17e23360a5b..2e48992e81e 100644 --- a/src/test/compile-fail/pinned-deep-copy.rs +++ b/src/test/compile-fail/pinned-deep-copy.rs @@ -14,7 +14,7 @@ struct r { #[unsafe_destructor] impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.i) = *(self.i) + 1; } diff --git a/src/test/compile-fail/repeat-to-run-dtor-twice.rs b/src/test/compile-fail/repeat-to-run-dtor-twice.rs index 0dd12822dfa..c997ce2a281 100644 --- a/src/test/compile-fail/repeat-to-run-dtor-twice.rs +++ b/src/test/compile-fail/repeat-to-run-dtor-twice.rs @@ -17,7 +17,7 @@ struct Foo { } impl Drop for Foo { - fn finalize(&self) { + fn drop(&self) { println("Goodbye!"); } } diff --git a/src/test/compile-fail/unique-object-noncopyable.rs b/src/test/compile-fail/unique-object-noncopyable.rs index 3844dab726e..dacfd466040 100644 --- a/src/test/compile-fail/unique-object-noncopyable.rs +++ b/src/test/compile-fail/unique-object-noncopyable.rs @@ -17,7 +17,7 @@ struct Bar { } impl Drop for Bar { - fn finalize(&self) {} + fn drop(&self) {} } impl Foo for Bar { diff --git a/src/test/compile-fail/unique-pinned-nocopy.rs b/src/test/compile-fail/unique-pinned-nocopy.rs index a08f03d5628..1deb850741e 100644 --- a/src/test/compile-fail/unique-pinned-nocopy.rs +++ b/src/test/compile-fail/unique-pinned-nocopy.rs @@ -13,7 +13,7 @@ struct r { } impl Drop for r { - fn finalize(&self) {} + fn drop(&self) {} } fn main() { diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index 003e8ccf309..e231e5e5037 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -14,7 +14,7 @@ struct r { #[unsafe_destructor] impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.i) = *(self.i) + 1; } diff --git a/src/test/compile-fail/use-after-move-self-based-on-type.rs b/src/test/compile-fail/use-after-move-self-based-on-type.rs index 5b4d67fb0ce..0622c028c63 100644 --- a/src/test/compile-fail/use-after-move-self-based-on-type.rs +++ b/src/test/compile-fail/use-after-move-self-based-on-type.rs @@ -3,7 +3,7 @@ struct S { } impl Drop for S { - fn finalize(&self) {} + fn drop(&self) {} } impl S { diff --git a/src/test/compile-fail/vec-res-add.rs b/src/test/compile-fail/vec-res-add.rs index 938e8c41e79..d881750bd3c 100644 --- a/src/test/compile-fail/vec-res-add.rs +++ b/src/test/compile-fail/vec-res-add.rs @@ -17,7 +17,7 @@ struct r { fn r(i:int) -> r { r { i: i } } impl Drop for r { - fn finalize(&self) {} + fn drop(&self) {} } fn main() { diff --git a/src/test/run-fail/issue-2061.rs b/src/test/run-fail/issue-2061.rs index cee3546acfa..3e78fd1f7db 100644 --- a/src/test/run-fail/issue-2061.rs +++ b/src/test/run-fail/issue-2061.rs @@ -15,7 +15,7 @@ struct R { } impl Drop for R { - fn finalize(&self) { + fn drop(&self) { let _y = R { b: self.b }; } } diff --git a/src/test/run-fail/morestack2.rs b/src/test/run-fail/morestack2.rs index d03433d5872..37bc3b6de8a 100644 --- a/src/test/run-fail/morestack2.rs +++ b/src/test/run-fail/morestack2.rs @@ -44,7 +44,7 @@ struct and_then_get_big_again { } impl Drop for and_then_get_big_again { - fn finalize(&self) { + fn drop(&self) { fn getbig(i: int) { if i != 0 { getbig(i - 1); diff --git a/src/test/run-fail/morestack3.rs b/src/test/run-fail/morestack3.rs index d2e17d28561..4e059c5bd3c 100644 --- a/src/test/run-fail/morestack3.rs +++ b/src/test/run-fail/morestack3.rs @@ -30,7 +30,7 @@ struct and_then_get_big_again { } impl Drop for and_then_get_big_again { - fn finalize(&self) { + fn drop(&self) { fn getbig(i: int) { if i != 0 { getbig(i - 1); diff --git a/src/test/run-fail/morestack4.rs b/src/test/run-fail/morestack4.rs index c4f7de49555..db46438ea3c 100644 --- a/src/test/run-fail/morestack4.rs +++ b/src/test/run-fail/morestack4.rs @@ -30,7 +30,7 @@ struct and_then_get_big_again { } impl Drop for and_then_get_big_again { - fn finalize(&self) {} + fn drop(&self) {} } fn and_then_get_big_again(x:int) -> and_then_get_big_again { diff --git a/src/test/run-fail/rt-set-exit-status-fail2.rs b/src/test/run-fail/rt-set-exit-status-fail2.rs index 3d0341d01f4..ee268f409a5 100644 --- a/src/test/run-fail/rt-set-exit-status-fail2.rs +++ b/src/test/run-fail/rt-set-exit-status-fail2.rs @@ -21,7 +21,7 @@ struct r { // failed has no effect and the process exits with the // runtime's exit code impl Drop for r { - fn finalize(&self) { + fn drop(&self) { os::set_exit_status(50); } } diff --git a/src/test/run-fail/too-much-recursion-unwinding.rs b/src/test/run-fail/too-much-recursion-unwinding.rs index 1c668dfc90d..16d0fe34668 100644 --- a/src/test/run-fail/too-much-recursion-unwinding.rs +++ b/src/test/run-fail/too-much-recursion-unwinding.rs @@ -24,7 +24,7 @@ struct r { } impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { if !*(self.recursed) { *(self.recursed) = true; diff --git a/src/test/run-fail/unwind-box-res.rs b/src/test/run-fail/unwind-box-res.rs index a1e1ee433bb..7f022d5761c 100644 --- a/src/test/run-fail/unwind-box-res.rs +++ b/src/test/run-fail/unwind-box-res.rs @@ -21,7 +21,7 @@ struct r { } impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { let _v2: ~int = cast::transmute(self.v); } diff --git a/src/test/run-fail/unwind-resource-fail.rs b/src/test/run-fail/unwind-resource-fail.rs index 486c2dd3b36..b4b0150013a 100644 --- a/src/test/run-fail/unwind-resource-fail.rs +++ b/src/test/run-fail/unwind-resource-fail.rs @@ -15,7 +15,7 @@ struct r { } impl Drop for r { - fn finalize(&self) { fail!("squirrel") } + fn drop(&self) { fail!("squirrel") } } fn r(i: int) -> r { r { i: i } } diff --git a/src/test/run-fail/unwind-resource-fail2.rs b/src/test/run-fail/unwind-resource-fail2.rs index ca98a61f234..6ebb4a742c4 100644 --- a/src/test/run-fail/unwind-resource-fail2.rs +++ b/src/test/run-fail/unwind-resource-fail2.rs @@ -16,7 +16,7 @@ struct r { } impl Drop for r { - fn finalize(&self) { fail!("wombat") } + fn drop(&self) { fail!("wombat") } } fn r(i: int) -> r { r { i: i } } diff --git a/src/test/run-fail/unwind-resource-fail3.rs b/src/test/run-fail/unwind-resource-fail3.rs index 9d6f877293b..2de9d4cec77 100644 --- a/src/test/run-fail/unwind-resource-fail3.rs +++ b/src/test/run-fail/unwind-resource-fail3.rs @@ -19,7 +19,7 @@ fn faily_box(i: @int) -> faily_box { faily_box { i: i } } #[unsafe_destructor] impl Drop for faily_box { - fn finalize(&self) { + fn drop(&self) { fail!("quux"); } } diff --git a/src/test/run-pass/attr-no-drop-flag-size.rs b/src/test/run-pass/attr-no-drop-flag-size.rs index e6f05970cce..00a7955d834 100644 --- a/src/test/run-pass/attr-no-drop-flag-size.rs +++ b/src/test/run-pass/attr-no-drop-flag-size.rs @@ -17,7 +17,7 @@ struct Test { #[unsafe_destructor] impl Drop for Test { - fn finalize(&self) { } + fn drop(&self) { } } fn main() { diff --git a/src/test/run-pass/borrowck-unary-move-2.rs b/src/test/run-pass/borrowck-unary-move-2.rs index c74fd4a68e7..c52371de54a 100644 --- a/src/test/run-pass/borrowck-unary-move-2.rs +++ b/src/test/run-pass/borrowck-unary-move-2.rs @@ -13,7 +13,7 @@ struct noncopyable { } impl Drop for noncopyable { - fn finalize(&self) { + fn drop(&self) { error!("dropped"); } } diff --git a/src/test/run-pass/class-attributes-1.rs b/src/test/run-pass/class-attributes-1.rs index b7ecb622e7f..108ae023e12 100644 --- a/src/test/run-pass/class-attributes-1.rs +++ b/src/test/run-pass/class-attributes-1.rs @@ -16,7 +16,7 @@ struct cat { impl Drop for cat { #[cat_dropper] - fn finalize(&self) { error!("%s landed on hir feet" , self . name); } + fn drop(&self) { error!("%s landed on hir feet" , self . name); } } diff --git a/src/test/run-pass/class-attributes-2.rs b/src/test/run-pass/class-attributes-2.rs index 8636699c482..02279677276 100644 --- a/src/test/run-pass/class-attributes-2.rs +++ b/src/test/run-pass/class-attributes-2.rs @@ -17,7 +17,7 @@ impl Drop for cat { /** Actually, cats don't always land on their feet when you drop them. */ - fn finalize(&self) { + fn drop(&self) { error!("%s landed on hir feet", self.name); } } diff --git a/src/test/run-pass/class-dtor.rs b/src/test/run-pass/class-dtor.rs index 229c683706d..c294670faa3 100644 --- a/src/test/run-pass/class-dtor.rs +++ b/src/test/run-pass/class-dtor.rs @@ -14,7 +14,7 @@ struct cat { } impl Drop for cat { - fn finalize(&self) { + fn drop(&self) { (self.done)(self.meows); } } diff --git a/src/test/run-pass/drop-trait-generic.rs b/src/test/run-pass/drop-trait-generic.rs index 894c387b036..557a153bce2 100644 --- a/src/test/run-pass/drop-trait-generic.rs +++ b/src/test/run-pass/drop-trait-generic.rs @@ -14,7 +14,7 @@ struct S { #[unsafe_destructor] impl ::std::ops::Drop for S { - fn finalize(&self) { + fn drop(&self) { println("bye"); } } diff --git a/src/test/run-pass/drop-trait.rs b/src/test/run-pass/drop-trait.rs index 258a0f88ab5..0ed5a27eb19 100644 --- a/src/test/run-pass/drop-trait.rs +++ b/src/test/run-pass/drop-trait.rs @@ -13,7 +13,7 @@ struct Foo { } impl Drop for Foo { - fn finalize(&self) { + fn drop(&self) { println("bye"); } } diff --git a/src/test/run-pass/init-res-into-things.rs b/src/test/run-pass/init-res-into-things.rs index 5e10419da6e..cad6661bbce 100644 --- a/src/test/run-pass/init-res-into-things.rs +++ b/src/test/run-pass/init-res-into-things.rs @@ -19,7 +19,7 @@ struct Box { x: r } #[unsafe_destructor] impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.i) = *(self.i) + 1; } diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index 5e5fb70bcd4..0f9f1102aea 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -14,7 +14,7 @@ struct socket { } impl Drop for socket { - fn finalize(&self) {} + fn drop(&self) {} } impl socket { diff --git a/src/test/run-pass/issue-2708.rs b/src/test/run-pass/issue-2708.rs index 9e8438efad5..44ace16fb95 100644 --- a/src/test/run-pass/issue-2708.rs +++ b/src/test/run-pass/issue-2708.rs @@ -16,7 +16,7 @@ struct Font { } impl Drop for Font { - fn finalize(&self) {} + fn drop(&self) {} } fn Font() -> Font { diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 014aebeff9d..9fbca7d0572 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -160,7 +160,7 @@ pub mod pipes { #[unsafe_destructor] impl Drop for send_packet { - fn finalize(&self) { + fn drop(&self) { unsafe { if self.p != None { let self_p: &mut Option<*packet> = @@ -190,7 +190,7 @@ pub mod pipes { #[unsafe_destructor] impl Drop for recv_packet { - fn finalize(&self) { + fn drop(&self) { unsafe { if self.p != None { let self_p: &mut Option<*packet> = diff --git a/src/test/run-pass/issue-2735-2.rs b/src/test/run-pass/issue-2735-2.rs index ca584e1a6e3..b44d50921a5 100644 --- a/src/test/run-pass/issue-2735-2.rs +++ b/src/test/run-pass/issue-2735-2.rs @@ -15,7 +15,7 @@ struct defer { #[unsafe_destructor] impl Drop for defer { - fn finalize(&self) { + fn drop(&self) { *self.b = true; } } diff --git a/src/test/run-pass/issue-2735-3.rs b/src/test/run-pass/issue-2735-3.rs index 44ca5d6929b..902b2f69d61 100644 --- a/src/test/run-pass/issue-2735-3.rs +++ b/src/test/run-pass/issue-2735-3.rs @@ -15,7 +15,7 @@ struct defer { #[unsafe_destructor] impl Drop for defer { - fn finalize(&self) { + fn drop(&self) { *self.b = true; } } diff --git a/src/test/run-pass/issue-2895.rs b/src/test/run-pass/issue-2895.rs index e6b3f9f6f35..a80a079b695 100644 --- a/src/test/run-pass/issue-2895.rs +++ b/src/test/run-pass/issue-2895.rs @@ -19,7 +19,7 @@ struct Kitty { } impl Drop for Kitty { - fn finalize(&self) {} + fn drop(&self) {} } #[cfg(target_arch = "x86_64")] diff --git a/src/test/run-pass/issue-3220.rs b/src/test/run-pass/issue-3220.rs index 9cc5e591043..dce6d8f0bf1 100644 --- a/src/test/run-pass/issue-3220.rs +++ b/src/test/run-pass/issue-3220.rs @@ -11,7 +11,7 @@ struct thing { x: int, } impl Drop for thing { - fn finalize(&self) {} + fn drop(&self) {} } fn thing() -> thing { diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 012e70988ad..e574502a9fb 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -58,7 +58,7 @@ struct AsciiArt { } impl Drop for AsciiArt { - fn finalize(&self) {} + fn drop(&self) {} } // It's common to define a constructor sort of function to create struct instances. diff --git a/src/test/run-pass/issue-4252.rs b/src/test/run-pass/issue-4252.rs index f3b73c84714..de1f630a245 100644 --- a/src/test/run-pass/issue-4252.rs +++ b/src/test/run-pass/issue-4252.rs @@ -26,7 +26,7 @@ impl X for Y { } impl Drop for Z { - fn finalize(&self) { + fn drop(&self) { self.x.call(); // Adding this statement causes an ICE. } } diff --git a/src/test/run-pass/issue-4735.rs b/src/test/run-pass/issue-4735.rs index 057622d2251..3da90ba1edc 100644 --- a/src/test/run-pass/issue-4735.rs +++ b/src/test/run-pass/issue-4735.rs @@ -15,7 +15,7 @@ use std::libc::c_void; struct NonCopyable(*c_void); impl Drop for NonCopyable { - fn finalize(&self) { + fn drop(&self) { let p = **self; let v = unsafe { transmute::<*c_void, ~int>(p) }; } diff --git a/src/test/run-pass/issue-6341.rs b/src/test/run-pass/issue-6341.rs index 394345556fc..29fc0744305 100644 --- a/src/test/run-pass/issue-6341.rs +++ b/src/test/run-pass/issue-6341.rs @@ -12,7 +12,7 @@ struct A { x: uint } impl Drop for A { - fn finalize(&self) {} + fn drop(&self) {} } fn main() {} \ No newline at end of file diff --git a/src/test/run-pass/issue-6344-let.rs b/src/test/run-pass/issue-6344-let.rs index 916131b6b71..bb0c71d6d55 100644 --- a/src/test/run-pass/issue-6344-let.rs +++ b/src/test/run-pass/issue-6344-let.rs @@ -11,7 +11,7 @@ struct A { x: uint } impl Drop for A { - fn finalize(&self) {} + fn drop(&self) {} } fn main() { diff --git a/src/test/run-pass/issue-6344-match.rs b/src/test/run-pass/issue-6344-match.rs index 5bf57aa7116..7987f9689fa 100644 --- a/src/test/run-pass/issue-6344-match.rs +++ b/src/test/run-pass/issue-6344-match.rs @@ -10,7 +10,7 @@ struct A { x: uint } impl Drop for A { - fn finalize(&self) {} + fn drop(&self) {} } fn main() { diff --git a/src/test/run-pass/issue-979.rs b/src/test/run-pass/issue-979.rs index 20bb8ea965b..34a9055ae83 100644 --- a/src/test/run-pass/issue-979.rs +++ b/src/test/run-pass/issue-979.rs @@ -14,7 +14,7 @@ struct r { #[unsafe_destructor] impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.b) += 1; } diff --git a/src/test/run-pass/newtype-struct-drop-run.rs b/src/test/run-pass/newtype-struct-drop-run.rs index dd5da3b09bb..b7fdfabff9a 100644 --- a/src/test/run-pass/newtype-struct-drop-run.rs +++ b/src/test/run-pass/newtype-struct-drop-run.rs @@ -14,7 +14,7 @@ struct Foo(@mut int); #[unsafe_destructor] impl Drop for Foo { - fn finalize(&self) { + fn drop(&self) { ***self = 23; } } diff --git a/src/test/run-pass/newtype-struct-with-dtor.rs b/src/test/run-pass/newtype-struct-with-dtor.rs index 0e36f27aa92..6062f3075e2 100644 --- a/src/test/run-pass/newtype-struct-with-dtor.rs +++ b/src/test/run-pass/newtype-struct-with-dtor.rs @@ -4,7 +4,7 @@ use std::libc; pub struct Fd(c_int); impl Drop for Fd { - fn finalize(&self) { + fn drop(&self) { unsafe { libc::close(**self); } diff --git a/src/test/run-pass/option-unwrap.rs b/src/test/run-pass/option-unwrap.rs index ea8a6f236cd..5c8cfd68240 100644 --- a/src/test/run-pass/option-unwrap.rs +++ b/src/test/run-pass/option-unwrap.rs @@ -15,7 +15,7 @@ struct dtor { #[unsafe_destructor] impl Drop for dtor { - fn finalize(&self) { + fn drop(&self) { // abuse access to shared mutable state to write this code unsafe { *self.x -= 1; diff --git a/src/test/run-pass/pipe-presentation-examples.rs b/src/test/run-pass/pipe-presentation-examples.rs index 54cf8ba9c0a..65e0537dfb7 100644 --- a/src/test/run-pass/pipe-presentation-examples.rs +++ b/src/test/run-pass/pipe-presentation-examples.rs @@ -85,7 +85,7 @@ pub struct Buffer { } impl Drop for Buffer { - fn finalize(&self) {} + fn drop(&self) {} } proto! double_buffer ( diff --git a/src/test/run-pass/resource-assign-is-not-copy.rs b/src/test/run-pass/resource-assign-is-not-copy.rs index edd692196ec..112c6be560d 100644 --- a/src/test/run-pass/resource-assign-is-not-copy.rs +++ b/src/test/run-pass/resource-assign-is-not-copy.rs @@ -14,7 +14,7 @@ struct r { #[unsafe_destructor] impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.i) += 1; } diff --git a/src/test/run-pass/resource-cycle.rs b/src/test/run-pass/resource-cycle.rs index 3ce5ea66781..e48b841144a 100644 --- a/src/test/run-pass/resource-cycle.rs +++ b/src/test/run-pass/resource-cycle.rs @@ -17,7 +17,7 @@ struct r { } impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x", cast::transmute::<*r, uint>(self), diff --git a/src/test/run-pass/resource-cycle2.rs b/src/test/run-pass/resource-cycle2.rs index 0f031424ad4..1a82e321bd7 100644 --- a/src/test/run-pass/resource-cycle2.rs +++ b/src/test/run-pass/resource-cycle2.rs @@ -23,7 +23,7 @@ struct r { } impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { let v2: ~int = cast::transmute(self.v.c); } diff --git a/src/test/run-pass/resource-cycle3.rs b/src/test/run-pass/resource-cycle3.rs index f3ca932778a..1e0d8447aeb 100644 --- a/src/test/run-pass/resource-cycle3.rs +++ b/src/test/run-pass/resource-cycle3.rs @@ -27,7 +27,7 @@ struct R { } impl Drop for R { - fn finalize(&self) { + fn drop(&self) { unsafe { let _v2: ~int = cast::transmute(self.v.c); // let _v3: ~int = cast::transmute_copy(self.x); diff --git a/src/test/run-pass/resource-destruct.rs b/src/test/run-pass/resource-destruct.rs index c240c6708a4..7eac25535a8 100644 --- a/src/test/run-pass/resource-destruct.rs +++ b/src/test/run-pass/resource-destruct.rs @@ -14,7 +14,7 @@ struct shrinky_pointer { #[unsafe_destructor] impl Drop for shrinky_pointer { - fn finalize(&self) { + fn drop(&self) { unsafe { error!(~"Hello!"); **(self.i) -= 1; } diff --git a/src/test/run-pass/resource-generic.rs b/src/test/run-pass/resource-generic.rs index 7a18cd02c2d..75d978b0d05 100644 --- a/src/test/run-pass/resource-generic.rs +++ b/src/test/run-pass/resource-generic.rs @@ -18,7 +18,7 @@ struct finish { #[unsafe_destructor] impl Drop for finish { - fn finalize(&self) { + fn drop(&self) { unsafe { (self.arg.fin)(copy self.arg.val); } diff --git a/src/test/run-pass/resource-in-struct.rs b/src/test/run-pass/resource-in-struct.rs index d74ec61d3c0..836b49f9a15 100644 --- a/src/test/run-pass/resource-in-struct.rs +++ b/src/test/run-pass/resource-in-struct.rs @@ -20,7 +20,7 @@ struct close_res { #[unsafe_destructor] impl Drop for close_res { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.i) = false; } diff --git a/src/test/run-pass/send-resource.rs b/src/test/run-pass/send-resource.rs index a2cee0082b5..e450e1f48c0 100644 --- a/src/test/run-pass/send-resource.rs +++ b/src/test/run-pass/send-resource.rs @@ -16,7 +16,7 @@ struct test { } impl Drop for test { - fn finalize(&self) {} + fn drop(&self) {} } fn test(f: int) -> test { diff --git a/src/test/run-pass/struct-literal-dtor.rs b/src/test/run-pass/struct-literal-dtor.rs index 9f5b8cf27dd..2fc6833242f 100644 --- a/src/test/run-pass/struct-literal-dtor.rs +++ b/src/test/run-pass/struct-literal-dtor.rs @@ -13,7 +13,7 @@ struct foo { } impl Drop for foo { - fn finalize(&self) { + fn drop(&self) { error!("%s", self.x); } } diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 2025a5c304c..aa37f5e9ce9 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -24,7 +24,7 @@ struct notify { #[unsafe_destructor] impl Drop for notify { - fn finalize(&self) { + fn drop(&self) { unsafe { error!("notify: task=%? v=%x unwinding=%b b=%b", task::get_task(), diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs index bd6165806c2..416e7bf82bb 100644 --- a/src/test/run-pass/type-param-constraints.rs +++ b/src/test/run-pass/type-param-constraints.rs @@ -19,7 +19,7 @@ struct r { } impl Drop for r { - fn finalize(&self) {} + fn drop(&self) {} } fn r(i:int) -> r { diff --git a/src/test/run-pass/unique-pinned-nocopy-2.rs b/src/test/run-pass/unique-pinned-nocopy-2.rs index 197f26f897d..b0ad7f50420 100644 --- a/src/test/run-pass/unique-pinned-nocopy-2.rs +++ b/src/test/run-pass/unique-pinned-nocopy-2.rs @@ -14,7 +14,7 @@ struct r { #[unsafe_destructor] impl Drop for r { - fn finalize(&self) { + fn drop(&self) { unsafe { *(self.i) = *(self.i) + 1; } diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index b19a0aa1e98..41b971d64d0 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -16,7 +16,7 @@ use std::task; struct Foo; impl Drop for Foo { - fn finalize(&self) { + fn drop(&self) { fail!("This failure should happen."); } } diff --git a/src/test/run-pass/unwind-resource.rs b/src/test/run-pass/unwind-resource.rs index 4b71d79ccc4..450e81bee33 100644 --- a/src/test/run-pass/unwind-resource.rs +++ b/src/test/run-pass/unwind-resource.rs @@ -19,7 +19,7 @@ struct complainer { } impl Drop for complainer { - fn finalize(&self) { + fn drop(&self) { error!("About to send!"); self.c.send(true); error!("Sent!"); diff --git a/src/test/run-pass/unwind-resource2.rs b/src/test/run-pass/unwind-resource2.rs index b5a496eb206..841fb37d29d 100644 --- a/src/test/run-pass/unwind-resource2.rs +++ b/src/test/run-pass/unwind-resource2.rs @@ -19,7 +19,7 @@ struct complainer { #[unsafe_destructor] impl Drop for complainer { - fn finalize(&self) {} + fn drop(&self) {} } fn complainer(c: @int) -> complainer { diff --git a/src/test/run-pass/vec-slice-drop.rs b/src/test/run-pass/vec-slice-drop.rs index 695441daf28..54626e52d23 100644 --- a/src/test/run-pass/vec-slice-drop.rs +++ b/src/test/run-pass/vec-slice-drop.rs @@ -15,7 +15,7 @@ struct foo { #[unsafe_destructor] impl Drop for foo { - fn finalize(&self) { + fn drop(&self) { unsafe { *self.x += 1; } -- cgit 1.4.1-3-g733a5 From 366ca44cc8f79704f8781adb15e74d3c2a0e5572 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 28 Jun 2013 01:45:24 +1000 Subject: std: silence some test warnings. --- src/libstd/iterator.rs | 1 - src/libstd/local_data.rs | 23 ++++++++++------------- src/libstd/rt/uv/timer.rs | 4 ++-- src/libstd/str.rs | 3 ++- src/libstd/task/mod.rs | 14 ++++++-------- src/libstd/vec.rs | 4 ++-- 6 files changed, 22 insertions(+), 27 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index ab433a9a79d..7de02a9f815 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -980,7 +980,6 @@ mod tests { use super::*; use prelude::*; - use iter; use uint; #[test] diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 82c01c998cf..33b4e3f1963 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -92,14 +92,12 @@ fn test_tls_multitask() { fn my_key(_x: @~str) { } local_data_set(my_key, @~"parent data"); do task::spawn { - unsafe { - // TLS shouldn't carry over. - assert!(local_data_get(my_key).is_none()); - local_data_set(my_key, @~"child data"); - assert!(*(local_data_get(my_key).get()) == + // TLS shouldn't carry over. + assert!(local_data_get(my_key).is_none()); + local_data_set(my_key, @~"child data"); + assert!(*(local_data_get(my_key).get()) == ~"child data"); - // should be cleaned up for us - } + // should be cleaned up for us } // Must work multiple times assert!(*(local_data_get(my_key).get()) == ~"parent data"); @@ -206,12 +204,11 @@ fn test_tls_cleanup_on_failure() { local_data_set(str_key, @~"parent data"); local_data_set(box_key, @@()); do task::spawn { - unsafe { // spawn_linked - local_data_set(str_key, @~"string data"); - local_data_set(box_key, @@()); - local_data_set(int_key, @42); - fail!(); - } + // spawn_linked + local_data_set(str_key, @~"string data"); + local_data_set(box_key, @@()); + local_data_set(int_key, @42); + fail!(); } // Not quite nondeterministic. local_data_set(int_key, @31337); diff --git a/src/libstd/rt/uv/timer.rs b/src/libstd/rt/uv/timer.rs index cd6fc5c0a25..14465eb7dfd 100644 --- a/src/libstd/rt/uv/timer.rs +++ b/src/libstd/rt/uv/timer.rs @@ -160,14 +160,14 @@ mod test { let mut timer2 = TimerWatcher::new(&mut loop_); do timer2.start(10, 0) |timer2, _| { - unsafe { *count_ptr += 1; } + *count_ptr += 1; timer2.close(||()); // Restart the original timer let mut timer = timer; do timer.start(1, 0) |timer, _| { - unsafe { *count_ptr += 1; } + *count_ptr += 1; timer.close(||()); } } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 58cdc6631f0..b4292a30541 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2249,7 +2249,7 @@ mod tests { assert!("" <= ""); assert!("" <= "foo"); assert!("foo" <= "foo"); - assert!("foo" != ~"bar"); + assert!("foo" != "bar"); } #[test] @@ -3156,6 +3156,7 @@ mod tests { #[test] fn test_add() { + #[allow(unnecessary_allocation)]; macro_rules! t ( ($s1:expr, $s2:expr, $e:expr) => { assert_eq!($s1 + $s2, $e); diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 223afbce091..b558b9d53a3 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -934,17 +934,15 @@ fn test_spawn_sched_blocking() { let lock = testrt::rust_dbg_lock_create(); do spawn_sched(SingleThreaded) { - unsafe { - testrt::rust_dbg_lock_lock(lock); + testrt::rust_dbg_lock_lock(lock); - start_ch.send(()); + start_ch.send(()); - // Block the scheduler thread - testrt::rust_dbg_lock_wait(lock); - testrt::rust_dbg_lock_unlock(lock); + // Block the scheduler thread + testrt::rust_dbg_lock_wait(lock); + testrt::rust_dbg_lock_unlock(lock); - fin_ch.send(()); - } + fin_ch.send(()); }; // Wait until the other task has its lock diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 5dfea811c23..8cbd9309cc6 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -3861,11 +3861,11 @@ mod tests { fn test_vec_zero() { use num::Zero; macro_rules! t ( - ($ty:ty) => { + ($ty:ty) => {{ let v: $ty = Zero::zero(); assert!(v.is_empty()); assert!(v.is_zero()); - } + }} ); t!(&[int]); -- cgit 1.4.1-3-g733a5 From 1c0aa7848103b5018473df851bc115d3e5585185 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 5 Jun 2013 17:56:24 -0700 Subject: librustc: Change "Owned" to "Send" everywhere --- src/libextra/arc.rs | 28 +++--- src/libextra/comm.rs | 14 +-- src/libextra/flatpipes.rs | 24 ++--- src/libextra/future.rs | 4 +- src/libextra/par.rs | 10 +-- src/libextra/rc.rs | 8 +- src/libextra/sync.rs | 6 +- src/libextra/timer.rs | 4 +- src/libextra/workcache.rs | 10 +-- src/librustc/middle/borrowck/doc.rs | 4 +- .../middle/borrowck/gather_loans/lifetime.rs | 2 +- .../middle/borrowck/gather_loans/restrictions.rs | 2 +- src/librustc/middle/typeck/check/_match.rs | 8 +- src/librustdoc/astsrv.rs | 2 +- src/librustdoc/attr_pass.rs | 2 +- src/libstd/clone.rs | 4 +- src/libstd/comm.rs | 100 ++++++++++----------- src/libstd/kinds.rs | 6 +- src/libstd/pipes.rs | 34 +++---- src/libstd/prelude.rs | 2 +- src/libstd/rt/comm.rs | 10 +-- src/libstd/rt/message_queue.rs | 4 +- src/libstd/rt/work_queue.rs | 4 +- src/libstd/task/mod.rs | 8 +- src/libstd/unstable/global.rs | 14 +-- src/libstd/unstable/sync.rs | 12 +-- src/libsyntax/ast.rs | 2 +- src/libsyntax/ext/deriving/to_str.rs | 2 +- src/libsyntax/ext/deriving/ty.rs | 6 +- src/test/auxiliary/cci_capture_clause.rs | 2 +- src/test/bench/pingpong.rs | 6 +- src/test/compile-fail/closure-bounds-subtype.rs | 14 +-- src/test/compile-fail/issue-2766-a.rs | 6 +- src/test/compile-fail/kindck-destructor-owned.rs | 2 +- src/test/compile-fail/liveness-use-after-send.rs | 2 +- src/test/compile-fail/non_owned-enum.rs | 4 +- src/test/compile-fail/non_owned-struct.rs | 4 +- src/test/compile-fail/unique-unique-kind.rs | 4 +- src/test/compile-fail/unsendable-class.rs | 4 +- src/test/run-fail/bug-811.rs | 2 +- src/test/run-pass/alignment-gep-tup-like-2.rs | 2 +- src/test/run-pass/fixed-point-bind-unique.rs | 4 +- src/test/run-pass/fn-bare-spawn.rs | 2 +- src/test/run-pass/generic-alias-unique.rs | 2 +- src/test/run-pass/issue-2718.rs | 24 ++--- src/test/run-pass/issue-2834.rs | 2 +- src/test/run-pass/issue-2930.rs | 2 +- src/test/run-pass/pipe-bank-proto.rs | 4 +- src/test/run-pass/pipe-select.rs | 4 +- src/test/run-pass/pipe-sleep.rs | 2 +- src/test/run-pass/send-type-inference.rs | 2 +- src/test/run-pass/type-param-constraints.rs | 2 +- src/test/run-pass/uniq-cc-generic.rs | 2 +- src/test/run-pass/unique-kinds.rs | 4 +- 54 files changed, 222 insertions(+), 222 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index e0ab2558e3f..2fb03fecb59 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -112,7 +112,7 @@ impl<'self> Condvar<'self> { pub struct ARC { x: UnsafeAtomicRcBox } /// Create an atomically reference counted wrapper. -pub fn ARC(data: T) -> ARC { +pub fn ARC(data: T) -> ARC { ARC { x: UnsafeAtomicRcBox::new(data) } } @@ -120,7 +120,7 @@ pub fn ARC(data: T) -> ARC { * Access the underlying data in an atomically reference counted * wrapper. */ -impl ARC { +impl ARC { pub fn get<'a>(&'a self) -> &'a T { unsafe { &*self.x.get_immut() } } @@ -133,7 +133,7 @@ impl ARC { * object. However, one of the `arc` objects can be sent to another task, * allowing them to share the underlying data. */ -impl Clone for ARC { +impl Clone for ARC { fn clone(&self) -> ARC { ARC { x: self.x.clone() } } @@ -149,14 +149,14 @@ struct MutexARCInner { lock: Mutex, failed: bool, data: T } struct MutexARC { x: UnsafeAtomicRcBox> } /// 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(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), @@ -164,7 +164,7 @@ pub fn mutex_arc_with_condvars(user_data: T, MutexARC { x: UnsafeAtomicRcBox::new(data) } } -impl Clone for MutexARC { +impl Clone for MutexARC { /// Duplicate a mutex-protected ARC, as arc::clone. fn clone(&self) -> MutexARC { // NB: Cloning the underlying mutex is not necessary. Its reference @@ -173,7 +173,7 @@ impl Clone for MutexARC { } } -impl MutexARC { +impl MutexARC { /** * Access the underlying mutable data with mutual exclusion from other @@ -282,14 +282,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(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( +pub fn rw_arc_with_condvars( user_data: T, num_condvars: uint) -> RWARC { @@ -299,7 +299,7 @@ pub fn rw_arc_with_condvars( RWARC { x: UnsafeAtomicRcBox::new(data), } } -impl RWARC { +impl RWARC { /// Duplicate a rwlock-protected ARC, as arc::clone. pub fn clone(&self) -> RWARC { RWARC { @@ -309,7 +309,7 @@ impl RWARC { } -impl RWARC { +impl RWARC { /** * Access the underlying data mutably. Locks the rwlock in write mode; * other readers and writers will block. @@ -435,7 +435,7 @@ impl RWARC { // lock it. This wraps the unsafety, with the justification that the 'lock' // field is never overwritten; only 'failed' and 'data'. #[doc(hidden)] -fn borrow_rwlock(state: *const RWARCInner) -> *RWlock { +fn borrow_rwlock(state: *const RWARCInner) -> *RWlock { unsafe { cast::transmute(&const (*state).lock) } } @@ -452,7 +452,7 @@ pub struct RWReadMode<'self, T> { token: sync::RWlockReadMode<'self>, } -impl<'self, T:Freeze + Owned> RWWriteMode<'self, T> { +impl<'self, T:Freeze + Send> RWWriteMode<'self, T> { /// Access the pre-downgrade RWARC in write mode. pub fn write(&mut self, blk: &fn(x: &mut T) -> U) -> U { match *self { @@ -493,7 +493,7 @@ impl<'self, T:Freeze + Owned> RWWriteMode<'self, T> { } } -impl<'self, T:Freeze + Owned> RWReadMode<'self, T> { +impl<'self, T:Freeze + Send> RWReadMode<'self, T> { /// Access the post-downgrade rwlock in read mode. pub fn read(&self, blk: &fn(x: &T) -> U) -> U { match *self { diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index 1001d4f6ac9..2cb2128db5f 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -30,7 +30,7 @@ pub struct DuplexStream { } // Allow these methods to be used without import: -impl DuplexStream { +impl DuplexStream { pub fn send(&self, x: T) { self.chan.send(x) } @@ -48,19 +48,19 @@ impl DuplexStream { } } -impl GenericChan for DuplexStream { +impl GenericChan for DuplexStream { fn send(&self, x: T) { self.chan.send(x) } } -impl GenericSmartChan for DuplexStream { +impl GenericSmartChan for DuplexStream { fn try_send(&self, x: T) -> bool { self.chan.try_send(x) } } -impl GenericPort for DuplexStream { +impl GenericPort for DuplexStream { fn recv(&self) -> U { self.port.recv() } @@ -70,20 +70,20 @@ impl GenericPort for DuplexStream { } } -impl Peekable for DuplexStream { +impl Peekable for DuplexStream { fn peek(&self) -> bool { self.port.peek() } } -impl Selectable for DuplexStream { +impl Selectable for DuplexStream { fn header(&mut self) -> *mut pipes::PacketHeader { self.port.header() } } /// Creates a bidirectional stream. -pub fn DuplexStream() +pub fn DuplexStream() -> (DuplexStream, DuplexStream) { let (p1, c2) = comm::stream(); diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index 60fbfdeb62c..d5e43e85a14 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -166,8 +166,8 @@ Constructors for flat pipes that send POD types using memcpy. # Safety Note -This module is currently unsafe because it uses `Copy Owned` as a type -parameter bounds meaning POD (plain old data), but `Copy Owned` and +This module is currently unsafe because it uses `Copy Send` as a type +parameter bounds meaning POD (plain old data), but `Copy Send` and POD are not equivelant. */ @@ -191,7 +191,7 @@ pub mod pod { pub type PipeChan = FlatChan, PipeByteChan>; /// Create a `FlatPort` from a `Reader` - pub fn reader_port( + pub fn reader_port( reader: R ) -> ReaderPort { let unflat: PodUnflattener = PodUnflattener::new(); @@ -200,7 +200,7 @@ pub mod pod { } /// Create a `FlatChan` from a `Writer` - pub fn writer_chan( + pub fn writer_chan( writer: W ) -> WriterChan { let flat: PodFlattener = PodFlattener::new(); @@ -209,21 +209,21 @@ pub mod pod { } /// Create a `FlatPort` from a `Port<~[u8]>` - pub fn pipe_port(port: Port<~[u8]>) -> PipePort { + pub fn pipe_port(port: Port<~[u8]>) -> PipePort { let unflat: PodUnflattener = PodUnflattener::new(); let byte_port = PipeBytePort::new(port); FlatPort::new(unflat, byte_port) } /// Create a `FlatChan` from a `Chan<~[u8]>` - pub fn pipe_chan(chan: Chan<~[u8]>) -> PipeChan { + pub fn pipe_chan(chan: Chan<~[u8]>) -> PipeChan { let flat: PodFlattener = PodFlattener::new(); let byte_chan = PipeByteChan::new(chan); FlatChan::new(flat, byte_chan) } /// Create a pair of `FlatChan` and `FlatPort`, backed by pipes - pub fn pipe_stream() -> (PipePort, PipeChan) { + pub fn pipe_stream() -> (PipePort, PipeChan) { let (port, chan) = comm::stream(); return (pipe_port(port), pipe_chan(chan)); } @@ -352,7 +352,7 @@ pub mod flatteners { use core::sys::size_of; use core::vec; - // FIXME #4074: Copy + Owned != POD + // FIXME #4074: Copy + Send != POD pub struct PodUnflattener { bogus: () } @@ -361,7 +361,7 @@ pub mod flatteners { bogus: () } - impl Unflattener for PodUnflattener { + impl Unflattener for PodUnflattener { fn unflatten(&self, buf: ~[u8]) -> T { assert!(size_of::() != 0); assert_eq!(size_of::(), buf.len()); @@ -371,7 +371,7 @@ pub mod flatteners { } } - impl Flattener for PodFlattener { + impl Flattener for PodFlattener { fn flatten(&self, val: T) -> ~[u8] { assert!(size_of::() != 0); let val: *T = ptr::to_unsafe_ptr(&val); @@ -380,7 +380,7 @@ pub mod flatteners { } } - impl PodUnflattener { + impl PodUnflattener { pub fn new() -> PodUnflattener { PodUnflattener { bogus: () @@ -388,7 +388,7 @@ pub mod flatteners { } } - impl PodFlattener { + impl PodFlattener { pub fn new() -> PodFlattener { PodFlattener { bogus: () diff --git a/src/libextra/future.rs b/src/libextra/future.rs index f2cd64085ef..00f4cc3989b 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -101,7 +101,7 @@ pub fn from_value(val: A) -> Future { Future {state: Forced(val)} } -pub fn from_port(port: PortOne) -> Future { +pub fn from_port(port: PortOne) -> Future { /*! * Create a future from a port * @@ -127,7 +127,7 @@ pub fn from_fn(f: ~fn() -> A) -> Future { Future {state: Pending(f)} } -pub fn spawn(blk: ~fn() -> A) -> Future { +pub fn spawn(blk: ~fn() -> A) -> Future { /*! * Create a future from a unique closure. * diff --git a/src/libextra/par.rs b/src/libextra/par.rs index 334ab7c9c99..a3014cf8894 100644 --- a/src/libextra/par.rs +++ b/src/libextra/par.rs @@ -33,7 +33,7 @@ static min_granularity : uint = 1024u; * This is used to build most of the other parallel vector functions, * like map or alli. */ -fn map_slices( +fn map_slices( xs: &[A], f: &fn() -> ~fn(uint, v: &[A]) -> B) -> ~[B] { @@ -88,7 +88,7 @@ fn map_slices( } /// A parallel version of map. -pub fn map( +pub fn map( xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] { vec::concat(map_slices(xs, || { let f = fn_factory(); @@ -99,7 +99,7 @@ pub fn map( } /// A parallel version of mapi. -pub fn mapi( +pub fn mapi( xs: &[A], fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] { let slices = map_slices(xs, || { @@ -118,7 +118,7 @@ pub fn mapi( } /// Returns true if the function holds for all elements in the vector. -pub fn alli( +pub fn alli( xs: &[A], fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool { @@ -133,7 +133,7 @@ pub fn alli( } /// Returns true if the function holds for any elements in the vector. -pub fn any( +pub fn any( xs: &[A], fn_factory: &fn() -> ~fn(&A) -> bool) -> bool { let mapped = map_slices(xs, || { diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index ca3229d4b25..009d68ac026 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -13,10 +13,10 @@ /** Task-local reference counted smart pointers Task-local reference counted smart pointers are an alternative to managed boxes with deterministic -destruction. They are restricted to containing types that are either `Owned` or `Freeze` (or both) to +destruction. They are restricted to containing types that are either `Send` or `Freeze` (or both) to prevent cycles. -Neither `Rc` or `RcMut` is ever `Owned` and `RcMut` is never `Freeze`. If `T` is `Freeze`, a +Neither `Rc` or `RcMut` is ever `Send` and `RcMut` is never `Freeze`. If `T` is `Freeze`, a cycle cannot be created with `Rc` because there is no way to modify it after creation. */ @@ -51,7 +51,7 @@ impl Rc { } // FIXME: #6516: should be a static method -pub fn rc_from_owned(value: T) -> Rc { +pub fn rc_from_owned(value: T) -> Rc { unsafe { Rc::new(value) } } @@ -185,7 +185,7 @@ impl RcMut { } // FIXME: #6516: should be a static method -pub fn rc_mut_from_owned(value: T) -> RcMut { +pub fn rc_mut_from_owned(value: T) -> RcMut { unsafe { RcMut::new(value) } } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 817e1ab1226..61b6a233944 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -86,7 +86,7 @@ struct SemInner { struct Sem(Exclusive>); #[doc(hidden)] -fn new_sem(count: int, q: Q) -> Sem { +fn new_sem(count: int, q: Q) -> Sem { Sem(exclusive(SemInner { count: count, waiters: new_waitqueue(), blocked: q })) } @@ -101,7 +101,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint) } #[doc(hidden)] -impl Sem { +impl Sem { pub fn acquire(&self) { unsafe { let mut waiter_nobe = None; @@ -175,7 +175,7 @@ struct SemReleaseGeneric<'self, Q> { sem: &'self Sem } #[doc(hidden)] #[unsafe_destructor] -impl<'self, Q:Owned> Drop for SemReleaseGeneric<'self, Q> { +impl<'self, Q:Send> Drop for SemReleaseGeneric<'self, Q> { fn drop(&self) { self.sem.release(); } diff --git a/src/libextra/timer.rs b/src/libextra/timer.rs index 71d8a5d81e7..5a622ddfa0d 100644 --- a/src/libextra/timer.rs +++ b/src/libextra/timer.rs @@ -39,7 +39,7 @@ use core::libc; * * ch - a channel of type T to send a `val` on * * val - a value of type T to send over the provided `ch` */ -pub fn delayed_send(iotask: &IoTask, +pub fn delayed_send(iotask: &IoTask, msecs: uint, ch: &Chan, val: T) { @@ -119,7 +119,7 @@ pub fn sleep(iotask: &IoTask, msecs: uint) { * on the provided port in the allotted timeout period, then the result will * be a `Some(T)`. If not, then `None` will be returned. */ -pub fn recv_timeout(iotask: &IoTask, +pub fn recv_timeout(iotask: &IoTask, msecs: uint, wait_po: &Port) -> Option { diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index a014293f063..567f9eda2fb 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -272,7 +272,7 @@ impl Context { } } - pub fn prep + Decodable>(@self, // FIXME(#5121) fn_name:&str, @@ -292,7 +292,7 @@ trait TPrep { fn declare_input(&mut self, kind:&str, name:&str, val:&str); fn is_fresh(&self, cat:&str, kind:&str, name:&str, val:&str) -> bool; fn all_fresh(&self, cat:&str, map:&WorkMap) -> bool; - fn exec + Decodable>( // FIXME(#5121) &self, blk: ~fn(&Exec) -> T) -> Work; @@ -328,7 +328,7 @@ impl TPrep for Prep { return true; } - fn exec + Decodable>( // FIXME(#5121) &self, blk: ~fn(&Exec) -> T) -> Work { @@ -365,7 +365,7 @@ impl TPrep for Prep { } } -impl + Decodable> Work { // FIXME(#5121) pub fn new(p: @mut Prep, e: Either>) -> Work { @@ -374,7 +374,7 @@ impl + Decodable>( // FIXME(#5121) w: Work) -> T { diff --git a/src/librustc/middle/borrowck/doc.rs b/src/librustc/middle/borrowck/doc.rs index 7a91f204b13..8bb5c4620ef 100644 --- a/src/librustc/middle/borrowck/doc.rs +++ b/src/librustc/middle/borrowck/doc.rs @@ -359,7 +359,7 @@ of its owner: LIFETIME(LV.f, LT, MQ) // L-Field LIFETIME(LV, LT, MQ) - LIFETIME(*LV, LT, MQ) // L-Deref-Owned + LIFETIME(*LV, LT, MQ) // L-Deref-Send TYPE(LV) = ~Ty LIFETIME(LV, LT, MQ) @@ -504,7 +504,7 @@ must prevent the owned pointer `LV` from being mutated, which means that we always add `MUTATE` and `CLAIM` to the restriction set imposed on `LV`: - RESTRICTIONS(*LV, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Owned-Pointer + RESTRICTIONS(*LV, ACTIONS) = RS, (*LV, ACTIONS) // R-Deref-Send-Pointer TYPE(LV) = ~Ty RESTRICTIONS(LV, ACTIONS|MUTATE|CLAIM) = RS diff --git a/src/librustc/middle/borrowck/gather_loans/lifetime.rs b/src/librustc/middle/borrowck/gather_loans/lifetime.rs index 9455340268e..131ee5aa067 100644 --- a/src/librustc/middle/borrowck/gather_loans/lifetime.rs +++ b/src/librustc/middle/borrowck/gather_loans/lifetime.rs @@ -109,7 +109,7 @@ impl GuaranteeLifetimeContext { } mc::cat_downcast(base) | - mc::cat_deref(base, _, mc::uniq_ptr(*)) | // L-Deref-Owned + mc::cat_deref(base, _, mc::uniq_ptr(*)) | // L-Deref-Send mc::cat_interior(base, _) => { // L-Field self.check(base, discr_scope) } diff --git a/src/librustc/middle/borrowck/gather_loans/restrictions.rs b/src/librustc/middle/borrowck/gather_loans/restrictions.rs index a867ea94802..5f4251ad0a4 100644 --- a/src/librustc/middle/borrowck/gather_loans/restrictions.rs +++ b/src/librustc/middle/borrowck/gather_loans/restrictions.rs @@ -103,7 +103,7 @@ impl RestrictionsContext { } mc::cat_deref(cmt_base, _, mc::uniq_ptr(*)) => { - // R-Deref-Owned-Pointer + // R-Deref-Send-Pointer // // When we borrow the interior of an owned pointer, we // cannot permit the base to be mutated, because that diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index de6b792032b..58a527f3501 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -538,7 +538,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) { check_pointer_pat(pcx, Managed, inner, pat.id, pat.span, expected); } ast::pat_uniq(inner) => { - check_pointer_pat(pcx, Owned, inner, pat.id, pat.span, expected); + check_pointer_pat(pcx, Send, inner, pat.id, pat.span, expected); } ast::pat_region(inner) => { check_pointer_pat(pcx, Borrowed, inner, pat.id, pat.span, expected); @@ -624,7 +624,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, ty::ty_box(e_inner) if pointer_kind == Managed => { check_inner(e_inner); } - ty::ty_uniq(e_inner) if pointer_kind == Owned => { + ty::ty_uniq(e_inner) if pointer_kind == Send => { check_inner(e_inner); } ty::ty_rptr(_, e_inner) if pointer_kind == Borrowed => { @@ -641,7 +641,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, Some(expected), fmt!("%s pattern", match pointer_kind { Managed => "an @-box", - Owned => "a ~-box", + Send => "a ~-box", Borrowed => "an &-pointer" }), None); @@ -651,4 +651,4 @@ pub fn check_pointer_pat(pcx: &pat_ctxt, } #[deriving(Eq)] -enum PointerKind { Managed, Owned, Borrowed } +enum PointerKind { Managed, Send, Borrowed } diff --git a/src/librustdoc/astsrv.rs b/src/librustdoc/astsrv.rs index 3775aafb569..27ab3aca020 100644 --- a/src/librustdoc/astsrv.rs +++ b/src/librustdoc/astsrv.rs @@ -99,7 +99,7 @@ fn act(po: &Port, source: @str, parse: Parser) { } } -pub fn exec( +pub fn exec( srv: Srv, f: ~fn(ctxt: Ctxt) -> T ) -> T { diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index 1c34007c99d..a2e50d37fb6 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -101,7 +101,7 @@ fn fold_item( } } -fn parse_item_attrs( +fn parse_item_attrs( srv: astsrv::Srv, id: doc::AstId, parse_attrs: ~fn(a: ~[ast::attribute]) -> T) -> T { diff --git a/src/libstd/clone.rs b/src/libstd/clone.rs index 4a85a8c871d..947aa5708c2 100644 --- a/src/libstd/clone.rs +++ b/src/libstd/clone.rs @@ -112,7 +112,7 @@ impl DeepClone for ~T { fn deep_clone(&self) -> ~T { ~(**self).deep_clone() } } -// FIXME: #6525: should also be implemented for `T: Owned + DeepClone` +// FIXME: #6525: should also be implemented for `T: Send + DeepClone` impl DeepClone for @T { /// Return a deep copy of the managed box. The `Freeze` trait is required to prevent performing /// a deep clone of a potentially cyclical type. @@ -120,7 +120,7 @@ impl DeepClone for @T { fn deep_clone(&self) -> @T { @(**self).deep_clone() } } -// FIXME: #6525: should also be implemented for `T: Owned + DeepClone` +// FIXME: #6525: should also be implemented for `T: Send + DeepClone` impl DeepClone for @mut T { /// Return a deep copy of the managed box. The `Freeze` trait is required to prevent performing /// a deep clone of a potentially cyclical type. diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index 7918abe4ae6..8316a33ecf1 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -17,7 +17,7 @@ Message passing use cast::{transmute, transmute_mut}; use container::Container; use either::{Either, Left, Right}; -use kinds::Owned; +use kinds::Send; use option::{Option, Some, None}; use uint; use vec::OwnedVector; @@ -77,7 +77,7 @@ pub struct Port { These allow sending or receiving an unlimited number of messages. */ -pub fn stream() -> (Port, Chan) { +pub fn stream() -> (Port, Chan) { let (port, chan) = match rt::context() { rt::OldTaskContext => match pipesy::stream() { (p, c) => (Left(p), Left(c)) @@ -91,7 +91,7 @@ pub fn stream() -> (Port, Chan) { return (port, chan); } -impl GenericChan for Chan { +impl GenericChan for Chan { fn send(&self, x: T) { match self.inner { Left(ref chan) => chan.send(x), @@ -100,7 +100,7 @@ impl GenericChan for Chan { } } -impl GenericSmartChan for Chan { +impl GenericSmartChan for Chan { fn try_send(&self, x: T) -> bool { match self.inner { Left(ref chan) => chan.try_send(x), @@ -109,7 +109,7 @@ impl GenericSmartChan for Chan { } } -impl GenericPort for Port { +impl GenericPort for Port { fn recv(&self) -> T { match self.inner { Left(ref port) => port.recv(), @@ -125,7 +125,7 @@ impl GenericPort for Port { } } -impl Peekable for Port { +impl Peekable for Port { fn peek(&self) -> bool { match self.inner { Left(ref port) => port.peek(), @@ -134,7 +134,7 @@ impl Peekable for Port { } } -impl Selectable for Port { +impl Selectable for Port { fn header(&mut self) -> *mut PacketHeader { match self.inner { Left(ref mut port) => port.header(), @@ -149,7 +149,7 @@ pub struct PortSet { ports: ~[pipesy::Port], } -impl PortSet { +impl PortSet { pub fn new() -> PortSet { PortSet { ports: ~[] @@ -175,7 +175,7 @@ impl PortSet { } } -impl GenericPort for PortSet { +impl GenericPort for PortSet { fn try_recv(&self) -> Option { unsafe { let self_ports = transmute_mut(&self.ports); @@ -204,7 +204,7 @@ impl GenericPort for PortSet { } } -impl Peekable for PortSet { +impl Peekable for PortSet { fn peek(&self) -> bool { // It'd be nice to use self.port.each, but that version isn't // pure. @@ -223,7 +223,7 @@ pub struct SharedChan { ch: Exclusive> } -impl SharedChan { +impl SharedChan { /// Converts a `chan` into a `shared_chan`. pub fn new(c: Chan) -> SharedChan { let Chan { inner } = c; @@ -235,7 +235,7 @@ impl SharedChan { } } -impl GenericChan for SharedChan { +impl GenericChan for SharedChan { fn send(&self, x: T) { unsafe { let mut xx = Some(x); @@ -247,7 +247,7 @@ impl GenericChan for SharedChan { } } -impl GenericSmartChan for SharedChan { +impl GenericSmartChan for SharedChan { fn try_send(&self, x: T) -> bool { unsafe { let mut xx = Some(x); @@ -259,7 +259,7 @@ impl GenericSmartChan for SharedChan { } } -impl ::clone::Clone for SharedChan { +impl ::clone::Clone for SharedChan { fn clone(&self) -> SharedChan { SharedChan { ch: self.ch.clone() } } @@ -273,7 +273,7 @@ pub struct ChanOne { inner: Either, rtcomm::ChanOne> } -pub fn oneshot() -> (PortOne, ChanOne) { +pub fn oneshot() -> (PortOne, ChanOne) { let (port, chan) = match rt::context() { rt::OldTaskContext => match pipesy::oneshot() { (p, c) => (Left(p), Left(c)), @@ -287,7 +287,7 @@ pub fn oneshot() -> (PortOne, ChanOne) { return (port, chan); } -impl PortOne { +impl PortOne { pub fn recv(self) -> T { let PortOne { inner } = self; match inner { @@ -305,7 +305,7 @@ impl PortOne { } } -impl ChanOne { +impl ChanOne { pub fn send(self, data: T) { let ChanOne { inner } = self; match inner { @@ -323,7 +323,7 @@ impl ChanOne { } } -pub fn recv_one(port: PortOne) -> T { +pub fn recv_one(port: PortOne) -> T { let PortOne { inner } = port; match inner { Left(p) => pipesy::recv_one(p), @@ -331,7 +331,7 @@ pub fn recv_one(port: PortOne) -> T { } } -pub fn try_recv_one(port: PortOne) -> Option { +pub fn try_recv_one(port: PortOne) -> Option { let PortOne { inner } = port; match inner { Left(p) => pipesy::try_recv_one(p), @@ -339,7 +339,7 @@ pub fn try_recv_one(port: PortOne) -> Option { } } -pub fn send_one(chan: ChanOne, data: T) { +pub fn send_one(chan: ChanOne, data: T) { let ChanOne { inner } = chan; match inner { Left(c) => pipesy::send_one(c, data), @@ -347,7 +347,7 @@ pub fn send_one(chan: ChanOne, data: T) { } } -pub fn try_send_one(chan: ChanOne, data: T) -> bool { +pub fn try_send_one(chan: ChanOne, data: T) -> bool { let ChanOne { inner } = chan; match inner { Left(c) => pipesy::try_send_one(c, data), @@ -357,7 +357,7 @@ pub fn try_send_one(chan: ChanOne, data: T) -> bool { mod pipesy { - use kinds::Owned; + use kinds::Send; use option::{Option, Some, None}; use pipes::{recv, try_recv, peek, PacketHeader}; use super::{GenericChan, GenericSmartChan, GenericPort, Peekable, Selectable}; @@ -365,17 +365,17 @@ mod pipesy { use util::replace; /*proto! oneshot ( - Oneshot:send { + Oneshot:send { send(T) -> ! } )*/ #[allow(non_camel_case_types)] pub mod oneshot { - priv use core::kinds::Owned; + priv use core::kinds::Send; use ptr::to_mut_unsafe_ptr; - pub fn init() -> (server::Oneshot, client::Oneshot) { + pub fn init() -> (server::Oneshot, client::Oneshot) { pub use core::pipes::HasBuffer; let buffer = ~::core::pipes::Buffer { @@ -399,10 +399,10 @@ mod pipesy { #[allow(non_camel_case_types)] pub mod client { - priv use core::kinds::Owned; + priv use core::kinds::Send; #[allow(non_camel_case_types)] - pub fn try_send(pipe: Oneshot, x_0: T) -> + pub fn try_send(pipe: Oneshot, x_0: T) -> ::core::option::Option<()> { { use super::send; @@ -414,7 +414,7 @@ mod pipesy { } #[allow(non_camel_case_types)] - pub fn send(pipe: Oneshot, x_0: T) { + pub fn send(pipe: Oneshot, x_0: T) { { use super::send; let message = send(x_0); @@ -464,12 +464,12 @@ mod pipesy { } /// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair. - pub fn oneshot() -> (PortOne, ChanOne) { + pub fn oneshot() -> (PortOne, ChanOne) { let (port, chan) = oneshot::init(); (PortOne::new(port), ChanOne::new(chan)) } - impl PortOne { + impl PortOne { pub fn recv(self) -> T { recv_one(self) } pub fn try_recv(self) -> Option { try_recv_one(self) } pub fn unwrap(self) -> oneshot::server::Oneshot { @@ -479,7 +479,7 @@ mod pipesy { } } - impl ChanOne { + impl ChanOne { pub fn send(self, data: T) { send_one(self, data) } pub fn try_send(self, data: T) -> bool { try_send_one(self, data) } pub fn unwrap(self) -> oneshot::client::Oneshot { @@ -493,7 +493,7 @@ mod pipesy { * 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 { match port { PortOne { contents: port } => { let oneshot::send(message) = recv(port); @@ -503,7 +503,7 @@ mod pipesy { } /// 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 { match port { PortOne { contents: port } => { let message = try_recv(port); @@ -519,7 +519,7 @@ mod pipesy { } /// 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) { match chan { ChanOne { contents: chan } => oneshot::client::send(chan, data), } @@ -529,7 +529,7 @@ mod pipesy { * Send a message on a oneshot pipe, or return false if the connection was * closed. */ - pub fn try_send_one(chan: ChanOne, data: T) -> bool { + pub fn try_send_one(chan: ChanOne, data: T) -> bool { match chan { ChanOne { contents: chan } => { oneshot::client::try_send(chan, data).is_some() @@ -540,16 +540,16 @@ mod pipesy { // Streams - Make pipes a little easier in general. /*proto! streamp ( - Open:send { + Open:send { data(T) -> Open } )*/ #[allow(non_camel_case_types)] pub mod streamp { - priv use core::kinds::Owned; + priv use core::kinds::Send; - pub fn init() -> (server::Open, client::Open) { + pub fn init() -> (server::Open, client::Open) { pub use core::pipes::HasBuffer; ::core::pipes::entangle() } @@ -559,10 +559,10 @@ mod pipesy { #[allow(non_camel_case_types)] pub mod client { - priv use core::kinds::Owned; + priv use core::kinds::Send; #[allow(non_camel_case_types)] - pub fn try_data(pipe: Open, x_0: T) -> + pub fn try_data(pipe: Open, x_0: T) -> ::core::option::Option> { { use super::data; @@ -575,7 +575,7 @@ mod pipesy { } #[allow(non_camel_case_types)] - pub fn data(pipe: Open, x_0: T) -> Open { + pub fn data(pipe: Open, x_0: T) -> Open { { use super::data; let (s, c) = ::core::pipes::entangle(); @@ -613,7 +613,7 @@ mod pipesy { These allow sending or receiving an unlimited number of messages. */ - pub fn stream() -> (Port, Chan) { + pub fn stream() -> (Port, Chan) { let (s, c) = streamp::init(); (Port { @@ -623,7 +623,7 @@ mod pipesy { }) } - impl GenericChan for Chan { + impl GenericChan for Chan { #[inline] fn send(&self, x: T) { unsafe { @@ -634,7 +634,7 @@ mod pipesy { } } - impl GenericSmartChan for Chan { + impl GenericSmartChan for Chan { #[inline] fn try_send(&self, x: T) -> bool { unsafe { @@ -651,7 +651,7 @@ mod pipesy { } } - impl GenericPort for Port { + impl GenericPort for Port { #[inline] fn recv(&self) -> T { unsafe { @@ -679,7 +679,7 @@ mod pipesy { } } - impl Peekable for Port { + impl Peekable for Port { #[inline] fn peek(&self) -> bool { unsafe { @@ -695,7 +695,7 @@ mod pipesy { } } - impl Selectable for Port { + impl Selectable for Port { fn header(&mut self) -> *mut PacketHeader { match self.endp { Some(ref mut endp) => endp.header(), @@ -723,15 +723,15 @@ pub fn select2i(a: &mut A, b: &mut B) } /// Receive a message from one of two endpoints. -pub trait Select2 { +pub trait Select2 { /// Receive a message or return `None` if a connection closes. fn try_select(&mut self) -> Either, Option>; /// Receive a message or fail if a connection closes. fn select(&mut self) -> Either; } -impl, Right:Selectable + GenericPort> Select2 diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index 9d5348ff98f..f350e106168 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -24,7 +24,7 @@ The 4 kinds are scalar types and managed pointers, and exludes owned pointers. It also excludes types that implement `Drop`. -* Owned - owned types and types containing owned types. These types +* Send - owned types and types containing owned types. These types may be transferred across task boundaries. * Freeze - types that are deeply immutable. @@ -45,13 +45,13 @@ pub trait Copy { #[cfg(stage0)] #[lang="owned"] -pub trait Owned { +pub trait Send { // empty. } #[cfg(not(stage0))] #[lang="send"] -pub trait Owned { +pub trait Send { // empty. } diff --git a/src/libstd/pipes.rs b/src/libstd/pipes.rs index 661dc2a659f..49713a3a23b 100644 --- a/src/libstd/pipes.rs +++ b/src/libstd/pipes.rs @@ -88,7 +88,7 @@ use container::Container; use cast::{forget, transmute, transmute_copy, transmute_mut}; use either::{Either, Left, Right}; use iterator::IteratorUtil; -use kinds::Owned; +use kinds::Send; use libc; use ops::Drop; use option::{None, Option, Some}; @@ -177,7 +177,7 @@ impl PacketHeader { transmute_copy(&self.buffer) } - pub fn set_buffer(&mut self, b: ~Buffer) { + pub fn set_buffer(&mut self, b: ~Buffer) { unsafe { self.buffer = transmute_copy(&b); } @@ -193,13 +193,13 @@ pub trait HasBuffer { fn set_buffer(&mut self, b: *libc::c_void); } -impl HasBuffer for Packet { +impl HasBuffer for Packet { fn set_buffer(&mut self, b: *libc::c_void) { self.header.buffer = b; } } -pub fn mk_packet() -> Packet { +pub fn mk_packet() -> Packet { Packet { header: PacketHeader(), payload: None, @@ -230,7 +230,7 @@ pub fn packet() -> *mut Packet { p } -pub fn entangle_buffer( +pub fn entangle_buffer( mut buffer: ~Buffer, init: &fn(*libc::c_void, x: &mut T) -> *mut Packet) -> (RecvPacketBuffered, SendPacketBuffered) { @@ -396,7 +396,7 @@ pub fn send(mut p: SendPacketBuffered, Fails if the sender closes the connection. */ -pub fn recv( +pub fn recv( p: RecvPacketBuffered) -> T { try_recv(p).expect("connection closed") } @@ -407,7 +407,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(mut p: RecvPacketBuffered) +pub fn try_recv(mut p: RecvPacketBuffered) -> Option { let p_ = p.unwrap(); let p = unsafe { &mut *p_ }; @@ -427,7 +427,7 @@ pub fn try_recv(mut p: RecvPacketBuffered) } } -fn try_recv_(p: &mut Packet) -> Option { +fn try_recv_(p: &mut Packet) -> Option { // optimistic path match p.header.state { Full => { @@ -511,7 +511,7 @@ fn try_recv_(p: &mut Packet) -> Option { } /// Returns true if messages are available. -pub fn peek(p: &mut RecvPacketBuffered) -> bool { +pub fn peek(p: &mut RecvPacketBuffered) -> bool { unsafe { match (*p.header()).state { Empty | Terminated => false, @@ -521,7 +521,7 @@ pub fn peek(p: &mut RecvPacketBuffered) -> bool { } } -fn sender_terminate(p: *mut Packet) { +fn sender_terminate(p: *mut Packet) { let p = unsafe { &mut *p }; @@ -553,7 +553,7 @@ fn sender_terminate(p: *mut Packet) { } } -fn receiver_terminate(p: *mut Packet) { +fn receiver_terminate(p: *mut Packet) { let p = unsafe { &mut *p }; @@ -671,7 +671,7 @@ pub struct SendPacketBuffered { } #[unsafe_destructor] -impl Drop for SendPacketBuffered { +impl Drop for SendPacketBuffered { fn drop(&self) { unsafe { let this: &mut SendPacketBuffered = transmute(self); @@ -729,7 +729,7 @@ pub struct RecvPacketBuffered { } #[unsafe_destructor] -impl Drop for RecvPacketBuffered { +impl Drop for RecvPacketBuffered { fn drop(&self) { unsafe { let this: &mut RecvPacketBuffered = transmute(self); @@ -741,7 +741,7 @@ impl Drop for RecvPacketBuffered { } } -impl RecvPacketBuffered { +impl RecvPacketBuffered { pub fn unwrap(&mut self) -> *mut Packet { replace(&mut self.p, None).unwrap() } @@ -751,7 +751,7 @@ impl RecvPacketBuffered { } } -impl Selectable for RecvPacketBuffered { +impl Selectable for RecvPacketBuffered { fn header(&mut self) -> *mut PacketHeader { match self.p { Some(packet) => unsafe { @@ -807,7 +807,7 @@ Sometimes messages will be available on both endpoints at once. In this case, `select2` may return either `left` or `right`. */ -pub fn select2( +pub fn select2( mut a: RecvPacketBuffered, mut b: RecvPacketBuffered) -> Either<(Option, RecvPacketBuffered), @@ -847,7 +847,7 @@ pub fn select2i(a: &mut A, b: &mut B) /// Waits on a set of endpoints. Returns a message, its index, and a /// list of the remaining endpoints. -pub fn select(mut endpoints: ~[RecvPacketBuffered]) +pub fn select(mut endpoints: ~[RecvPacketBuffered]) -> (uint, Option, ~[RecvPacketBuffered]) { diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 5959cdaf318..13d19b276f5 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -30,7 +30,7 @@ Rust's prelude has three main parts: // Reexported core operators pub use either::{Either, Left, Right}; pub use kinds::{Copy, Sized}; -pub use kinds::{Freeze, Owned}; +pub use kinds::{Freeze, Send}; pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not}; pub use ops::{BitAnd, BitOr, BitXor}; pub use ops::{Drop}; diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 75b1d8f3810..72907f40a07 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -19,7 +19,7 @@ use option::*; use cast; use util; use ops::Drop; -use kinds::Owned; +use kinds::Send; use rt::sched::{Scheduler, Coroutine}; use rt::local::Local; use unstable::intrinsics::{atomic_xchg, atomic_load}; @@ -68,7 +68,7 @@ pub struct PortOneHack { suppress_finalize: bool } -pub fn oneshot() -> (PortOne, ChanOne) { +pub fn oneshot() -> (PortOne, ChanOne) { let packet: ~Packet = ~Packet { state: STATE_BOTH, payload: None @@ -307,20 +307,20 @@ pub struct Port { next: Cell>> } -pub fn stream() -> (Port, Chan) { +pub fn stream() -> (Port, Chan) { let (pone, cone) = oneshot(); let port = Port { next: Cell::new(pone) }; let chan = Chan { next: Cell::new(cone) }; return (port, chan); } -impl GenericChan for Chan { +impl GenericChan for Chan { fn send(&self, val: T) { self.try_send(val); } } -impl GenericSmartChan for Chan { +impl GenericSmartChan for Chan { fn try_send(&self, val: T) -> bool { let (next_pone, next_cone) = oneshot(); let cone = self.next.take(); diff --git a/src/libstd/rt/message_queue.rs b/src/libstd/rt/message_queue.rs index 5b60543344d..d561e81d032 100644 --- a/src/libstd/rt/message_queue.rs +++ b/src/libstd/rt/message_queue.rs @@ -9,7 +9,7 @@ // except according to those terms. use container::Container; -use kinds::Owned; +use kinds::Send; use vec::OwnedVector; use cell::Cell; use option::*; @@ -21,7 +21,7 @@ pub struct MessageQueue { priv queue: ~Exclusive<~[T]> } -impl MessageQueue { +impl MessageQueue { pub fn new() -> MessageQueue { MessageQueue { queue: ~exclusive(~[]) diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index cfffc55a58c..00d27744268 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -13,7 +13,7 @@ use option::*; use vec::OwnedVector; use unstable::sync::{Exclusive, exclusive}; use cell::Cell; -use kinds::Owned; +use kinds::Send; use clone::Clone; pub struct WorkQueue { @@ -21,7 +21,7 @@ pub struct WorkQueue { priv queue: ~Exclusive<~[T]> } -impl WorkQueue { +impl WorkQueue { pub fn new() -> WorkQueue { WorkQueue { queue: ~exclusive(~[]) diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index b558b9d53a3..a8e8cfd163a 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -353,7 +353,7 @@ impl TaskBuilder { } /// Runs a task, while transfering ownership of one argument to the child. - pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { + pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { let arg = Cell::new(arg); do self.spawn { f(arg.take()); @@ -373,7 +373,7 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - pub fn try(&mut self, f: ~fn() -> T) -> Result { + pub fn try(&mut self, f: ~fn() -> T) -> Result { let (po, ch) = stream::(); let mut result = None; @@ -445,7 +445,7 @@ pub fn spawn_supervised(f: ~fn()) { task.spawn(f) } -pub fn spawn_with(arg: A, f: ~fn(v: A)) { +pub fn spawn_with(arg: A, f: ~fn(v: A)) { /*! * Runs a task, while transfering ownership of one argument to the * child. @@ -478,7 +478,7 @@ pub fn spawn_sched(mode: SchedMode, f: ~fn()) { task.spawn(f) } -pub fn try(f: ~fn() -> T) -> Result { +pub fn try(f: ~fn() -> T) -> Result { /*! * Execute a function in another task and return either the return value * of the function or result::err. diff --git a/src/libstd/unstable/global.rs b/src/libstd/unstable/global.rs index 4fde8f704b9..285a8114cc2 100644 --- a/src/libstd/unstable/global.rs +++ b/src/libstd/unstable/global.rs @@ -27,7 +27,7 @@ avoid hitting the mutex. use cast::{transmute}; use clone::Clone; -use kinds::Owned; +use kinds::Send; use libc::{c_void}; use option::{Option, Some, None}; use ops::Drop; @@ -43,7 +43,7 @@ use sys::Closure; pub type GlobalDataKey<'self,T> = &'self fn(v: T); -pub unsafe fn global_data_clone_create( +pub unsafe fn global_data_clone_create( key: GlobalDataKey, create: &fn() -> ~T) -> T { /*! * Clone a global value or, if it has not been created, @@ -59,7 +59,7 @@ pub unsafe fn global_data_clone_create( global_data_clone_create_(key_ptr(key), create) } -unsafe fn global_data_clone_create_( +unsafe fn global_data_clone_create_( key: uint, create: &fn() -> ~T) -> T { let mut clone_value: Option = None; @@ -79,13 +79,13 @@ unsafe fn global_data_clone_create_( return clone_value.unwrap(); } -unsafe fn global_data_modify( +unsafe fn global_data_modify( key: GlobalDataKey, op: &fn(Option<~T>) -> Option<~T>) { global_data_modify_(key_ptr(key), op) } -unsafe fn global_data_modify_( +unsafe fn global_data_modify_( key: uint, op: &fn(Option<~T>) -> Option<~T>) { let mut old_dtor = None; @@ -124,7 +124,7 @@ unsafe fn global_data_modify_( } } -pub unsafe fn global_data_clone( +pub unsafe fn global_data_clone( key: GlobalDataKey) -> Option { let mut maybe_clone: Option = None; do global_data_modify(key) |current| { @@ -220,7 +220,7 @@ fn get_global_state() -> Exclusive { } } -fn key_ptr(key: GlobalDataKey) -> uint { +fn key_ptr(key: GlobalDataKey) -> uint { unsafe { let closure: Closure = transmute(key); return transmute(closure.code); diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index 0f9298595ee..06c3ecb8147 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -17,7 +17,7 @@ use unstable::finally::Finally; use unstable::intrinsics; use ops::Drop; use clone::Clone; -use kinds::Owned; +use kinds::Send; /// An atomically reference counted pointer. /// @@ -31,7 +31,7 @@ struct AtomicRcBoxData { data: Option, } -impl UnsafeAtomicRcBox { +impl UnsafeAtomicRcBox { pub fn new(data: T) -> UnsafeAtomicRcBox { unsafe { let data = ~AtomicRcBoxData { count: 1, data: Some(data) }; @@ -61,7 +61,7 @@ impl UnsafeAtomicRcBox { } } -impl Clone for UnsafeAtomicRcBox { +impl Clone for UnsafeAtomicRcBox { fn clone(&self) -> UnsafeAtomicRcBox { unsafe { let mut data: ~AtomicRcBoxData = cast::transmute(self.data); @@ -144,7 +144,7 @@ pub struct Exclusive { x: UnsafeAtomicRcBox> } -pub fn exclusive(user_data: T) -> Exclusive { +pub fn exclusive(user_data: T) -> Exclusive { let data = ExData { lock: LittleLock(), failed: false, @@ -155,14 +155,14 @@ pub fn exclusive(user_data: T) -> Exclusive { } } -impl Clone for Exclusive { +impl Clone for Exclusive { // Duplicate an exclusive ARC, as std::arc::clone. fn clone(&self) -> Exclusive { Exclusive { x: self.x.clone() } } } -impl Exclusive { +impl Exclusive { // Exactly like std::arc::mutex_arc,access(), but with the little_lock // instead of a proper mutex. Same reason for being unsafe. // diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a9b0c3986f8..265e9e444e9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -147,7 +147,7 @@ pub static crate_node_id: node_id = 0; // The AST represents all type param bounds as types. // typeck::collect::compute_bounds matches these against // the "special" built-in traits (see middle::lang_items) and -// detects Copy, Send, Owned, and Freeze. +// detects Copy, Send, Send, and Freeze. pub enum TyParamBound { TraitTyParamBound(@trait_ref), RegionTyParamBound diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index d1d4d173a3f..c9d63d2c416 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -30,7 +30,7 @@ pub fn expand_deriving_to_str(cx: @ExtCtxt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: ~[], - ret_ty: Ptr(~Literal(Path::new_local("str")), Owned), + ret_ty: Ptr(~Literal(Path::new_local("str")), Send), const_nonmatching: false, combine_substructure: to_str_substructure } diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 2f21eba11d7..a2f9aa58d99 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -22,7 +22,7 @@ use opt_vec; /// The types of pointers pub enum PtrTy<'self> { - Owned, // ~ + Send, // ~ Managed(ast::mutability), // @[mut] Borrowed(Option<&'self str>, ast::mutability), // &['lifetime] [mut] } @@ -128,7 +128,7 @@ impl<'self> Ty<'self> { Ptr(ref ty, ref ptr) => { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); match *ptr { - Owned => { + Send => { cx.ty_uniq(span, raw_ty) } Managed(mutbl) => { @@ -248,7 +248,7 @@ pub fn get_explicit_self(cx: @ExtCtxt, span: span, self_ptr: &Option) let self_ty = respan( span, match *ptr { - Owned => ast::sty_uniq(ast::m_imm), + Send => ast::sty_uniq(ast::m_imm), Managed(mutbl) => ast::sty_box(mutbl), Borrowed(ref lt, mutbl) => { let lt = lt.map(|s| @cx.lifetime(span, diff --git a/src/test/auxiliary/cci_capture_clause.rs b/src/test/auxiliary/cci_capture_clause.rs index e45bfc8ea5d..beca0adbe3c 100644 --- a/src/test/auxiliary/cci_capture_clause.rs +++ b/src/test/auxiliary/cci_capture_clause.rs @@ -11,7 +11,7 @@ use std::comm::*; use std::task; -pub fn foo(x: T) -> Port { +pub fn foo(x: T) -> Port { let (p, c) = stream(); do task::spawn() { c.send(copy x); diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs index 63e4174a0fc..1d32a78303a 100644 --- a/src/test/bench/pingpong.rs +++ b/src/test/bench/pingpong.rs @@ -82,7 +82,7 @@ endpoint. The send endpoint is returned to the caller and the receive endpoint is passed to the new task. */ -pub fn spawn_service( +pub fn spawn_service( init: extern fn() -> (RecvPacketBuffered, SendPacketBuffered), service: ~fn(v: RecvPacketBuffered)) @@ -103,7 +103,7 @@ pub fn spawn_service( receive state. */ -pub fn spawn_service_recv( +pub fn spawn_service_recv( init: extern fn() -> (SendPacketBuffered, RecvPacketBuffered), service: ~fn(v: SendPacketBuffered)) @@ -120,7 +120,7 @@ pub fn spawn_service_recv( client } -fn switch(endp: std::pipes::RecvPacketBuffered, +fn switch(endp: std::pipes::RecvPacketBuffered, f: &fn(v: Option) -> U) -> U { f(std::pipes::try_recv(endp)) diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index 887346e35e5..6ffdd0f541e 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -5,7 +5,7 @@ fn take_any(_: &fn:()) { fn take_copyable(_: &fn:Copy()) { } -fn take_copyable_owned(_: &fn:Copy+Owned()) { +fn take_copyable_owned(_: &fn:Copy+Send()) { } fn take_const_owned(_: &fn:Const+Owned()) { @@ -14,22 +14,22 @@ fn take_const_owned(_: &fn:Const+Owned()) { fn give_any(f: &fn:()) { take_any(f); take_copyable(f); //~ ERROR expected bounds `Copy` but found no bounds - take_copyable_owned(f); //~ ERROR expected bounds `Copy+Owned` but found no bounds + take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found no bounds } fn give_copyable(f: &fn:Copy()) { take_any(f); take_copyable(f); - take_copyable_owned(f); //~ ERROR expected bounds `Copy+Owned` but found bounds `Copy` + take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found bounds `Copy` } -fn give_owned(f: &fn:Owned()) { +fn give_owned(f: &fn:Send()) { take_any(f); - take_copyable(f); //~ ERROR expected bounds `Copy` but found bounds `Owned` - take_copyable_owned(f); //~ ERROR expected bounds `Copy+Owned` but found bounds `Owned` + take_copyable(f); //~ ERROR expected bounds `Copy` but found bounds `Send` + take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found bounds `Send` } -fn give_copyable_owned(f: &fn:Copy+Owned()) { +fn give_copyable_owned(f: &fn:Copy+Send()) { take_any(f); take_copyable(f); take_copyable_owned(f); diff --git a/src/test/compile-fail/issue-2766-a.rs b/src/test/compile-fail/issue-2766-a.rs index 91ae0e1c07a..c5d13c81b7c 100644 --- a/src/test/compile-fail/issue-2766-a.rs +++ b/src/test/compile-fail/issue-2766-a.rs @@ -9,12 +9,12 @@ // except according to those terms. pub mod stream { - pub enum Stream { send(T, ::stream::server::Stream), } + pub enum Stream { send(T, ::stream::server::Stream), } pub mod server { use std::option; use std::pipes; - impl Stream { + impl Stream { pub fn recv() -> extern fn(v: Stream) -> ::stream::Stream { // resolve really should report just one error here. // Change the test case when it changes. @@ -28,7 +28,7 @@ pub mod stream { } } - pub type Stream = pipes::RecvPacket<::stream::Stream>; + pub type Stream = pipes::RecvPacket<::stream::Stream>; } } diff --git a/src/test/compile-fail/kindck-destructor-owned.rs b/src/test/compile-fail/kindck-destructor-owned.rs index 551b50c94f2..00d73b02dbc 100644 --- a/src/test/compile-fail/kindck-destructor-owned.rs +++ b/src/test/compile-fail/kindck-destructor-owned.rs @@ -2,7 +2,7 @@ struct Foo { f: @mut int, } -impl Drop for Foo { //~ ERROR cannot implement a destructor on a struct that is not Owned +impl Drop for Foo { //~ ERROR cannot implement a destructor on a struct that is not Send fn drop(&self) { *self.f = 10; } diff --git a/src/test/compile-fail/liveness-use-after-send.rs b/src/test/compile-fail/liveness-use-after-send.rs index 23d3fff01cf..72555d7e851 100644 --- a/src/test/compile-fail/liveness-use-after-send.rs +++ b/src/test/compile-fail/liveness-use-after-send.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn send(ch: _chan, data: T) { +fn send(ch: _chan, data: T) { debug!(ch); debug!(data); fail!(); diff --git a/src/test/compile-fail/non_owned-enum.rs b/src/test/compile-fail/non_owned-enum.rs index 79c2be8183a..6068b7f1730 100644 --- a/src/test/compile-fail/non_owned-enum.rs +++ b/src/test/compile-fail/non_owned-enum.rs @@ -11,9 +11,9 @@ #[non_owned] enum Foo { A } -fn bar(_: T) {} +fn bar(_: T) {} fn main() { let x = A; - bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Owned` + bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Send` } diff --git a/src/test/compile-fail/non_owned-struct.rs b/src/test/compile-fail/non_owned-struct.rs index 2d0bc9a7e8e..b6f29df0575 100644 --- a/src/test/compile-fail/non_owned-struct.rs +++ b/src/test/compile-fail/non_owned-struct.rs @@ -11,9 +11,9 @@ #[non_owned] struct Foo { a: int } -fn bar(_: T) {} +fn bar(_: T) {} fn main() { let x = Foo { a: 5 }; - bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Owned` + bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Send` } diff --git a/src/test/compile-fail/unique-unique-kind.rs b/src/test/compile-fail/unique-unique-kind.rs index 26058bf89ca..d51df4979e3 100644 --- a/src/test/compile-fail/unique-unique-kind.rs +++ b/src/test/compile-fail/unique-unique-kind.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(_i: T) { +fn f(_i: T) { } fn main() { let i = ~@100; - f(i); //~ ERROR does not fulfill `Owned` + f(i); //~ ERROR does not fulfill `Send` } diff --git a/src/test/compile-fail/unsendable-class.rs b/src/test/compile-fail/unsendable-class.rs index 58de0926f7c..de089dcf914 100644 --- a/src/test/compile-fail/unsendable-class.rs +++ b/src/test/compile-fail/unsendable-class.rs @@ -27,6 +27,6 @@ fn foo(i:int, j: @~str) -> foo { fn main() { let cat = ~"kitty"; - let (_, ch) = comm::stream(); //~ ERROR does not fulfill `Owned` - ch.send(foo(42, @(cat))); //~ ERROR does not fulfill `Owned` + let (_, ch) = comm::stream(); //~ ERROR does not fulfill `Send` + ch.send(foo(42, @(cat))); //~ ERROR does not fulfill `Send` } diff --git a/src/test/run-fail/bug-811.rs b/src/test/run-fail/bug-811.rs index b497b0224b9..992747187f6 100644 --- a/src/test/run-fail/bug-811.rs +++ b/src/test/run-fail/bug-811.rs @@ -19,6 +19,6 @@ struct chan_t { port: port_id, } -fn send(ch: chan_t, data: T) { fail!(); } +fn send(ch: chan_t, data: T) { fail!(); } fn main() { fail!("quux"); } diff --git a/src/test/run-pass/alignment-gep-tup-like-2.rs b/src/test/run-pass/alignment-gep-tup-like-2.rs index 753e5339de9..24709fb2974 100644 --- a/src/test/run-pass/alignment-gep-tup-like-2.rs +++ b/src/test/run-pass/alignment-gep-tup-like-2.rs @@ -23,7 +23,7 @@ fn make_cycle(a: A) { g.rec = Some(g); } -fn f(a: A, b: B) -> @fn() -> (A, B) { +fn f(a: A, b: B) -> @fn() -> (A, B) { let result: @fn() -> (A, B) = || (copy a, copy b); result } diff --git a/src/test/run-pass/fixed-point-bind-unique.rs b/src/test/run-pass/fixed-point-bind-unique.rs index 53f9c723a47..c7b64fde3fd 100644 --- a/src/test/run-pass/fixed-point-bind-unique.rs +++ b/src/test/run-pass/fixed-point-bind-unique.rs @@ -10,11 +10,11 @@ // xfail-fast -fn fix_help(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B { +fn fix_help(f: extern fn(@fn(A) -> B, A) -> B, x: A) -> B { return f(|a| fix_help(f, a), x); } -fn fix(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B { +fn fix(f: extern fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B { return |a| fix_help(f, a); } diff --git a/src/test/run-pass/fn-bare-spawn.rs b/src/test/run-pass/fn-bare-spawn.rs index 4f0f451a08c..e9954be9357 100644 --- a/src/test/run-pass/fn-bare-spawn.rs +++ b/src/test/run-pass/fn-bare-spawn.rs @@ -10,7 +10,7 @@ // This is what the signature to spawn should look like with bare functions -fn spawn(val: T, f: extern fn(T)) { +fn spawn(val: T, f: extern fn(T)) { f(val); } diff --git a/src/test/run-pass/generic-alias-unique.rs b/src/test/run-pass/generic-alias-unique.rs index ad271186639..815cc1bc79b 100644 --- a/src/test/run-pass/generic-alias-unique.rs +++ b/src/test/run-pass/generic-alias-unique.rs @@ -10,7 +10,7 @@ -fn id(t: T) -> T { return t; } +fn id(t: T) -> T { return t; } pub fn main() { let expected = ~100; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 9fbca7d0572..14915555889 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -39,7 +39,7 @@ pub mod pipes { payload: Option } - pub fn packet() -> *packet { + pub fn packet() -> *packet { unsafe { let p: *packet = cast::transmute(~Stuff{ state: empty, @@ -74,7 +74,7 @@ pub mod pipes { } } - pub fn send(mut p: send_packet, payload: T) { + pub fn send(mut p: send_packet, payload: T) { let mut p = p.unwrap(); let mut p = unsafe { uniquify(p) }; assert!((*p).payload.is_none()); @@ -100,7 +100,7 @@ pub mod pipes { } } - pub fn recv(mut p: recv_packet) -> Option { + pub fn recv(mut p: recv_packet) -> Option { let mut p = p.unwrap(); let mut p = unsafe { uniquify(p) }; loop { @@ -120,7 +120,7 @@ pub mod pipes { } } - pub fn sender_terminate(mut p: *packet) { + pub fn sender_terminate(mut p: *packet) { let mut p = unsafe { uniquify(p) }; match swap_state_rel(&mut (*p).state, terminated) { empty | blocked => { @@ -137,7 +137,7 @@ pub mod pipes { } } - pub fn receiver_terminate(mut p: *packet) { + pub fn receiver_terminate(mut p: *packet) { let mut p = unsafe { uniquify(p) }; match swap_state_rel(&mut (*p).state, terminated) { empty => { @@ -159,7 +159,7 @@ pub mod pipes { } #[unsafe_destructor] - impl Drop for send_packet { + impl Drop for send_packet { fn drop(&self) { unsafe { if self.p != None { @@ -172,13 +172,13 @@ pub mod pipes { } } - impl send_packet { + impl send_packet { pub fn unwrap(&mut self) -> *packet { util::replace(&mut self.p, None).unwrap() } } - pub fn send_packet(p: *packet) -> send_packet { + pub fn send_packet(p: *packet) -> send_packet { send_packet { p: Some(p) } @@ -189,7 +189,7 @@ pub mod pipes { } #[unsafe_destructor] - impl Drop for recv_packet { + impl Drop for recv_packet { fn drop(&self) { unsafe { if self.p != None { @@ -202,19 +202,19 @@ pub mod pipes { } } - impl recv_packet { + impl recv_packet { pub fn unwrap(&mut self) -> *packet { util::replace(&mut self.p, None).unwrap() } } - pub fn recv_packet(p: *packet) -> recv_packet { + pub fn recv_packet(p: *packet) -> recv_packet { recv_packet { p: Some(p) } } - pub fn entangle() -> (send_packet, recv_packet) { + pub fn entangle() -> (send_packet, recv_packet) { let p = packet(); (send_packet(p), recv_packet(p)) } diff --git a/src/test/run-pass/issue-2834.rs b/src/test/run-pass/issue-2834.rs index 5d3a2d2331c..b0ddccf2894 100644 --- a/src/test/run-pass/issue-2834.rs +++ b/src/test/run-pass/issue-2834.rs @@ -12,7 +12,7 @@ // proto! streamp ( - open:send { + open:send { data(T) -> open } ) diff --git a/src/test/run-pass/issue-2930.rs b/src/test/run-pass/issue-2930.rs index cfce19826d7..10a19d62bd9 100644 --- a/src/test/run-pass/issue-2930.rs +++ b/src/test/run-pass/issue-2930.rs @@ -9,7 +9,7 @@ // except according to those terms. proto! stream ( - Stream:send { + Stream:send { send(T) -> Stream } ) diff --git a/src/test/run-pass/pipe-bank-proto.rs b/src/test/run-pass/pipe-bank-proto.rs index 7ac38966faa..11c43b93901 100644 --- a/src/test/run-pass/pipe-bank-proto.rs +++ b/src/test/run-pass/pipe-bank-proto.rs @@ -45,8 +45,8 @@ proto! bank ( } ) -fn switch(endp: pipes::RecvPacket, - f: &fn(v: Option) -> U) -> U { +fn switch(endp: pipes::RecvPacket, + f: &fn(v: Option) -> U) -> U { f(pipes::try_recv(endp)) } diff --git a/src/test/run-pass/pipe-select.rs b/src/test/run-pass/pipe-select.rs index 0a860d0a1e2..36f144152f2 100644 --- a/src/test/run-pass/pipe-select.rs +++ b/src/test/run-pass/pipe-select.rs @@ -29,12 +29,12 @@ proto! oneshot ( ) proto! stream ( - Stream:send { + Stream:send { send(T) -> Stream } ) -pub fn spawn_service( +pub fn spawn_service( init: extern fn() -> (RecvPacketBuffered, SendPacketBuffered), service: ~fn(v: RecvPacketBuffered)) diff --git a/src/test/run-pass/pipe-sleep.rs b/src/test/run-pass/pipe-sleep.rs index dc88f36ba11..dbf860cd040 100644 --- a/src/test/run-pass/pipe-sleep.rs +++ b/src/test/run-pass/pipe-sleep.rs @@ -33,7 +33,7 @@ endpoint. The send endpoint is returned to the caller and the receive endpoint is passed to the new task. */ -pub fn spawn_service( +pub fn spawn_service( init: extern fn() -> (RecvPacketBuffered, SendPacketBuffered), service: ~fn(v: RecvPacketBuffered)) diff --git a/src/test/run-pass/send-type-inference.rs b/src/test/run-pass/send-type-inference.rs index bdb1fbaf422..4fcbc789f57 100644 --- a/src/test/run-pass/send-type-inference.rs +++ b/src/test/run-pass/send-type-inference.rs @@ -16,7 +16,7 @@ struct Command { val: V } -fn cache_server(c: Chan>>) { +fn cache_server(c: Chan>>) { let (ctrl_port, ctrl_chan) = stream(); c.send(ctrl_chan); } diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs index 416e7bf82bb..216a7a939fe 100644 --- a/src/test/run-pass/type-param-constraints.rs +++ b/src/test/run-pass/type-param-constraints.rs @@ -12,7 +12,7 @@ fn p_foo(pinned: T) { } fn s_foo(shared: T) { } -fn u_foo(unique: T) { } +fn u_foo(unique: T) { } struct r { i: int, diff --git a/src/test/run-pass/uniq-cc-generic.rs b/src/test/run-pass/uniq-cc-generic.rs index b54b3b52692..2c3424d1f06 100644 --- a/src/test/run-pass/uniq-cc-generic.rs +++ b/src/test/run-pass/uniq-cc-generic.rs @@ -20,7 +20,7 @@ struct Pointy { d : ~fn() -> uint, } -fn make_uniq_closure(a: A) -> ~fn() -> uint { +fn make_uniq_closure(a: A) -> ~fn() -> uint { let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint; result } diff --git a/src/test/run-pass/unique-kinds.rs b/src/test/run-pass/unique-kinds.rs index b3ce71dcbff..391881deff6 100644 --- a/src/test/run-pass/unique-kinds.rs +++ b/src/test/run-pass/unique-kinds.rs @@ -12,11 +12,11 @@ use std::cmp::Eq; fn sendable() { - fn f(i: T, j: T) { + fn f(i: T, j: T) { assert_eq!(i, j); } - fn g(i: T, j: T) { + fn g(i: T, j: T) { assert!(i != j); } -- cgit 1.4.1-3-g733a5 From f9b54541ee2bbab1d81b14252f4d4172e10fd748 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 6 Jun 2013 18:54:14 -0700 Subject: librustc: Disallow "mut" from distributing over bindings. This is the backwards-incompatible part of per-binding-site "mut". --- doc/rust.md | 14 ++--- doc/tutorial-ffi.md | 4 +- src/libextra/md4.rs | 3 +- src/libextra/net_url.rs | 4 +- src/libextra/num/bigint.rs | 8 ++- src/libextra/timer.rs | 4 +- src/librustc/middle/trans/cabi_arm.rs | 4 +- src/librustc/middle/trans/cabi_mips.rs | 4 +- src/librustc/middle/trans/cabi_x86_64.rs | 3 +- src/librustc/middle/trans/callee.rs | 3 +- src/librustc/middle/trans/expr.rs | 5 +- src/libstd/io.rs | 7 ++- src/libstd/num/int_macros.rs | 3 +- src/libstd/num/uint_macros.rs | 3 +- src/libstd/rand.rs | 3 +- src/libstd/rand/distributions.rs | 3 +- src/libstd/rt/io/extensions.rs | 7 ++- src/libstd/str.rs | 70 +++++++++++++++++++++++- src/libstd/task/spawn.rs | 4 +- src/libstd/to_str.rs | 17 ++++-- src/libstd/vec.rs | 9 ++- src/libsyntax/ast_util.rs | 9 +++ src/libsyntax/parse/obsolete.rs | 6 ++ src/libsyntax/parse/parser.rs | 16 +++++- src/test/bench/shootout-mandelbrot.rs | 5 +- src/test/compile-fail/kindck-destructor-owned.rs | 2 +- src/test/compile-fail/kindck-nonsendable-1.rs | 6 +- src/test/compile-fail/no-send-res-ports.rs | 2 +- src/test/compile-fail/non_owned-enum.rs | 2 +- src/test/compile-fail/non_owned-struct.rs | 2 +- src/test/run-pass/let-destruct-fresh-mem.rs | 4 +- src/test/run-pass/pipe-peek.rs | 4 +- 32 files changed, 190 insertions(+), 50 deletions(-) (limited to 'src/libstd/task') diff --git a/doc/rust.md b/doc/rust.md index 8f742d0d210..cc53d7d17a2 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -2862,13 +2862,13 @@ call to the method `make_string`. Types in Rust are categorized into kinds, based on various properties of the components of the type. The kinds are: -`Const` +`Freeze` : Types of this kind are deeply immutable; they contain no mutable memory locations directly or indirectly via pointers. -`Owned` +`Send` : Types of this kind can be safely sent between tasks. This kind includes scalars, owning pointers, owned closures, and - structural types containing only other owned types. All `Owned` types are `Static`. + structural types containing only other owned types. All `Send` types are `Static`. `Static` : Types of this kind do not contain any borrowed pointers; this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions). @@ -2882,7 +2882,7 @@ The kinds are: trait provides a single method `finalize` that takes no parameters, and is run when values of the type are dropped. Such a method is called a "destructor", and are always executed in "top-down" order: a value is completely destroyed - before any of the values it owns run their destructors. Only `Owned` types + before any of the values it owns run their destructors. Only `Send` types that do not implement `Copy` can implement `Drop`. > **Note:** The `finalize` method may be renamed in future versions of Rust. @@ -2968,10 +2968,10 @@ frame they are allocated within. A task owns all memory it can *safely* reach through local variables, as well as managed, owning and borrowed pointers. -When a task sends a value that has the `Owned` trait to another task, +When a task sends a value that has the `Send` trait to another task, it loses ownership of the value sent and can no longer refer to it. This is statically guaranteed by the combined use of "move semantics", -and the compiler-checked _meaning_ of the `Owned` trait: +and the compiler-checked _meaning_ of the `Send` trait: it is only instantiated for (transitively) sendable kinds of data constructor and pointers, never including managed or borrowed pointers. @@ -3116,7 +3116,7 @@ These include: - read-only and read-write shared variables with various safe mutual exclusion patterns - simple locks and semaphores -When such facilities carry values, the values are restricted to the [`Owned` type-kind](#type-kinds). +When such facilities carry values, the values are restricted to the [`Send` type-kind](#type-kinds). Restricting communication interfaces to this kind ensures that no borrowed or managed pointers move between tasks. Thus access to an entire data structure can be mediated through its owning "root" value; no further locking or copying is required to avoid data races within the substructure of such a value. diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index 346112e655b..047b57e56a6 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -159,7 +159,7 @@ pub struct Unique { priv ptr: *mut T } -impl Unique { +impl Unique { pub fn new(value: T) -> Unique { unsafe { let ptr = malloc(std::sys::size_of::() as size_t) as *mut T; @@ -182,7 +182,7 @@ impl Unique { } #[unsafe_destructor] -impl Drop for Unique { +impl Drop for Unique { fn drop(&self) { unsafe { let x = intrinsics::init(); // dummy value to swap in diff --git a/src/libextra/md4.rs b/src/libextra/md4.rs index 6c972a313c4..2534fedd961 100644 --- a/src/libextra/md4.rs +++ b/src/libextra/md4.rs @@ -59,7 +59,8 @@ pub fn md4(msg: &[u8]) -> Quad { while i < e { let (aa, bb, cc, dd) = (a, b, c, d); - let mut (j, base) = (0u, i); + let mut j = 0u; + let mut base = i; while j < 16u { x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) + (msg[base + 2u] as u32 << 16u32) + diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index 5d3d31fdec4..f9eaa2bf02d 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -415,7 +415,9 @@ fn get_authority(rawurl: &str) -> let mut port = None; let mut colon_count = 0; - let mut (pos, begin, end) = (0, 2, len); + let mut pos = 0; + let mut begin = 2; + let mut end = len; for rawurl.iter().enumerate().advance |(i,c)| { if i < 2 { loop; } // ignore the leading // diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 1ac913e8a00..c2702ac70b1 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -380,7 +380,10 @@ impl Integer for BigUint { let mut d = Zero::zero::(); let mut n = 1; while m >= b { - let mut (d0, d_unit, b_unit) = div_estimate(&m, &b, n); + let (d0, d_unit, b_unit) = div_estimate(&m, &b, n); + let mut d0 = d0; + let mut d_unit = d_unit; + let mut b_unit = b_unit; let mut prod = b * d0; while prod > m { // FIXME(#6050): overloaded operators force moves with generic types @@ -442,7 +445,8 @@ impl Integer for BigUint { fn gcd(&self, other: &BigUint) -> BigUint { // Use Euclid's algorithm - let mut (m, n) = (copy *self, copy *other); + let mut m = copy *self; + let mut n = copy *other; while !m.is_zero() { let temp = m; m = n % temp; diff --git a/src/libextra/timer.rs b/src/libextra/timer.rs index 5a622ddfa0d..79451db8b17 100644 --- a/src/libextra/timer.rs +++ b/src/libextra/timer.rs @@ -123,7 +123,9 @@ pub fn recv_timeout(iotask: &IoTask, msecs: uint, wait_po: &Port) -> Option { - let mut (timeout_po, timeout_ch) = stream::<()>(); + let (timeout_po, timeout_ch) = stream::<()>(); + let mut timeout_po = timeout_po; + let mut timeout_ch = timeout_ch; delayed_send(iotask, msecs, &timeout_ch, ()); // XXX: Workaround due to ports and channels not being &mut. They should diff --git a/src/librustc/middle/trans/cabi_arm.rs b/src/librustc/middle/trans/cabi_arm.rs index ac51c7efc6f..45fdda1990c 100644 --- a/src/librustc/middle/trans/cabi_arm.rs +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -139,12 +139,14 @@ impl ABIInfo for ARM_ABIInfo { attrs.push(attr); } - let mut (ret_ty, ret_attr) = if ret_def { + let (ret_ty, ret_attr) = if ret_def { classify_ret_ty(rty) } else { (LLVMType { cast: false, ty: Type::void() }, None) }; + let mut ret_ty = ret_ty; + let sret = ret_attr.is_some(); if sret { arg_tys.unshift(ret_ty); diff --git a/src/librustc/middle/trans/cabi_mips.rs b/src/librustc/middle/trans/cabi_mips.rs index 8604ae37f77..47f2fb8634c 100644 --- a/src/librustc/middle/trans/cabi_mips.rs +++ b/src/librustc/middle/trans/cabi_mips.rs @@ -178,12 +178,14 @@ impl ABIInfo for MIPS_ABIInfo { atys: &[Type], rty: Type, ret_def: bool) -> FnType { - let mut (ret_ty, ret_attr) = if ret_def { + let (ret_ty, ret_attr) = if ret_def { classify_ret_ty(rty) } else { (LLVMType { cast: false, ty: Type::void() }, None) }; + let mut ret_ty = ret_ty; + let sret = ret_attr.is_some(); let mut arg_tys = ~[]; let mut attrs = ~[]; diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 73323634c2b..755075c17e9 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -360,8 +360,9 @@ fn x86_64_tys(atys: &[Type], arg_tys.push(ty); attrs.push(attr); } - let mut (ret_ty, ret_attr) = x86_64_ty(rty, |cls| cls.is_ret_bysret(), + let (ret_ty, ret_attr) = x86_64_ty(rty, |cls| cls.is_ret_bysret(), StructRetAttribute); + let mut ret_ty = ret_ty; let sret = ret_attr.is_some(); if sret { arg_tys = vec::append(~[ret_ty], arg_tys); diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 78c796329d8..045c8ec01aa 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -319,9 +319,10 @@ pub fn trans_fn_ref_with_vtables( // Should be either intra-crate or inlined. assert_eq!(def_id.crate, ast::local_crate); - let mut (val, must_cast) = + let (val, must_cast) = monomorphize::monomorphic_fn(ccx, def_id, &substs, vtables, opt_impl_did, Some(ref_id)); + let mut val = val; if must_cast && ref_id != 0 { // Monotype of the REFERENCE to the function (type params // are subst'd) diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 02f276cd050..35322730756 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -907,9 +907,12 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock { let scaled_ix = Mul(bcx, ix_val, vt.llunit_size); base::maybe_name_value(bcx.ccx(), scaled_ix, "scaled_ix"); - let mut (bcx, base, len) = + let (bcx, base, len) = base_datum.get_vec_base_and_len(bcx, index_expr.span, index_expr.id, 0); + let mut bcx = bcx; + let mut base = base; + let mut len = len; if ty::type_is_str(base_ty) { // acccount for null terminator in the case of string diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 36920bd2488..59ac58a514f 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -771,7 +771,9 @@ impl ReaderUtil for T { fn read_le_uint_n(&self, nbytes: uint) -> u64 { assert!(nbytes > 0 && nbytes <= 8); - let mut (val, pos, i) = (0u64, 0, nbytes); + let mut val = 0u64; + let mut pos = 0; + let mut i = nbytes; while i > 0 { val += (self.read_u8() as u64) << pos; pos += 8; @@ -787,7 +789,8 @@ impl ReaderUtil for T { fn read_be_uint_n(&self, nbytes: uint) -> u64 { assert!(nbytes > 0 && nbytes <= 8); - let mut (val, i) = (0u64, nbytes); + let mut val = 0u64; + let mut i = nbytes; while i > 0 { i -= 1; val += (self.read_u8() as u64) << i * 8; diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 74ec46ccfcd..845152f8552 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -400,7 +400,8 @@ impl Integer for $T { #[inline] fn gcd(&self, other: &$T) -> $T { // Use Euclid's algorithm - let mut (m, n) = (*self, *other); + let mut m = *self; + let mut n = *other; while m != 0 { let temp = m; m = n % temp; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 52f620f97ce..0dabe7fafa8 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -237,7 +237,8 @@ impl Integer for $T { #[inline] fn gcd(&self, other: &$T) -> $T { // Use Euclid's algorithm - let mut (m, n) = (*self, *other); + let mut m = *self; + let mut n = *other; while m != 0 { let temp = m; m = n % temp; diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index ea4a9059e72..8a6c05ce6e2 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -720,7 +720,8 @@ impl IsaacRng { fn isaac(&mut self) { self.c += 1; // abbreviations - let mut (a, b) = (self.a, self.b + self.c); + let mut a = self.a; + let mut b = self.b + self.c; static midpoint: uint = RAND_SIZE as uint / 2; diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs index 6f4f1a34977..e8dad2fc5e8 100644 --- a/src/libstd/rand/distributions.rs +++ b/src/libstd/rand/distributions.rs @@ -89,7 +89,8 @@ impl Rand for StandardNormal { // do-while, so the condition should be true on the first // run, they get overwritten anyway (0 < 1, so these are // good). - let mut (x, y) = (1.0, 0.0); + let mut x = 1.0; + let mut y = 0.0; // XXX infinities? while -2.0*y < x * x { diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index 1f82a9cd963..c6654e9dabe 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -343,7 +343,9 @@ impl ReaderByteConversions for T { fn read_le_uint_n(&mut self, nbytes: uint) -> u64 { assert!(nbytes > 0 && nbytes <= 8); - let mut (val, pos, i) = (0u64, 0, nbytes); + let mut val = 0u64; + let mut pos = 0; + let mut i = nbytes; while i > 0 { val += (self.read_u8() as u64) << pos; pos += 8; @@ -359,7 +361,8 @@ impl ReaderByteConversions for T { fn read_be_uint_n(&mut self, nbytes: uint) -> u64 { assert!(nbytes > 0 && nbytes <= 8); - let mut (val, i) = (0u64, nbytes); + let mut val = 0u64; + let mut i = nbytes; while i > 0 { i -= 1; val += (self.read_u8() as u64) << i * 8; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f8c8ffdbe35..78538d09938 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -473,6 +473,31 @@ pub fn each_split_within<'a>(ss: &'a str, return cont; } +/** + * Replace all occurrences of one string with another + * + * # Arguments + * + * * s - The string containing substrings to replace + * * from - The string to replace + * * to - The replacement string + * + * # Return value + * + * The original string with all occurances of `from` replaced with `to` + */ +pub fn replace(s: &str, from: &str, to: &str) -> ~str { + let mut result = ~""; + let mut last_end = 0; + for s.matches_index_iter(from).advance |(start, end)| { + result.push_str(unsafe{raw::slice_bytes(s, last_end, start)}); + result.push_str(to); + last_end = end; + } + result.push_str(unsafe{raw::slice_bytes(s, last_end, s.len())}); + result +} + /* Section: Comparing strings */ @@ -631,6 +656,48 @@ pub fn with_capacity(capacity: uint) -> ~str { buf } +/** + * As char_len but for a slice of a string + * + * # Arguments + * + * * s - A valid string + * * start - The position inside `s` where to start counting in bytes + * * end - The position where to stop counting + * + * # Return value + * + * The number of Unicode characters in `s` between the given indices. + */ +pub fn count_chars(s: &str, start: uint, end: uint) -> uint { + assert!(s.is_char_boundary(start)); + assert!(s.is_char_boundary(end)); + let mut i = start; + let mut len = 0u; + while i < end { + let next = s.char_range_at(i).next; + len += 1u; + i = next; + } + return len; +} + +/// Counts the number of bytes taken by the first `n` chars in `s` +/// starting from `start`. +pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint { + assert!(is_char_boundary(s, start)); + let mut end = start; + let mut cnt = n; + let l = s.len(); + while cnt > 0u { + assert!(end < l); + let next = s.char_range_at(end).next; + cnt -= 1u; + end = next; + } + end - start +} + /// Given a first byte, determine how many bytes are in this UTF-8 character pub fn utf8_char_width(b: u8) -> uint { let byte: uint = b as uint; @@ -737,7 +804,8 @@ pub mod raw { /// Create a Rust string from a null-terminated *u8 buffer pub unsafe fn from_buf(buf: *u8) -> ~str { - let mut (curr, i) = (buf, 0u); + let mut curr = buf; + let mut i = 0u; while *curr != 0u8 { i += 1u; curr = ptr::offset(buf, i); diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 95fc53c1b55..da3dc6b2a2e 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -636,7 +636,9 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let child_data = Cell::new((notify_chan, child_arc, ancestors)); let result: ~fn() = || { // Agh. Get move-mode items into the closure. FIXME (#2829) - let mut (notify_chan, child_arc, ancestors) = child_data.take(); + let (notify_chan, child_arc, ancestors) = child_data.take(); + let mut child_arc = child_arc; + let mut ancestors = ancestors; // Child task runs this code. // Even if the below code fails to kick the child off, we must diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index ea0e212b14f..dcd02744cf9 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -53,8 +53,9 @@ impl ToStr for (A,) { impl ToStr for HashMap { #[inline] fn to_str(&self) -> ~str { - let mut (acc, first) = (~"{", true); - for self.iter().advance |(key, value)| { + let mut acc = ~"{"; + let mut first = true; + for self.iter().advance |key, value| { if first { first = false; } @@ -73,7 +74,8 @@ impl ToStr for HashMap { impl ToStr for HashSet { #[inline] fn to_str(&self) -> ~str { - let mut (acc, first) = (~"{", true); + let mut acc = ~"{"; + let mut first = true; for self.iter().advance |element| { if first { first = false; @@ -121,7 +123,8 @@ impl ToStr for (A, B, C) { impl<'self,A:ToStr> ToStr for &'self [A] { #[inline] fn to_str(&self) -> ~str { - let mut (acc, first) = (~"[", true); + let mut acc = ~"["; + let mut first = true; for self.iter().advance |elt| { if first { first = false; @@ -139,7 +142,8 @@ impl<'self,A:ToStr> ToStr for &'self [A] { impl ToStr for ~[A] { #[inline] fn to_str(&self) -> ~str { - let mut (acc, first) = (~"[", true); + let mut acc = ~"["; + let mut first = true; for self.iter().advance |elt| { if first { first = false; @@ -157,7 +161,8 @@ impl ToStr for ~[A] { impl ToStr for @[A] { #[inline] fn to_str(&self) -> ~str { - let mut (acc, first) = (~"[", true); + let mut acc = ~"["; + let mut first = true; for self.iter().advance |elt| { if first { first = false; diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 8cbd9309cc6..aa4d632a482 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -348,7 +348,8 @@ pub fn consume_reverse(mut v: ~[T], f: &fn(uint, v: T)) { pub fn dedup(v: &mut ~[T]) { unsafe { if v.len() < 1 { return; } - let mut (last_written, next_to_read) = (0, 1); + let mut last_written = 0; + let mut next_to_read = 1; do as_const_buf(*v) |p, ln| { // We have a mutable reference to v, so we can make arbitrary // changes. (cf. push and pop) @@ -798,7 +799,8 @@ pub fn bsearch_elem(v: &[T], x: &T) -> Option { * Convert a vector of pairs into a pair of vectors, by reference. As unzip(). */ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { - let mut (ts, us) = (~[], ~[]); + let mut ts = ~[]; + let mut us = ~[]; for v.iter().advance |p| { let (t, u) = copy *p; ts.push(t); @@ -816,7 +818,8 @@ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { * of the i-th tuple of the input vector. */ pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { - let mut (ts, us) = (~[], ~[]); + let mut ts = ~[]; + let mut us = ~[]; do consume(v) |_i, p| { let (t, u) = p; ts.push(t); diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 9ba7cb3c818..4ffaba09061 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -619,6 +619,15 @@ pub enum Privacy { Public } +/// Returns true if the given pattern consists solely of an identifier +/// and false otherwise. +pub fn pat_is_ident(pat: @ast::pat) -> bool { + match pat.node { + ast::pat_ident(*) => true, + _ => false, + } +} + // HYGIENE FUNCTIONS /// Construct an identifier with the given name and an empty context: diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 32508f3b477..383faf22037 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -62,6 +62,7 @@ pub enum ObsoleteSyntax { ObsoleteFixedLengthVectorType, ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl, + ObsoleteMutWithMultipleBindings, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -223,6 +224,11 @@ impl Parser { "instead of e.g. `let a = 1, b = 2`, write \ `let (a, b) = (1, 2)`." ), + ObsoleteMutWithMultipleBindings => ( + "`mut` with multiple bindings", + "use multiple local declarations instead of e.g. `let mut \ + (x, y) = ...`." + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d67771fc435..11c73fe5711 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -83,7 +83,8 @@ use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer}; use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod}; use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType}; use parse::obsolete::{ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl}; -use parse::token::{can_begin_expr, get_ident_interner, ident_to_str, is_ident, is_ident_or_path}; +use parse::obsolete::{ObsoleteMutWithMultipleBindings}; +use parse::token::{can_begin_expr, get_ident_interner, is_ident, is_ident_or_path}; use parse::token::{is_plain_ident, INTERPOLATED, keywords, special_idents, token_to_binop}; use parse::token; use parse::{new_sub_parser_from_file, next_node_id, ParseSess}; @@ -821,6 +822,11 @@ impl Parser { self.parse_arg_mode(); is_mutbl = self.eat_keyword(keywords::Mut); let pat = self.parse_pat(); + + if is_mutbl && !ast_util::pat_is_ident(pat) { + self.obsolete(*self.span, ObsoleteMutWithMultipleBindings) + } + self.expect(&token::COLON); pat } else { @@ -2560,6 +2566,11 @@ impl Parser { fn parse_local(&self, is_mutbl: bool) -> @local { let lo = self.span.lo; let pat = self.parse_pat(); + + if is_mutbl && !ast_util::pat_is_ident(pat) { + self.obsolete(*self.span, ObsoleteMutWithMultipleBindings) + } + let mut ty = @Ty { id: self.get_id(), node: ty_infer, @@ -4420,7 +4431,8 @@ impl Parser { let mut attrs = vec::append(first_item_attrs, self.parse_outer_attributes()); // First, parse view items. - let mut (view_items, items) = (~[], ~[]); + let mut view_items = ~[]; + let mut items = ~[]; let mut done = false; // I think this code would probably read better as a single // loop with a mutable three-state-variable (for extern mods, diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 70f56f5c5a3..b79ecd03c0c 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -23,7 +23,10 @@ fn main() { for range(0, h) |y| { let y = y as f64; for range(0, w) |x| { - let mut (Zr, Zi, Tr, Ti) = (0f64, 0f64, 0f64, 0f64); + let mut Zr = 0f64; + let mut Zi = 0f64; + let mut Tr = 0f64; + let mut Ti = 0f64; let Cr = 2.0 * (x as f64) / (w as f64) - 1.5; let Ci = 2.0 * (y as f64) / (h as f64) - 1.0; diff --git a/src/test/compile-fail/kindck-destructor-owned.rs b/src/test/compile-fail/kindck-destructor-owned.rs index 00d73b02dbc..07adc3d81e5 100644 --- a/src/test/compile-fail/kindck-destructor-owned.rs +++ b/src/test/compile-fail/kindck-destructor-owned.rs @@ -2,7 +2,7 @@ struct Foo { f: @mut int, } -impl Drop for Foo { //~ ERROR cannot implement a destructor on a struct that is not Send +impl Drop for Foo { //~ ERROR cannot implement a destructor on a structure that does not satisfy Send fn drop(&self) { *self.f = 10; } diff --git a/src/test/compile-fail/kindck-nonsendable-1.rs b/src/test/compile-fail/kindck-nonsendable-1.rs index 38983a9aca6..99057ba940c 100644 --- a/src/test/compile-fail/kindck-nonsendable-1.rs +++ b/src/test/compile-fail/kindck-nonsendable-1.rs @@ -12,7 +12,7 @@ fn foo(_x: @uint) {} fn main() { let x = @3u; - let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Owned` - let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Owned` - let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Owned` + let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` + let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` + let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send` } diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 605e59d56c8..5f0d4bc60ac 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -32,7 +32,7 @@ fn main() { let x = Cell::new(foo(Port(@()))); do task::spawn { - let y = x.take(); //~ ERROR does not fulfill `Owned` + let y = x.take(); //~ ERROR does not fulfill `Send` error!(y); } } diff --git a/src/test/compile-fail/non_owned-enum.rs b/src/test/compile-fail/non_owned-enum.rs index 6068b7f1730..20b571ad614 100644 --- a/src/test/compile-fail/non_owned-enum.rs +++ b/src/test/compile-fail/non_owned-enum.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[non_owned] +#[non_sendable] enum Foo { A } fn bar(_: T) {} diff --git a/src/test/compile-fail/non_owned-struct.rs b/src/test/compile-fail/non_owned-struct.rs index b6f29df0575..d4b8e6755a1 100644 --- a/src/test/compile-fail/non_owned-struct.rs +++ b/src/test/compile-fail/non_owned-struct.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[non_owned] +#[non_sendable] struct Foo { a: int } fn bar(_: T) {} diff --git a/src/test/run-pass/let-destruct-fresh-mem.rs b/src/test/run-pass/let-destruct-fresh-mem.rs index 500502320df..2615396653d 100644 --- a/src/test/run-pass/let-destruct-fresh-mem.rs +++ b/src/test/run-pass/let-destruct-fresh-mem.rs @@ -13,7 +13,9 @@ struct A { a: int } pub fn main() { let u = X {x: 10, y: @A {a: 20}}; - let mut X {x: x, y: @A {a: a}} = u; + let X {x: x, y: @A {a: a}} = u; + let mut x = x; + let mut a = a; x = 100; a = 100; assert_eq!(x, 100); diff --git a/src/test/run-pass/pipe-peek.rs b/src/test/run-pass/pipe-peek.rs index 8d8c96c6f51..cbc822060ce 100644 --- a/src/test/run-pass/pipe-peek.rs +++ b/src/test/run-pass/pipe-peek.rs @@ -22,7 +22,9 @@ proto! oneshot ( ) pub fn main() { - let mut (p, c) = oneshot::init(); + let (p, c) = oneshot::init(); + let mut p = p; + let mut c = c; assert!(!pipes::peek(&mut p)); -- cgit 1.4.1-3-g733a5 From f6a27cbda273d5d39af953bca12990cc4930382c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 26 Jun 2013 15:54:51 -0700 Subject: libextra: Fix even more merge fallout. --- src/libextra/ebml.rs | 3 ++- src/libextra/num/bigint.rs | 2 -- src/libextra/test.rs | 3 --- src/libextra/timer.rs | 1 - src/libstd/task/spawn.rs | 1 - 5 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index fad04b772eb..d401710a466 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -94,7 +94,6 @@ pub mod reader { use serialize; - use core::prelude::*; use core::cast::transmute; use core::int; use core::io; @@ -106,6 +105,8 @@ pub mod reader { #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")] + use core::option::{None, Option, Some}; + use core::ptr::offset; use core::unstable::intrinsics::bswap32; // ebml reading diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index b0fa715fdd8..002d8a7f956 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -382,8 +382,6 @@ impl Integer for BigUint { while m >= b { let (d0, d_unit, b_unit) = div_estimate(&m, &b, n); let mut d0 = d0; - let mut d_unit = d_unit; - let mut b_unit = b_unit; let mut prod = b * d0; while prod > m { // FIXME(#6050): overloaded operators force moves with generic types diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 672c4cd648c..209b46809ce 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -751,9 +751,6 @@ impl BenchHarness { } pub mod bench { - use core::prelude::*; - - use core::vec; use test::{BenchHarness, BenchSamples}; pub fn benchmark(f: &fn(&mut BenchHarness)) -> BenchSamples { diff --git a/src/libextra/timer.rs b/src/libextra/timer.rs index 79451db8b17..e23f9113319 100644 --- a/src/libextra/timer.rs +++ b/src/libextra/timer.rs @@ -125,7 +125,6 @@ pub fn recv_timeout(iotask: &IoTask, -> Option { let (timeout_po, timeout_ch) = stream::<()>(); let mut timeout_po = timeout_po; - let mut timeout_ch = timeout_ch; delayed_send(iotask, msecs, &timeout_ch, ()); // XXX: Workaround due to ports and channels not being &mut. They should diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index da3dc6b2a2e..8f06fede057 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -637,7 +637,6 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let result: ~fn() = || { // Agh. Get move-mode items into the closure. FIXME (#2829) let (notify_chan, child_arc, ancestors) = child_data.take(); - let mut child_arc = child_arc; let mut ancestors = ancestors; // Child task runs this code. -- cgit 1.4.1-3-g733a5 From ff4ab9e147b0be4126b8b70ca6ab27173a46077a Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Fri, 21 Jun 2013 20:08:35 -0400 Subject: 'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for making them noncopyable. --- src/libextra/fun_treemap.rs | 4 +-- src/libextra/rope.rs | 4 +-- src/libextra/sort.rs | 7 +++-- src/libextra/sync.rs | 12 ++++---- src/libextra/test.rs | 6 ++-- src/libextra/treemap.rs | 12 ++++---- src/libextra/workcache.rs | 2 +- src/librustc/metadata/filesearch.rs | 2 +- src/librustc/metadata/tydecode.rs | 40 ++++++++++++------------- src/librustc/middle/borrowck/move_data.rs | 2 +- src/librustc/middle/mem_categorization.rs | 16 +++++----- src/librustc/middle/trans/base.rs | 2 +- src/librustc/middle/ty.rs | 24 +++++++-------- src/librustc/middle/typeck/check/regionmanip.rs | 12 ++++---- src/librustc/middle/typeck/infer/mod.rs | 4 +-- src/libstd/hashmap.rs | 5 ++-- src/libstd/iterator.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/str.rs | 4 +-- src/libstd/task/spawn.rs | 4 +++ src/libstd/to_bytes.rs | 9 ++++-- src/libstd/trie.rs | 6 ++-- src/libstd/vec.rs | 8 ++--- src/libsyntax/ast_util.rs | 10 +++---- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/deriving/iter_bytes.rs | 12 ++++++-- src/libsyntax/ext/deriving/rand.rs | 2 +- src/test/compile-fail/regions-creating-enums.rs | 4 +-- 28 files changed, 118 insertions(+), 101 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libextra/fun_treemap.rs b/src/libextra/fun_treemap.rs index eb8c27e9902..5906e809c98 100644 --- a/src/libextra/fun_treemap.rs +++ b/src/libextra/fun_treemap.rs @@ -66,9 +66,9 @@ pub fn traverse(m: Treemap, f: &fn(&K, &V)) { // matches to me, so I changed it. but that may be a // de-optimization -- tjc Node(@ref k, @ref v, left, right) => { - traverse(left, f); + traverse(left, |k,v| f(k,v)); f(k, v); - traverse(right, f); + traverse(right, |k,v| f(k,v)); } } } diff --git a/src/libextra/rope.rs b/src/libextra/rope.rs index fed73256c00..71393ff9fae 100644 --- a/src/libextra/rope.rs +++ b/src/libextra/rope.rs @@ -1078,7 +1078,7 @@ pub mod node { pub fn loop_chars(node: @Node, it: &fn(c: char) -> bool) -> bool { return loop_leaves(node,|leaf| { - leaf.content.slice(leaf.byte_offset, leaf.byte_len).iter().all(it) + leaf.content.slice(leaf.byte_offset, leaf.byte_len).iter().all(|c| it(c)) }); } @@ -1101,7 +1101,7 @@ pub mod node { loop { match (*current) { Leaf(x) => return it(x), - Concat(ref x) => if loop_leaves(x.left, it) { //non tail call + Concat(ref x) => if loop_leaves(x.left, |l| it(l)) { //non tail call current = x.right; //tail call } else { return false; diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index 6befd49e8af..10dbe2326d7 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -42,7 +42,8 @@ pub fn merge_sort(v: &[T], le: Le) -> ~[T] { let mid = v_len / 2 + begin; let a = (begin, mid); let b = (mid, end); - return merge(le, merge_sort_(v, a, le), merge_sort_(v, b, le)); + return merge(|x,y| le(x,y), merge_sort_(v, a, |x,y| le(x,y)), + merge_sort_(v, b, |x,y| le(x,y))); } fn merge(le: Le, a: &[T], b: &[T]) -> ~[T] { @@ -83,10 +84,10 @@ fn qsort(arr: &mut [T], left: uint, right: uint, compare_func: Le) { if right > left { let pivot = (left + right) / 2u; - let new_pivot = part::(arr, left, right, pivot, compare_func); + let new_pivot = part::(arr, left, right, pivot, |x,y| compare_func(x,y)); if new_pivot != 0u { // Need to do this check before recursing due to overflow - qsort::(arr, left, new_pivot - 1u, compare_func); + qsort::(arr, left, new_pivot - 1u, |x,y| compare_func(x,y)); } qsort::(arr, new_pivot + 1u, right, compare_func); } diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 3908b61381b..9c6be901d98 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -563,7 +563,9 @@ impl RWlock { (&self.order_lock).acquire(); do (&self.access_lock).access_waitqueue { (&self.order_lock).release(); - task::rekillable(blk) + do task::rekillable { + blk() + } } } } @@ -1182,12 +1184,12 @@ mod tests { Write => x.write(blk), Downgrade => do x.write_downgrade |mode| { - (&mode).write(blk); + do mode.write { blk() }; }, DowngradeRead => do x.write_downgrade |mode| { let mode = x.downgrade(mode); - (&mode).read(blk); + do mode.read { blk() }; }, } } @@ -1340,10 +1342,10 @@ mod tests { fn lock_cond(x: &RWlock, downgrade: bool, blk: &fn(c: &Condvar)) { if downgrade { do x.write_downgrade |mode| { - (&mode).write_cond(blk) + do mode.write_cond |c| { blk(c) } } } else { - x.write_cond(blk) + do x.write_cond |c| { blk(c) } } } let x = ~RWlock(); diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 209b46809ce..50ca96e6e21 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -678,7 +678,7 @@ impl BenchHarness { // Initial bench run to get ballpark figure. let mut n = 1_u64; - self.bench_n(n, f); + self.bench_n(n, |x| f(x)); while n < 1_000_000_000 && self.ns_elapsed() < 1_000_000_000 { @@ -694,7 +694,7 @@ impl BenchHarness { n = u64::max(u64::min(n+n/2, 100*last), last+1); n = round_up(n); - self.bench_n(n, f); + self.bench_n(n, |x| f(x)); } } @@ -714,7 +714,7 @@ impl BenchHarness { magnitude * 2); let samples = do vec::from_fn(n_samples) |_| { - self.bench_n(n_iter as u64, f); + self.bench_n(n_iter as u64, |x| f(x)); self.ns_per_iter() as f64 }; diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 4622b8c7284..d546b48f817 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -511,14 +511,14 @@ impl TreeNode { fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode>, f: &fn(&'r K, &'r V) -> bool) -> bool { - node.iter().advance(|x| each(&x.left, f) && f(&x.key, &x.value) && - each(&x.right, f)) + node.iter().advance(|x| each(&x.left, |k,v| f(k,v)) && f(&x.key, &x.value) && + each(&x.right, |k,v| f(k,v))) } fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode>, f: &fn(&'r K, &'r V) -> bool) -> bool { - node.iter().advance(|x| each_reverse(&x.right, f) && f(&x.key, &x.value) && - each_reverse(&x.left, f)) + node.iter().advance(|x| each_reverse(&x.right, |k,v| f(k,v)) && f(&x.key, &x.value) && + each_reverse(&x.left, |k,v| f(k,v))) } fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, @@ -527,9 +527,9 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode>, match *node { Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left, right: ref mut right, _}) => { - if !mutate_values(left, f) { return false } + if !mutate_values(left, |k,v| f(k,v)) { return false } if !f(key, value) { return false } - if !mutate_values(right, f) { return false } + if !mutate_values(right, |k,v| f(k,v)) { return false } } None => return false } diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 567f9eda2fb..4d4f3c3a49b 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -107,7 +107,7 @@ struct WorkKey { impl to_bytes::IterBytes for WorkKey { #[inline] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { - self.kind.iter_bytes(lsb0, f) && self.name.iter_bytes(lsb0, f) + self.kind.iter_bytes(lsb0, |b| f(b)) && self.name.iter_bytes(lsb0, |b| f(b)) } } diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 6268932ba99..abfb5f7d4d4 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -48,7 +48,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>, debug!("filesearch: searching additional lib search paths [%?]", self.addl_lib_search_paths.len()); // a little weird - self.addl_lib_search_paths.iter().advance(f); + self.addl_lib_search_paths.iter().advance(|path| f(path)); debug!("filesearch: searching target lib path"); if !f(&make_target_lib_path(self.sysroot, diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 1ec5c983f62..22786581073 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -189,11 +189,11 @@ fn parse_trait_store(st: &mut PState) -> ty::TraitStore { fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs { let self_r = parse_opt(st, |st| parse_region(st) ); - let self_ty = parse_opt(st, |st| parse_ty(st, conv) ); + let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) ); assert_eq!(next(st), '['); let mut params: ~[ty::t] = ~[]; - while peek(st) != ']' { params.push(parse_ty(st, conv)); } + while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); } st.pos = st.pos + 1u; return ty::substs { @@ -270,8 +270,8 @@ fn parse_str(st: &mut PState, term: char) -> ~str { } fn parse_trait_ref(st: &mut PState, conv: conv_did) -> ty::TraitRef { - let def = parse_def(st, NominalType, conv); - let substs = parse_substs(st, conv); + let def = parse_def(st, NominalType, |x,y| conv(x,y)); + let substs = parse_substs(st, |x,y| conv(x,y)); ty::TraitRef {def_id: def, substs: substs} } @@ -301,18 +301,18 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t { 'c' => return ty::mk_char(), 't' => { assert_eq!(next(st), '['); - let def = parse_def(st, NominalType, conv); - let substs = parse_substs(st, conv); + let def = parse_def(st, NominalType, |x,y| conv(x,y)); + let substs = parse_substs(st, |x,y| conv(x,y)); assert_eq!(next(st), ']'); return ty::mk_enum(st.tcx, def, substs); } 'x' => { assert_eq!(next(st), '['); - let def = parse_def(st, NominalType, conv); - let substs = parse_substs(st, conv); + let def = parse_def(st, NominalType, |x,y| conv(x,y)); + let substs = parse_substs(st, |x,y| conv(x,y)); let store = parse_trait_store(st); let mt = parse_mutability(st); - let bounds = parse_bounds(st, conv); + let bounds = parse_bounds(st, |x,y| conv(x,y)); assert_eq!(next(st), ']'); return ty::mk_trait(st.tcx, def, substs, store, mt, bounds.builtin_bounds); } @@ -346,7 +346,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t { 'T' => { assert_eq!(next(st), '['); let mut params = ~[]; - while peek(st) != ']' { params.push(parse_ty(st, conv)); } + while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); } st.pos = st.pos + 1u; return ty::mk_tup(st.tcx, params); } @@ -380,15 +380,15 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t { } } '"' => { - let _ = parse_def(st, TypeWithId, conv); - let inner = parse_ty(st, conv); + let _ = parse_def(st, TypeWithId, |x,y| conv(x,y)); + let inner = parse_ty(st, |x,y| conv(x,y)); inner } 'B' => ty::mk_opaque_box(st.tcx), 'a' => { assert_eq!(next(st), '['); - let did = parse_def(st, NominalType, conv); - let substs = parse_substs(st, conv); + let did = parse_def(st, NominalType, |x,y| conv(x,y)); + let substs = parse_substs(st, |x,y| conv(x,y)); assert_eq!(next(st), ']'); return ty::mk_struct(st.tcx, did, substs); } @@ -473,8 +473,8 @@ fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy { let purity = parse_purity(next(st)); let onceness = parse_onceness(next(st)); let region = parse_region(st); - let bounds = parse_bounds(st, conv); - let sig = parse_sig(st, conv); + let bounds = parse_bounds(st, |x,y| conv(x,y)); + let sig = parse_sig(st, |x,y| conv(x,y)); ty::ClosureTy { purity: purity, sigil: sigil, @@ -500,7 +500,7 @@ fn parse_sig(st: &mut PState, conv: conv_did) -> ty::FnSig { assert_eq!(next(st), '['); let mut inputs = ~[]; while peek(st) != ']' { - inputs.push(parse_ty(st, conv)); + inputs.push(parse_ty(st, |x,y| conv(x,y))); } st.pos += 1u; // eat the ']' let ret_ty = parse_ty(st, conv); @@ -544,8 +544,8 @@ pub fn parse_type_param_def_data(data: &[u8], start: uint, } fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef { - ty::TypeParameterDef {def_id: parse_def(st, NominalType, conv), - bounds: @parse_bounds(st, conv)} + ty::TypeParameterDef {def_id: parse_def(st, NominalType, |x,y| conv(x,y)), + bounds: @parse_bounds(st, |x,y| conv(x,y))} } fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds { @@ -571,7 +571,7 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds { param_bounds.builtin_bounds.add(ty::BoundSized); } 'I' => { - param_bounds.trait_bounds.push(@parse_trait_ref(st, conv)); + param_bounds.trait_bounds.push(@parse_trait_ref(st, |x,y| conv(x,y))); } '.' => { return param_bounds; diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 7396dc1bd7b..623dbbd61b2 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -411,7 +411,7 @@ impl MoveData { let mut p = self.path(index).first_child; while p != InvalidMovePathIndex { - if !self.each_extending_path(p, f) { + if !self.each_extending_path(p, |x| f(x)) { return false; } p = self.path(p).next_sibling; diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 52c01fa7647..a2907e99120 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -890,7 +890,7 @@ impl mem_categorization_ctxt { pat, downcast_cmt, subpat_ty, InteriorField(PositionalField(i))); - self.cat_pattern(subcmt, subpat, op); + self.cat_pattern(subcmt, subpat, |x,y| op(x,y)); } } Some(&ast::def_fn(*)) | @@ -901,12 +901,12 @@ impl mem_categorization_ctxt { self.cat_imm_interior( pat, cmt, subpat_ty, InteriorField(PositionalField(i))); - self.cat_pattern(cmt_field, subpat, op); + self.cat_pattern(cmt_field, subpat, |x,y| op(x,y)); } } Some(&ast::def_static(*)) => { for subpats.iter().advance |&subpat| { - self.cat_pattern(cmt, subpat, op); + self.cat_pattern(cmt, subpat, |x,y| op(x,y)); } } _ => { @@ -930,7 +930,7 @@ impl mem_categorization_ctxt { for field_pats.iter().advance |fp| { let field_ty = self.pat_ty(fp.pat); // see (*) let cmt_field = self.cat_field(pat, cmt, fp.ident, field_ty); - self.cat_pattern(cmt_field, fp.pat, op); + self.cat_pattern(cmt_field, fp.pat, |x,y| op(x,y)); } } @@ -942,7 +942,7 @@ impl mem_categorization_ctxt { self.cat_imm_interior( pat, cmt, subpat_ty, InteriorField(PositionalField(i))); - self.cat_pattern(subcmt, subpat, op); + self.cat_pattern(subcmt, subpat, |x,y| op(x,y)); } } @@ -956,15 +956,15 @@ impl mem_categorization_ctxt { ast::pat_vec(ref before, slice, ref after) => { let elt_cmt = self.cat_index(pat, cmt, 0); for before.iter().advance |&before_pat| { - self.cat_pattern(elt_cmt, before_pat, op); + self.cat_pattern(elt_cmt, before_pat, |x,y| op(x,y)); } for slice.iter().advance |&slice_pat| { let slice_ty = self.pat_ty(slice_pat); let slice_cmt = self.cat_rvalue(pat, slice_ty); - self.cat_pattern(slice_cmt, slice_pat, op); + self.cat_pattern(slice_cmt, slice_pat, |x,y| op(x,y)); } for after.iter().advance |&after_pat| { - self.cat_pattern(elt_cmt, after_pat, op); + self.cat_pattern(elt_cmt, after_pat, |x,y| op(x,y)); } } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index efa69ab5e62..d9fea121346 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -674,7 +674,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, int::to_str(variant.disr_val)); let variant_cx = iter_variant(variant_cx, repr, av, *variant, - substs.tps, f); + substs.tps, |x,y,z| f(x,y,z)); match adt::trans_case(cx, repr, variant.disr_val) { _match::single_result(r) => { AddCase(llswitch, r.val, variant_cx.llbb) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a990e4c70a9..9f9127663af 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1241,15 +1241,15 @@ pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) { } ty_enum(_, ref substs) | ty_struct(_, ref substs) | ty_trait(_, ref substs, _, _, _) => { - for (*substs).tps.iter().advance |subty| { maybe_walk_ty(*subty, f); } + for (*substs).tps.iter().advance |subty| { maybe_walk_ty(*subty, |x| f(x)); } } - ty_tup(ref ts) => { for ts.iter().advance |tt| { maybe_walk_ty(*tt, f); } } + ty_tup(ref ts) => { for ts.iter().advance |tt| { maybe_walk_ty(*tt, |x| f(x)); } } ty_bare_fn(ref ft) => { - for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, f); } + for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, |x| f(x)); } maybe_walk_ty(ft.sig.output, f); } ty_closure(ref ft) => { - for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, f); } + for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, |x| f(x)); } maybe_walk_ty(ft.sig.output, f); } } @@ -1331,7 +1331,7 @@ fn fold_sty(sty: &sty, fldop: &fn(t) -> t) -> sty { // Folds types from the bottom up. pub fn fold_ty(cx: ctxt, t0: t, fldop: &fn(t) -> t) -> t { - let sty = fold_sty(&get(t0).sty, |t| fold_ty(cx, fldop(t), fldop)); + let sty = fold_sty(&get(t0).sty, |t| fold_ty(cx, fldop(t), |t| fldop(t))); fldop(mk_t(cx, sty)) } @@ -1345,8 +1345,8 @@ pub fn walk_regions_and_ty( fold_regions_and_ty( cx, ty, |r| { walkr(r); r }, - |t| { walk_regions_and_ty(cx, t, walkr, walkt); t }, - |t| { walk_regions_and_ty(cx, t, walkr, walkt); t }); + |t| { walk_regions_and_ty(cx, t, |r| walkr(r), |t| walkt(t)); t }, + |t| { walk_regions_and_ty(cx, t, |r| walkr(r), |t| walkt(t)); t }); } } @@ -1426,8 +1426,8 @@ pub fn fold_regions( fold_regions_and_ty( cx, ty, |r| fldr(r, in_fn), - |t| do_fold(cx, t, true, fldr), - |t| do_fold(cx, t, in_fn, fldr)) + |t| do_fold(cx, t, true, |r,b| fldr(r,b)), + |t| do_fold(cx, t, in_fn, |r,b| fldr(r,b))) } do_fold(cx, ty, false, fldr) } @@ -2374,7 +2374,7 @@ pub fn type_structurally_contains(cx: ctxt, for (*enum_variants(cx, did)).iter().advance |variant| { for variant.args.iter().advance |aty| { let sty = subst(cx, substs, *aty); - if type_structurally_contains(cx, sty, test) { return true; } + if type_structurally_contains(cx, sty, |x| test(x)) { return true; } } } return false; @@ -2383,14 +2383,14 @@ pub fn type_structurally_contains(cx: ctxt, let r = lookup_struct_fields(cx, did); for r.iter().advance |field| { let ft = lookup_field_type(cx, did, field.id, substs); - if type_structurally_contains(cx, ft, test) { return true; } + if type_structurally_contains(cx, ft, |x| test(x)) { return true; } } return false; } ty_tup(ref ts) => { for ts.iter().advance |tt| { - if type_structurally_contains(cx, *tt, test) { return true; } + if type_structurally_contains(cx, *tt, |x| test(x)) { return true; } } return false; } diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index 160737142c8..fb79a7c3c99 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -112,7 +112,7 @@ pub fn replace_bound_regions_in_fn_sig( // 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| { - if !in_fn { isr = append_isr(isr, to_r, r); } + if !in_fn { isr = append_isr(isr, |br| to_r(br), r); } r }; @@ -211,18 +211,18 @@ pub fn relate_nested_regions( match ty::get(ty).sty { ty::ty_rptr(r, ref mt) | ty::ty_evec(ref mt, ty::vstore_slice(r)) => { - relate(*the_stack, r, relate_op); + relate(*the_stack, r, |x,y| relate_op(x,y)); the_stack.push(r); - walk_ty(tcx, the_stack, mt.ty, relate_op); + walk_ty(tcx, the_stack, mt.ty, |x,y| relate_op(x,y)); the_stack.pop(); } _ => { ty::fold_regions_and_ty( tcx, ty, - |r| { relate(*the_stack, r, relate_op); r }, - |t| { walk_ty(tcx, the_stack, t, relate_op); t }, - |t| { walk_ty(tcx, the_stack, t, relate_op); t }); + |r| { relate( *the_stack, r, |x,y| relate_op(x,y)); r }, + |t| { walk_ty(tcx, the_stack, t, |x,y| relate_op(x,y)); t }, + |t| { walk_ty(tcx, the_stack, t, |x,y| relate_op(x,y)); t }); } } } diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 1bfe452f25e..3e2d4a71dfb 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -582,7 +582,7 @@ impl InferCtxt { debug!("commit()"); do indent { - let r = self.try(f); + let r = self.try(|| f()); self.ty_var_bindings.bindings.truncate(0); self.int_var_bindings.bindings.truncate(0); @@ -836,6 +836,6 @@ pub fn fold_regions_in_sig( fldr: &fn(r: ty::Region, in_fn: bool) -> ty::Region) -> ty::FnSig { do ty::fold_sig(fn_sig) |t| { - ty::fold_regions(tcx, t, fldr) + ty::fold_regions(tcx, t, |r, in_fn| fldr(r, in_fn)) } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index bfa0f2fa124..7f9fb6ad938 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -671,7 +671,7 @@ impl Set for HashSet { fn symmetric_difference(&self, other: &HashSet, f: &fn(&T) -> bool) -> bool { - self.difference(other, f) && other.difference(self, f) + self.difference(other, |t| f(t)) && other.difference(self, |t| f(t)) } /// Visit the values representing the intersection @@ -681,7 +681,8 @@ impl Set for HashSet { /// Visit the values representing the union fn union(&self, other: &HashSet, f: &fn(&T) -> bool) -> bool { - self.iter().advance(f) && other.iter().advance(|v| self.contains(v) || f(v)) + self.iter().advance(|t| f(t)) && + other.iter().advance(|v| self.contains(v) || f(v)) } } diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 765bf3b36f2..976ca8bae7a 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -964,7 +964,7 @@ impl<'self, A, T: Iterator, B, U: Iterator> Iterator for return Some(x) } } - match self.iter.next().map_consume(self.f) { + match self.iter.next().map_consume(|x| (self.f)(x)) { None => return None, next => self.subiter = next, } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 400a93ee28f..1fbcda12dce 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -595,7 +595,7 @@ pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool { let r = list_dir(p); r.iter().advance(|q| { let path = &p.push(*q); - f(path) && (!path_is_dir(path) || walk_dir(path, f)) + f(path) && (!path_is_dir(path) || walk_dir(path, |p| f(p))) }) } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 2144afc0fbd..e47800d70c6 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -463,7 +463,7 @@ pub fn each_split_within<'a>(ss: &'a str, cont }; - ss.iter().enumerate().advance(machine); + ss.iter().enumerate().advance(|x| machine(x)); // Let the automaton 'run out' by supplying trailing whitespace let mut fake_i = ss.len(); @@ -761,7 +761,7 @@ impl<'self> StrUtil for &'self str { // NB: len includes the trailing null. assert!(len > 0); if unsafe { *(ptr::offset(buf,len-1)) != 0 } { - to_owned(self).as_c_str(f) + to_owned(self).as_c_str(|s| f(s)) } else { f(buf as *libc::c_char) } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 8f06fede057..c932a9660c2 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -230,11 +230,15 @@ fn each_ancestor(list: &mut AncestorList, // 'do_continue' - Did the forward_blk succeed at this point? (i.e., // should we recurse? or should our callers unwind?) + let forward_blk = Cell::new(forward_blk); + // The map defaults to None, because if ancestors is None, we're at // the end of the list, which doesn't make sense to coalesce. return do (**ancestors).map_default((None,false)) |ancestor_arc| { // NB: Takes a lock! (this ancestor node) do access_ancestors(ancestor_arc) |nobe| { + // Argh, but we couldn't give it to coalesce() otherwise. + let forward_blk = forward_blk.take(); // Check monotonicity assert!(last_generation > nobe.generation); /*##########################################################* diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 6f0c615d007..d6e92dd679e 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -232,7 +232,8 @@ impl IterBytes for (A,B) { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { match *self { - (ref a, ref b) => { a.iter_bytes(lsb0, f) && b.iter_bytes(lsb0, f) } + (ref a, ref b) => { a.iter_bytes(lsb0, |b| f(b)) && + b.iter_bytes(lsb0, |b| f(b)) } } } } @@ -242,7 +243,9 @@ impl IterBytes for (A,B,C) { fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { match *self { (ref a, ref b, ref c) => { - a.iter_bytes(lsb0, f) && b.iter_bytes(lsb0, f) && c.iter_bytes(lsb0, f) + a.iter_bytes(lsb0, |b| f(b)) && + b.iter_bytes(lsb0, |b| f(b)) && + c.iter_bytes(lsb0, |b| f(b)) } } } @@ -296,7 +299,7 @@ impl IterBytes for Option { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { match *self { - Some(ref a) => 0u8.iter_bytes(lsb0, f) && a.iter_bytes(lsb0, f), + Some(ref a) => 0u8.iter_bytes(lsb0, |b| f(b)) && a.iter_bytes(lsb0, |b| f(b)), None => 1u8.iter_bytes(lsb0, f) } } diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 8f70c75439a..b9b03ea5661 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -251,7 +251,7 @@ impl TrieNode { fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { for uint::range(0, self.children.len()) |idx| { match self.children[idx] { - Internal(ref x) => if !x.each(f) { return false }, + Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false }, External(k, ref v) => if !f(&k, v) { return false }, Nothing => () } @@ -262,7 +262,7 @@ impl TrieNode { fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { for uint::range_rev(self.children.len(), 0) |idx| { match self.children[idx - 1] { - Internal(ref x) => if !x.each_reverse(f) { return false }, + Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false }, External(k, ref v) => if !f(&k, v) { return false }, Nothing => () } @@ -273,7 +273,7 @@ impl TrieNode { fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool { for self.children.mut_iter().advance |child| { match *child { - Internal(ref mut x) => if !x.mutate_values(f) { + Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) { return false }, External(k, ref mut v) => if !f(&k, v) { return false }, diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 8555d99255d..4e7943f7cfd 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -191,7 +191,7 @@ pub fn split(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut start = 0u; let mut result = ~[]; while start < ln { - match position_between(v, start, ln, f) { + match position_between(v, start, ln, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(start, i).to_owned()); @@ -215,7 +215,7 @@ pub fn splitn(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut count = n; let mut result = ~[]; while start < ln && count > 0u { - match position_between(v, start, ln, f) { + match position_between(v, start, ln, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(start, i).to_owned()); @@ -240,7 +240,7 @@ pub fn rsplit(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut end = ln; let mut result = ~[]; while end > 0 { - match rposition_between(v, 0, end, f) { + match rposition_between(v, 0, end, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(i + 1, end).to_owned()); @@ -265,7 +265,7 @@ pub fn rsplitn(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { let mut count = n; let mut result = ~[]; while end > 0u && count > 0u { - match rposition_between(v, 0u, end, f) { + match rposition_between(v, 0u, end, |t| f(t)) { None => break, Some(i) => { result.push(v.slice(i + 1u, end).to_owned()); diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 6e21ceb64c4..9439f45be21 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -535,18 +535,18 @@ pub fn walk_pat(pat: @pat, it: &fn(@pat) -> bool) -> bool { match pat.node { pat_ident(_, _, Some(p)) => walk_pat(p, it), pat_struct(_, ref fields, _) => { - fields.iter().advance(|f| walk_pat(f.pat, it)) + fields.iter().advance(|f| walk_pat(f.pat, |p| it(p))) } pat_enum(_, Some(ref s)) | pat_tup(ref s) => { - s.iter().advance(|&p| walk_pat(p, it)) + s.iter().advance(|&p| walk_pat(p, |p| it(p))) } pat_box(s) | pat_uniq(s) | pat_region(s) => { walk_pat(s, it) } pat_vec(ref before, ref slice, ref after) => { - before.iter().advance(|&p| walk_pat(p, it)) && - slice.iter().advance(|&p| walk_pat(p, it)) && - after.iter().advance(|&p| walk_pat(p, it)) + before.iter().advance(|&p| walk_pat(p, |p| it(p))) && + slice.iter().advance(|&p| walk_pat(p, |p| it(p))) && + after.iter().advance(|&p| walk_pat(p, |p| it(p))) } pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _, _) | pat_enum(_, _) => { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 282a28ff9e0..78fdb99753d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -509,7 +509,7 @@ impl MapChain{ } }, ConsMapChain (~ref mut map, rest) => { - if satisfies_pred(map,&n,pred) { + if satisfies_pred(map,&n,|v|pred(v)) { map.insert(key,ext); } else { rest.insert_into_frame(key,ext,n,pred) diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 8403234f892..15fb6ee9ff7 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -43,15 +43,21 @@ pub fn expand_deriving_iter_bytes(cx: @ExtCtxt, } fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { - let lsb0_f = match substr.nonself_args { - [l, f] => ~[l, f], + let (lsb0, f)= match substr.nonself_args { + [l, f] => (l, f), _ => cx.span_bug(span, "Incorrect number of arguments in `deriving(IterBytes)`") }; + // Build the "explicitly borrowed" stack closure, "|_buf| f(_buf)". + let blk_arg = cx.ident_of("_buf"); + let borrowed_f = + cx.lambda_expr_1(span, cx.expr_call(span, f, ~[cx.expr_ident(span, blk_arg)]), + blk_arg); + let iter_bytes_ident = substr.method_ident; let call_iterbytes = |thing_expr| { cx.expr_method_call(span, thing_expr, iter_bytes_ident, - copy lsb0_f) + ~[lsb0, borrowed_f]) }; let mut exprs = ~[]; let fields; diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index dfbc028ddf6..19aa29a62a9 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -99,7 +99,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr { (ident, ref summary) => { cx.arm(span, ~[ pat ], - rand_thing(cx, span, ident, summary, rand_call)) + rand_thing(cx, span, ident, summary, || rand_call())) } } }; diff --git a/src/test/compile-fail/regions-creating-enums.rs b/src/test/compile-fail/regions-creating-enums.rs index 2ab0c14b49b..c2d8427d5eb 100644 --- a/src/test/compile-fail/regions-creating-enums.rs +++ b/src/test/compile-fail/regions-creating-enums.rs @@ -33,8 +33,8 @@ fn map_nums(x: &ast, f: &fn(uint) -> uint) -> &ast { return &num(f(x)); //~ ERROR borrowed value does not live long enough } add(x, y) => { - let m_x = map_nums(x, f); - let m_y = map_nums(y, f); + let m_x = map_nums(x, |z| f(z)); + let m_y = map_nums(y, |z| f(z)); return &add(m_x, m_y); //~ ERROR borrowed value does not live long enough } } -- cgit 1.4.1-3-g733a5 From b29c36867418ea551b23c767f45454eea4623d79 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 23 Jun 2013 20:44:11 -0700 Subject: Removing a lot of usage of '&const' --- src/libextra/arc.rs | 4 +- src/libextra/bitv.rs | 4 +- src/libextra/deque.rs | 4 +- src/libextra/flate.rs | 8 ++-- src/libextra/treemap.rs | 8 ++-- src/librustc/middle/lang_items.rs | 76 +++++++++++++++--------------- src/librustc/middle/ty.rs | 4 +- src/librustc/middle/typeck/check/vtable.rs | 2 +- src/libstd/at_vec.rs | 6 +-- src/libstd/hashmap.rs | 8 ++-- src/libstd/io.rs | 6 +-- src/libstd/option.rs | 4 +- src/libstd/ptr.rs | 18 +++---- src/libstd/str.rs | 8 ++-- src/libstd/task/spawn.rs | 2 +- src/libstd/trie.rs | 8 ++-- src/libstd/vec.rs | 72 ++++++++-------------------- 17 files changed, 105 insertions(+), 137 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 30067c92300..13d159d8fed 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -436,8 +436,8 @@ impl RWARC { // lock it. This wraps the unsafety, with the justification that the 'lock' // field is never overwritten; only 'failed' and 'data'. #[doc(hidden)] -fn borrow_rwlock(state: *const RWARCInner) -> *RWlock { - unsafe { cast::transmute(&const (*state).lock) } +fn borrow_rwlock(state: *mut RWARCInner) -> *RWlock { + unsafe { cast::transmute(&(*state).lock) } } /// The "write permission" token used for RWARC.write_downgrade(). diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 4fe7761bf18..92ee3fb43c6 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -705,8 +705,8 @@ impl cmp::Eq for BitvSet { } impl Container for BitvSet { - fn len(&const self) -> uint { self.size } - fn is_empty(&const self) -> bool { self.size == 0 } + fn len(&self) -> uint { self.size } + fn is_empty(&self) -> bool { self.size == 0 } } impl Mutable for BitvSet { diff --git a/src/libextra/deque.rs b/src/libextra/deque.rs index c70c87b6ea1..cf7b188cb1d 100644 --- a/src/libextra/deque.rs +++ b/src/libextra/deque.rs @@ -28,10 +28,10 @@ pub struct Deque { impl Container for Deque { /// Return the number of elements in the deque - fn len(&const self) -> uint { self.nelts } + fn len(&self) -> uint { self.nelts } /// Return true if the deque contains no elements - fn is_empty(&const self) -> bool { self.len() == 0 } + fn is_empty(&self) -> bool { self.len() == 0 } } impl Mutable for Deque { diff --git a/src/libextra/flate.rs b/src/libextra/flate.rs index 0fde03b69cb..fe8f4bee75e 100644 --- a/src/libextra/flate.rs +++ b/src/libextra/flate.rs @@ -44,8 +44,8 @@ static lz_fast : c_int = 0x1; // LZ with only one probe static lz_norm : c_int = 0x80; // LZ with 128 probes, "normal" static lz_best : c_int = 0xfff; // LZ with 4095 probes, "best" -pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] { - do vec::as_const_buf(bytes) |b, len| { +pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] { + do vec::as_imm_buf(bytes) |b, len| { unsafe { let mut outsz : size_t = 0; let res = @@ -62,8 +62,8 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] { } } -pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] { - do vec::as_const_buf(bytes) |b, len| { +pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] { + do vec::as_imm_buf(bytes) |b, len| { unsafe { let mut outsz : size_t = 0; let res = diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index d546b48f817..fcee3a2b796 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -87,10 +87,10 @@ impl Ord for TreeMap { impl Container for TreeMap { /// Return the number of elements in the map - fn len(&const self) -> uint { self.length } + fn len(&self) -> uint { self.length } /// Return true if the map contains no elements - fn is_empty(&const self) -> bool { self.root.is_none() } + fn is_empty(&self) -> bool { self.root.is_none() } } impl Mutable for TreeMap { @@ -265,11 +265,11 @@ impl Ord for TreeSet { impl Container for TreeSet { /// Return the number of elements in the set #[inline] - fn len(&const self) -> uint { self.map.len() } + fn len(&self) -> uint { self.map.len() } /// Return true if the set contains no elements #[inline] - fn is_empty(&const self) -> bool { self.map.is_empty() } + fn is_empty(&self) -> bool { self.map.is_empty() } } impl Mutable for TreeSet { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 08e55df5b36..b167a22992c 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -152,122 +152,122 @@ impl LanguageItems { // FIXME #4621: Method macros sure would be nice here. - pub fn freeze_trait(&const self) -> def_id { + pub fn freeze_trait(&self) -> def_id { self.items[FreezeTraitLangItem as uint].get() } - pub fn copy_trait(&const self) -> def_id { + pub fn copy_trait(&self) -> def_id { self.items[CopyTraitLangItem as uint].get() } - pub fn send_trait(&const self) -> def_id { + pub fn send_trait(&self) -> def_id { self.items[SendTraitLangItem as uint].get() } - pub fn sized_trait(&const self) -> def_id { + pub fn sized_trait(&self) -> def_id { self.items[SizedTraitLangItem as uint].get() } - pub fn drop_trait(&const self) -> def_id { + pub fn drop_trait(&self) -> def_id { self.items[DropTraitLangItem as uint].get() } - pub fn add_trait(&const self) -> def_id { + pub fn add_trait(&self) -> def_id { self.items[AddTraitLangItem as uint].get() } - pub fn sub_trait(&const self) -> def_id { + pub fn sub_trait(&self) -> def_id { self.items[SubTraitLangItem as uint].get() } - pub fn mul_trait(&const self) -> def_id { + pub fn mul_trait(&self) -> def_id { self.items[MulTraitLangItem as uint].get() } - pub fn div_trait(&const self) -> def_id { + pub fn div_trait(&self) -> def_id { self.items[DivTraitLangItem as uint].get() } - pub fn rem_trait(&const self) -> def_id { + pub fn rem_trait(&self) -> def_id { self.items[RemTraitLangItem as uint].get() } - pub fn neg_trait(&const self) -> def_id { + pub fn neg_trait(&self) -> def_id { self.items[NegTraitLangItem as uint].get() } - pub fn not_trait(&const self) -> def_id { + pub fn not_trait(&self) -> def_id { self.items[NotTraitLangItem as uint].get() } - pub fn bitxor_trait(&const self) -> def_id { + pub fn bitxor_trait(&self) -> def_id { self.items[BitXorTraitLangItem as uint].get() } - pub fn bitand_trait(&const self) -> def_id { + pub fn bitand_trait(&self) -> def_id { self.items[BitAndTraitLangItem as uint].get() } - pub fn bitor_trait(&const self) -> def_id { + pub fn bitor_trait(&self) -> def_id { self.items[BitOrTraitLangItem as uint].get() } - pub fn shl_trait(&const self) -> def_id { + pub fn shl_trait(&self) -> def_id { self.items[ShlTraitLangItem as uint].get() } - pub fn shr_trait(&const self) -> def_id { + pub fn shr_trait(&self) -> def_id { self.items[ShrTraitLangItem as uint].get() } - pub fn index_trait(&const self) -> def_id { + pub fn index_trait(&self) -> def_id { self.items[IndexTraitLangItem as uint].get() } - pub fn eq_trait(&const self) -> def_id { + pub fn eq_trait(&self) -> def_id { self.items[EqTraitLangItem as uint].get() } - pub fn ord_trait(&const self) -> def_id { + pub fn ord_trait(&self) -> def_id { self.items[OrdTraitLangItem as uint].get() } - pub fn str_eq_fn(&const self) -> def_id { + pub fn str_eq_fn(&self) -> def_id { self.items[StrEqFnLangItem as uint].get() } - pub fn uniq_str_eq_fn(&const self) -> def_id { + pub fn uniq_str_eq_fn(&self) -> def_id { self.items[UniqStrEqFnLangItem as uint].get() } - pub fn annihilate_fn(&const self) -> def_id { + pub fn annihilate_fn(&self) -> def_id { self.items[AnnihilateFnLangItem as uint].get() } - pub fn log_type_fn(&const self) -> def_id { + pub fn log_type_fn(&self) -> def_id { self.items[LogTypeFnLangItem as uint].get() } - pub fn fail_fn(&const self) -> def_id { + pub fn fail_fn(&self) -> def_id { self.items[FailFnLangItem as uint].get() } - pub fn fail_bounds_check_fn(&const self) -> def_id { + pub fn fail_bounds_check_fn(&self) -> def_id { self.items[FailBoundsCheckFnLangItem as uint].get() } - pub fn exchange_malloc_fn(&const self) -> def_id { + pub fn exchange_malloc_fn(&self) -> def_id { self.items[ExchangeMallocFnLangItem as uint].get() } - pub fn exchange_free_fn(&const self) -> def_id { + pub fn exchange_free_fn(&self) -> def_id { self.items[ExchangeFreeFnLangItem as uint].get() } - pub fn malloc_fn(&const self) -> def_id { + pub fn malloc_fn(&self) -> def_id { self.items[MallocFnLangItem as uint].get() } - pub fn free_fn(&const self) -> def_id { + pub fn free_fn(&self) -> def_id { self.items[FreeFnLangItem as uint].get() } - pub fn borrow_as_imm_fn(&const self) -> def_id { + pub fn borrow_as_imm_fn(&self) -> def_id { self.items[BorrowAsImmFnLangItem as uint].get() } - pub fn borrow_as_mut_fn(&const self) -> def_id { + pub fn borrow_as_mut_fn(&self) -> def_id { self.items[BorrowAsMutFnLangItem as uint].get() } - pub fn return_to_mut_fn(&const self) -> def_id { + pub fn return_to_mut_fn(&self) -> def_id { self.items[ReturnToMutFnLangItem as uint].get() } - pub fn check_not_borrowed_fn(&const self) -> def_id { + pub fn check_not_borrowed_fn(&self) -> def_id { self.items[CheckNotBorrowedFnLangItem as uint].get() } - pub fn strdup_uniq_fn(&const self) -> def_id { + pub fn strdup_uniq_fn(&self) -> def_id { self.items[StrDupUniqFnLangItem as uint].get() } - pub fn record_borrow_fn(&const self) -> def_id { + pub fn record_borrow_fn(&self) -> def_id { self.items[RecordBorrowFnLangItem as uint].get() } - pub fn unrecord_borrow_fn(&const self) -> def_id { + pub fn unrecord_borrow_fn(&self) -> def_id { self.items[UnrecordBorrowFnLangItem as uint].get() } - pub fn start_fn(&const self) -> def_id { + pub fn start_fn(&self) -> def_id { self.items[StartFnLangItem as uint].get() } pub fn ty_desc(&const self) -> def_id { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index b8ee1eee26e..48e841353c0 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3696,14 +3696,14 @@ pub enum DtorKind { } impl DtorKind { - pub fn is_not_present(&const self) -> bool { + pub fn is_not_present(&self) -> bool { match *self { NoDtor => true, _ => false } } - pub fn is_present(&const self) -> bool { + pub fn is_present(&self) -> bool { !self.is_not_present() } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 0bf20f9fbcb..a46d2f28b13 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -64,7 +64,7 @@ pub struct VtableContext { } impl VtableContext { - pub fn tcx(&const self) -> ty::ctxt { self.ccx.tcx } + pub fn tcx(&self) -> ty::ctxt { self.ccx.tcx } } fn has_trait_bounds(type_param_defs: &[ty::TypeParameterDef]) -> bool { diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 5a2f948600a..325ce097cd5 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -108,7 +108,7 @@ pub fn build_sized_opt(size: Option, /// Iterates over the `rhs` vector, copying each element and appending it to the /// `lhs`. Afterwards, the `lhs` is then returned for use again. #[inline] -pub fn append(lhs: @[T], rhs: &const [T]) -> @[T] { +pub fn append(lhs: @[T], rhs: &[T]) -> @[T] { do build_sized(lhs.len() + rhs.len()) |push| { for lhs.iter().advance |x| { push(copy *x); } for uint::range(0, rhs.len()) |i| { push(copy rhs[i]); } @@ -180,9 +180,9 @@ pub mod traits { use kinds::Copy; use ops::Add; - impl<'self,T:Copy> Add<&'self const [T],@[T]> for @[T] { + impl<'self,T:Copy> Add<&'self [T],@[T]> for @[T] { #[inline] - fn add(&self, rhs: & &'self const [T]) -> @[T] { + fn add(&self, rhs: & &'self [T]) -> @[T] { append(*self, (*rhs)) } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 7f9fb6ad938..35db229b65d 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -282,10 +282,10 @@ impl HashMap { impl Container for HashMap { /// Return the number of elements in the map - fn len(&const self) -> uint { self.size } + fn len(&self) -> uint { self.size } /// Return true if the map contains no elements - fn is_empty(&const self) -> bool { self.len() == 0 } + fn is_empty(&self) -> bool { self.len() == 0 } } impl Mutable for HashMap { @@ -623,10 +623,10 @@ impl Eq for HashSet { impl Container for HashSet { /// Return the number of elements in the set - fn len(&const self) -> uint { self.map.len() } + fn len(&self) -> uint { self.map.len() } /// Return true if the set contains no elements - fn is_empty(&const self) -> bool { self.map.is_empty() } + fn is_empty(&self) -> bool { self.map.is_empty() } } impl Mutable for HashSet { diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 59ac58a514f..40793ff1af7 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1152,7 +1152,7 @@ impl Writer for Wrapper { impl Writer for *libc::FILE { fn write(&self, v: &[u8]) { unsafe { - do vec::as_const_buf(v) |vbuf, len| { + do vec::as_imm_buf(v) |vbuf, len| { let nout = libc::fwrite(vbuf as *c_void, 1, len as size_t, @@ -1203,9 +1203,9 @@ impl Writer for fd_t { fn write(&self, v: &[u8]) { unsafe { let mut count = 0u; - do vec::as_const_buf(v) |vbuf, len| { + do vec::as_imm_buf(v) |vbuf, len| { while count < len { - let vb = ptr::const_offset(vbuf, count) as *c_void; + let vb = ptr::offset(vbuf, count) as *c_void; let nout = libc::write(*self, vb, len as size_t); if nout < 0 as ssize_t { error!("error writing buffer"); diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 12ae2abd4a1..64381231258 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -121,13 +121,13 @@ impl Option { /// Returns true if the option equals `none` #[inline] - pub fn is_none(&const self) -> bool { + pub fn is_none(&self) -> bool { match *self { None => true, Some(_) => false } } /// Returns true if the option contains some value #[inline] - pub fn is_some(&const self) -> bool { !self.is_none() } + pub fn is_some(&self) -> bool { !self.is_none() } /// Update an optional value by optionally running its content through a /// function that returns an option. diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 7f89d454be1..473f56ddd79 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -232,9 +232,9 @@ pub unsafe fn array_each(arr: **T, cb: &fn(*T)) { #[allow(missing_doc)] pub trait RawPtr { - fn is_null(&const self) -> bool; - fn is_not_null(&const self) -> bool; - unsafe fn to_option(&const self) -> Option<&T>; + fn is_null(&self) -> bool; + fn is_not_null(&self) -> bool; + unsafe fn to_option(&self) -> Option<&T>; fn offset(&self, count: uint) -> Self; } @@ -242,11 +242,11 @@ pub trait RawPtr { impl RawPtr for *T { /// Returns true if the pointer is equal to the null pointer. #[inline] - fn is_null(&const self) -> bool { is_null(*self) } + fn is_null(&self) -> bool { is_null(*self) } /// Returns true if the pointer is not equal to the null pointer. #[inline] - fn is_not_null(&const self) -> bool { is_not_null(*self) } + fn is_not_null(&self) -> bool { is_not_null(*self) } /// /// Returns `None` if the pointer is null, or else returns the value wrapped @@ -259,7 +259,7 @@ impl RawPtr for *T { /// be pointing to invalid memory. /// #[inline] - unsafe fn to_option(&const self) -> Option<&T> { + unsafe fn to_option(&self) -> Option<&T> { if self.is_null() { None } else { Some(cast::transmute(*self)) } @@ -274,11 +274,11 @@ impl RawPtr for *T { impl RawPtr for *mut T { /// Returns true if the pointer is equal to the null pointer. #[inline] - fn is_null(&const self) -> bool { is_null(*self) } + fn is_null(&self) -> bool { is_null(*self) } /// Returns true if the pointer is not equal to the null pointer. #[inline] - fn is_not_null(&const self) -> bool { is_not_null(*self) } + fn is_not_null(&self) -> bool { is_not_null(*self) } /// /// Returns `None` if the pointer is null, or else returns the value wrapped @@ -291,7 +291,7 @@ impl RawPtr for *mut T { /// be pointing to invalid memory. /// #[inline] - unsafe fn to_option(&const self) -> Option<&T> { + unsafe fn to_option(&self) -> Option<&T> { if self.is_null() { None } else { Some(cast::transmute(*self)) } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index e47800d70c6..a06d858e424 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -569,7 +569,7 @@ Section: Misc */ /// Determines if a vector of bytes contains valid UTF-8 -pub fn is_utf8(v: &const [u8]) -> bool { +pub fn is_utf8(v: &[u8]) -> bool { let mut i = 0u; let total = v.len(); while i < total { @@ -815,7 +815,7 @@ pub mod raw { } /// Create a Rust string from a *u8 buffer of the given length - pub unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str { + pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str { let mut v: ~[u8] = vec::with_capacity(len + 1); vec::as_mut_buf(v, |vbuf, _len| { ptr::copy_memory(vbuf, buf as *u8, len) @@ -838,8 +838,8 @@ pub mod raw { } /// Converts a vector of bytes to a new owned string. - pub unsafe fn from_bytes(v: &const [u8]) -> ~str { - do vec::as_const_buf(v) |buf, len| { + pub unsafe fn from_bytes(v: &[u8]) -> ~str { + do vec::as_imm_buf(v) |buf, len| { from_buf_len(buf, len) } } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index c932a9660c2..190485a720a 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -129,7 +129,7 @@ type TaskGroupInner<'self> = &'self mut Option; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { - (&const tg.members).is_empty() + tg.members.is_empty() } // A list-like structure by which taskgroups keep track of all ancestor groups diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index b9b03ea5661..8ce02d59ab1 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -35,11 +35,11 @@ pub struct TrieMap { impl Container for TrieMap { /// Return the number of elements in the map #[inline] - fn len(&const self) -> uint { self.length } + fn len(&self) -> uint { self.length } /// Return true if the map contains no elements #[inline] - fn is_empty(&const self) -> bool { self.len() == 0 } + fn is_empty(&self) -> bool { self.len() == 0 } } impl Mutable for TrieMap { @@ -179,11 +179,11 @@ pub struct TrieSet { impl Container for TrieSet { /// Return the number of elements in the set #[inline] - fn len(&const self) -> uint { self.map.len() } + fn len(&self) -> uint { self.map.len() } /// Return true if the set contains no elements #[inline] - fn is_empty(&const self) -> bool { self.map.is_empty() } + fn is_empty(&self) -> bool { self.map.is_empty() } } impl Mutable for TrieSet { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 4e7943f7cfd..4196fbac0be 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -64,7 +64,7 @@ pub mod rustrt { } /// Returns true if two vectors have the same length -pub fn same_length(xs: &const [T], ys: &const [U]) -> bool { +pub fn same_length(xs: &[T], ys: &[U]) -> bool { xs.len() == ys.len() } @@ -350,10 +350,7 @@ pub fn dedup(v: &mut ~[T]) { if v.len() < 1 { return; } let mut last_written = 0; let mut next_to_read = 1; - 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; + do as_mut_buf(*v) |p, ln| { // last_written < next_to_read <= ln while next_to_read < ln { // last_written < next_to_read < ln @@ -384,7 +381,7 @@ pub fn dedup(v: &mut ~[T]) { /// Iterates over the `rhs` vector, copying each element and appending it to the /// `lhs`. Afterwards, the `lhs` is then returned for use again. #[inline] -pub fn append(lhs: ~[T], rhs: &const [T]) -> ~[T] { +pub fn append(lhs: ~[T], rhs: &[T]) -> ~[T] { let mut v = lhs; v.push_all(rhs); v @@ -831,7 +828,7 @@ pub fn unzip(v: ~[(T, U)]) -> (~[T], ~[U]) { /** * Convert two vectors to a vector of pairs, by reference. As zip(). */ -pub fn zip_slice(v: &const [T], u: &const [U]) +pub fn zip_slice(v: &[T], u: &[U]) -> ~[(T, U)] { let mut zipped = ~[]; let sz = v.len(); @@ -893,7 +890,7 @@ pub fn reverse(v: &mut [T]) { } /// Returns a vector with the order of elements reversed -pub fn reversed(v: &const [T]) -> ~[T] { +pub fn reversed(v: &[T]) -> ~[T] { let mut rs: ~[T] = ~[]; let mut i = v.len(); if i == 0 { return (rs); } else { i -= 1; } @@ -1003,16 +1000,6 @@ pub fn as_imm_buf(s: &[T], } } -/// Similar to `as_imm_buf` but passing a `*const T` -#[inline] -pub fn as_const_buf(s: &const [T], f: &fn(*const T, uint) -> U) -> U { - unsafe { - let v : *(*const T,uint) = transmute(&s); - let (buf,len) = *v; - f(buf, len / sys::nonzero_size_of::()) - } -} - /// Similar to `as_imm_buf` but passing a `*mut T` #[inline] pub fn as_mut_buf(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U { @@ -1198,25 +1185,25 @@ pub mod traits { use ops::Add; use vec::append; - impl<'self,T:Copy> Add<&'self const [T],~[T]> for ~[T] { + impl<'self,T:Copy> Add<&'self [T],~[T]> for ~[T] { #[inline] - fn add(&self, rhs: & &'self const [T]) -> ~[T] { + fn add(&self, rhs: & &'self [T]) -> ~[T] { append(copy *self, (*rhs)) } } } -impl<'self, T> Container for &'self const [T] { +impl<'self, T> Container for &'self [T] { /// Returns true if a vector contains no elements #[inline] fn is_empty(&self) -> bool { - as_const_buf(*self, |_p, len| len == 0u) + as_imm_buf(*self, |_p, len| len == 0u) } /// Returns the length of a vector #[inline] fn len(&self) -> uint { - as_const_buf(*self, |_p, len| len) + as_imm_buf(*self, |_p, len| len) } } @@ -1224,13 +1211,13 @@ impl Container for ~[T] { /// Returns true if a vector contains no elements #[inline] fn is_empty(&self) -> bool { - as_const_buf(*self, |_p, len| len == 0u) + as_imm_buf(*self, |_p, len| len == 0u) } /// Returns the length of a vector #[inline] fn len(&self) -> uint { - as_const_buf(*self, |_p, len| len) + as_imm_buf(*self, |_p, len| len) } } @@ -1843,7 +1830,7 @@ impl Mutable for ~[T] { #[allow(missing_doc)] pub trait OwnedCopyableVector { - fn push_all(&mut self, rhs: &const [T]); + fn push_all(&mut self, rhs: &[T]); fn grow(&mut self, n: uint, initval: &T); fn grow_set(&mut self, index: uint, initval: &T, val: T); } @@ -1860,7 +1847,7 @@ impl OwnedCopyableVector for ~[T] { /// assert!(a == ~[1, 2, 3, 4]); /// ~~~ #[inline] - fn push_all(&mut self, rhs: &const [T]) { + fn push_all(&mut self, rhs: &[T]) { let new_len = self.len() + rhs.len(); self.reserve(new_len); @@ -2017,7 +2004,7 @@ pub mod raw { use ptr; use sys; use unstable::intrinsics; - use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, with_capacity}; + use vec::{UnboxedVecRepr, as_imm_buf, as_mut_buf, with_capacity}; use util; /// The internal representation of a (boxed) vector @@ -2065,15 +2052,6 @@ pub mod raw { } } - /** see `to_ptr()` */ - #[inline] - pub fn to_const_ptr(v: &const [T]) -> *const T { - unsafe { - let repr: **SliceRepr = transmute(&v); - transmute(&((**repr).data)) - } - } - /** see `to_ptr()` */ #[inline] pub fn to_mut_ptr(v: &mut [T]) -> *mut T { @@ -2113,8 +2091,8 @@ pub mod raw { * Unchecked vector indexing. */ #[inline] - pub unsafe fn get(v: &const [T], i: uint) -> T { - as_const_buf(v, |p, _len| copy *ptr::const_offset(p, i)) + pub unsafe fn get(v: &[T], i: uint) -> T { + as_imm_buf(v, |p, _len| copy *ptr::offset(p, i)) } /** @@ -2156,13 +2134,13 @@ pub mod raw { * may overlap. */ #[inline] - pub unsafe fn copy_memory(dst: &mut [T], src: &const [T], + pub unsafe fn copy_memory(dst: &mut [T], src: &[T], count: uint) { assert!(dst.len() >= count); assert!(src.len() >= count); do as_mut_buf(dst) |p_dst, _len_dst| { - do as_const_buf(src) |p_src, _len_src| { + do as_imm_buf(src) |p_src, _len_src| { ptr::copy_memory(p_dst, p_src, count) } } @@ -2238,7 +2216,7 @@ pub mod bytes { * may overlap. */ #[inline] - pub fn copy_memory(dst: &mut [u8], src: &const [u8], count: uint) { + pub fn copy_memory(dst: &mut [u8], src: &[u8], count: uint) { // Bound checks are done at vec::raw::copy_memory. unsafe { vec::raw::copy_memory(dst, src, count) } } @@ -3690,16 +3668,6 @@ mod tests { } } - #[test] - #[ignore(windows)] - #[should_fail] - fn test_as_const_buf_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - do as_const_buf(v) |_buf, _i| { - fail!() - } - } - #[test] #[ignore(cfg(windows))] #[should_fail] -- cgit 1.4.1-3-g733a5