From 10612ee30c31d33885f233c3e5839574fdb8be80 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 19 Oct 2012 11:37:00 -0700 Subject: [PATCH] Remove superfluous by-ref in option::get, option::get_default, option::expect Superficial change, no review. --- src/fuzzer/fuzzer.rs | 2 +- src/libcore/dlist.rs | 24 ++++++++++++------------ src/libcore/iter-trait/dlist.rs | 2 +- src/libcore/option.rs | 18 +++++++++--------- src/libcore/os.rs | 2 +- src/libstd/map.rs | 2 +- src/rustc/middle/trans/alt.rs | 2 +- src/rustc/middle/trans/meth.rs | 2 +- src/rustc/middle/trans/monomorphize.rs | 4 ++-- src/rustc/middle/trans/reflect.rs | 2 +- src/rustdoc/attr_pass.rs | 4 ++-- src/rustdoc/doc.rs | 2 +- src/test/run-pass/test-ignore-cfg.rs | 4 ++-- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 018972d4c3e0..a4968382cf47 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -296,7 +296,7 @@ fn check_variants_T( } fn last_part(filename: ~str) -> ~str { - let ix = option::get(&str::rfind_char(filename, '/')); + let ix = option::get(str::rfind_char(filename, '/')); str::slice(filename, ix + 1u, str::len(filename) - 3u) } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 3bcf486ef7e0..35399878e261 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -208,7 +208,7 @@ impl DList { fn push_head_n(data: T) -> DListNode { let mut nobe = self.new_link(move data); self.add_head(nobe); - option::get(&nobe) + option::get(nobe) } /// Add data to the tail of the list. O(1). fn push(data: T) { @@ -221,7 +221,7 @@ impl DList { fn push_n(data: T) -> DListNode { let mut nobe = self.new_link(move data); self.add_tail(nobe); - option::get(&nobe) + option::get(nobe) } /** * Insert data into the middle of the list, left of the given node. @@ -245,7 +245,7 @@ impl DList { fn insert_before_n(data: T, neighbour: DListNode) -> DListNode { let mut nobe = self.new_link(move data); self.insert_left(nobe, neighbour); - option::get(&nobe) + option::get(nobe) } /** * Insert data into the middle of the list, right of the given node. @@ -269,7 +269,7 @@ impl DList { fn insert_after_n(data: T, neighbour: DListNode) -> DListNode { let mut nobe = self.new_link(move data); self.insert_right(neighbour, nobe); - option::get(&nobe) + option::get(nobe) } /// Remove a node from the head of the list. O(1). @@ -385,17 +385,17 @@ impl DList { let mut link = self.peek_n(); let mut rabbit = link; while option::is_some(&link) { - let nobe = option::get(&link); + let nobe = option::get(link); assert nobe.linked; // check cycle if option::is_some(&rabbit) { - rabbit = option::get(&rabbit).next; + rabbit = option::get(rabbit).next; } if option::is_some(&rabbit) { - rabbit = option::get(&rabbit).next; + rabbit = option::get(rabbit).next; } if option::is_some(&rabbit) { - assert !box::ptr_eq(*option::get(&rabbit), *nobe); + assert !box::ptr_eq(*option::get(rabbit), *nobe); } // advance link = nobe.next_link(); @@ -406,17 +406,17 @@ impl DList { link = self.peek_tail_n(); rabbit = link; while option::is_some(&link) { - let nobe = option::get(&link); + let nobe = option::get(link); assert nobe.linked; // check cycle if option::is_some(&rabbit) { - rabbit = option::get(&rabbit).prev; + rabbit = option::get(rabbit).prev; } if option::is_some(&rabbit) { - rabbit = option::get(&rabbit).prev; + rabbit = option::get(rabbit).prev; } if option::is_some(&rabbit) { - assert !box::ptr_eq(*option::get(&rabbit), *nobe); + assert !box::ptr_eq(*option::get(rabbit), *nobe); } // advance link = nobe.prev_link(); diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs index 2a5bb59b0c1f..1b5f11569c37 100644 --- a/src/libcore/iter-trait/dlist.rs +++ b/src/libcore/iter-trait/dlist.rs @@ -11,7 +11,7 @@ pub type IMPL_T = dlist::DList; pub pure fn EACH(self: &IMPL_T, f: fn(v: &A) -> bool) { let mut link = self.peek_n(); while option::is_some(&link) { - let nobe = option::get(&link); + let nobe = option::get(link); assert nobe.linked; if !f(&nobe.data) { break; } // Check (weakly) that the user didn't do a remove. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 50489a820291..baabc35b428c 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -42,7 +42,7 @@ pub enum Option { Some(T), } -pub pure fn get(opt: &Option) -> T { +pub pure fn get(opt: Option) -> T { /*! Gets the value out of an option @@ -58,7 +58,7 @@ pub pure fn get(opt: &Option) -> T { case explicitly. */ - match *opt { + match opt { Some(copy x) => return x, None => fail ~"option::get none" } @@ -85,7 +85,7 @@ pub pure fn get_ref(opt: &r/Option) -> &r/T { } } -pub pure fn expect(opt: &Option, reason: ~str) -> T { +pub pure fn expect(opt: Option, reason: ~str) -> T { /*! * Gets the value out of an option, printing a specified message on * failure @@ -94,7 +94,7 @@ pub pure fn expect(opt: &Option, reason: ~str) -> T { * * Fails if the value equals `none` */ - match *opt { Some(copy x) => x, None => fail reason } + match opt { Some(copy x) => x, None => fail reason } } pub pure fn map(opt: &Option, f: fn(x: &T) -> U) -> Option { @@ -167,10 +167,10 @@ pub pure fn is_some(opt: &Option) -> bool { !is_none(opt) } -pub pure fn get_default(opt: &Option, def: T) -> T { +pub pure fn get_default(opt: Option, def: T) -> T { //! Returns the contained value or a default - match *opt { Some(copy x) => x, None => def } + match opt { Some(copy x) => x, None => def } } pub pure fn map_default(opt: &Option, def: U, @@ -284,8 +284,8 @@ impl Option { Instead, prefer to use pattern matching and handle the `None` case explicitly. */ - pure fn get() -> T { get(&self) } - pure fn get_default(def: T) -> T { get_default(&self, def) } + pure fn get() -> T { get(self) } + pure fn get_default(def: T) -> T { get_default(self, def) } /** * Gets the value out of an option, printing a specified message on * failure @@ -294,7 +294,7 @@ impl Option { * * Fails if the value equals `none` */ - pure fn expect(reason: ~str) -> T { expect(&self, move reason) } + pure fn expect(reason: ~str) -> T { expect(self, move reason) } /// Applies a function zero or more times until the result is none. pure fn while_some(blk: fn(v: T) -> Option) { while_some(self, blk) } } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 24e4d7eff41f..d201761d86be 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -473,7 +473,7 @@ pub fn tmpdir() -> Path { #[cfg(unix)] #[allow(non_implicitly_copyable_typarams)] fn lookup() -> Path { - option::get_default(&getenv_nonempty("TMPDIR"), + option::get_default(getenv_nonempty("TMPDIR"), Path("/tmp")) } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 9f78f98fa316..e49f1abd02b4 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -723,7 +723,7 @@ mod tests { let map = map::HashMap::<~str, ~str>(); assert (option::is_none(&map.find(key))); map.insert(key, ~"val"); - assert (option::get(&map.find(key)) == ~"val"); + assert (option::get(map.find(key)) == ~"val"); } #[test] diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index d760bc349073..6de9ad977c9f 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -353,7 +353,7 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint, match p.node { ast::pat_enum(_, subpats) => { if opt_eq(tcx, &variant_opt(tcx, p.id), opt) { - Some(option::get_default(&subpats, + Some(option::get_default(subpats, vec::from_elem(variant_size, dummy))) } else { diff --git a/src/rustc/middle/trans/meth.rs b/src/rustc/middle/trans/meth.rs index 89b101ab8759..fadde08b9f89 100644 --- a/src/rustc/middle/trans/meth.rs +++ b/src/rustc/middle/trans/meth.rs @@ -299,7 +299,7 @@ fn trans_static_method_callee(bcx: block, fn method_from_methods(ms: ~[@ast::method], name: ast::ident) -> ast::def_id { - local_def(option::get(&vec::find(ms, |m| m.ident == name)).id) + local_def(option::get(vec::find(ms, |m| m.ident == name)).id) } fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id, diff --git a/src/rustc/middle/trans/monomorphize.rs b/src/rustc/middle/trans/monomorphize.rs index f6763206e18c..aadd6fc7957a 100644 --- a/src/rustc/middle/trans/monomorphize.rs +++ b/src/rustc/middle/trans/monomorphize.rs @@ -113,7 +113,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, ccx.stats.n_monos += 1; - let depth = option::get_default(&ccx.monomorphizing.find(fn_id), 0u); + let depth = option::get_default(ccx.monomorphizing.find(fn_id), 0u); // Random cut-off -- code that needs to instantiate the same function // recursively more than ten times can probably safely be assumed to be // causing an infinite expansion. @@ -158,7 +158,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, } ast_map::node_variant(v, enum_item, _) => { let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); - let this_tv = option::get(&vec::find(*tvs, |tv| { + let this_tv = option::get(vec::find(*tvs, |tv| { tv.id.node == fn_id.node})); let d = mk_lldecl(); set_inline_hint(d); diff --git a/src/rustc/middle/trans/reflect.rs b/src/rustc/middle/trans/reflect.rs index 18a25888bb46..c52b653d536c 100644 --- a/src/rustc/middle/trans/reflect.rs +++ b/src/rustc/middle/trans/reflect.rs @@ -57,7 +57,7 @@ impl reflector { fn visit(ty_name: ~str, args: ~[ValueRef]) { let tcx = self.bcx.tcx(); - let mth_idx = option::get(&ty::method_idx( + let mth_idx = option::get(ty::method_idx( tcx.sess.ident_of(~"visit_" + ty_name), *self.visitor_methods)); let mth_ty = ty::mk_fn(tcx, self.visitor_methods[mth_idx].fty); diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index cd310791b4df..0748f603580b 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -52,7 +52,7 @@ fn fold_crate( { topmod: doc::ModDoc_({ item: { - name: option::get_default(&attrs.name, doc.topmod.name()), + name: option::get_default(attrs.name, doc.topmod.name()), .. doc.topmod.item }, .. *doc.topmod @@ -151,7 +151,7 @@ fn fold_enum( node: ast::item_enum(enum_definition, _), _ }, _) => { let ast_variant = option::get( - &vec::find(enum_definition.variants, |v| { + vec::find(enum_definition.variants, |v| { to_str(v.node.name) == variant.name })); diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index 0764d9e24326..2d5bf5fc3c69 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -377,7 +377,7 @@ impl IndexEntry : cmp::Eq { impl Doc { fn CrateDoc() -> CrateDoc { - option::get(&vec::foldl(None, self.pages, |_m, page| { + option::get(vec::foldl(None, self.pages, |_m, page| { match *page { doc::CratePage(doc) => Some(doc), _ => None diff --git a/src/test/run-pass/test-ignore-cfg.rs b/src/test/run-pass/test-ignore-cfg.rs index 0482fc278c81..0baabecb0ab9 100644 --- a/src/test/run-pass/test-ignore-cfg.rs +++ b/src/test/run-pass/test-ignore-cfg.rs @@ -20,10 +20,10 @@ fn checktests() { let tests = __test::tests(); let shouldignore = option::get( - &vec::find(tests, |t| t.name == ~"shouldignore" )); + vec::find(tests, |t| t.name == ~"shouldignore" )); assert shouldignore.ignore == true; let shouldnotignore = option::get( - &vec::find(tests, |t| t.name == ~"shouldnotignore" )); + vec::find(tests, |t| t.name == ~"shouldnotignore" )); assert shouldnotignore.ignore == false; } \ No newline at end of file