]> git.lizzy.rs Git - rust.git/commitdiff
default => or_insert per RFC
authorAlexis Beingessner <a.beingessner@gmail.com>
Fri, 20 Mar 2015 17:43:01 +0000 (13:43 -0400)
committerAlexis <a.beingessner@gmail.com>
Fri, 27 Mar 2015 11:42:03 +0000 (07:42 -0400)
16 files changed:
src/libcollections/btree/map.rs
src/libcollections/vec_map.rs
src/librustc/metadata/loader.rs
src/librustc/middle/dataflow.rs
src/librustc/middle/traits/fulfill.rs
src/librustc/middle/ty.rs
src/librustc/session/config.rs
src/librustc_resolve/lib.rs
src/librustc_resolve/resolve_imports.rs
src/librustc_typeck/check/mod.rs
src/librustdoc/html/render.rs
src/librustdoc/lib.rs
src/libstd/collections/hash/map.rs
src/libstd/collections/mod.rs
src/libsyntax/ext/mtwt.rs
src/libsyntax/lib.rs

index 1c484d5dd5eea4b7564376ee5f67275c479910e4..04a692cc3aea2b59d63675bb648ddcd900418d4b 100644 (file)
@@ -1146,7 +1146,7 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
     #[unstable(feature = "std_misc",
                reason = "will soon be replaced by or_insert")]
     #[deprecated(since = "1.0",
-                reason = "replaced with more ergonomic `default` and `default_with`")]
+                reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
     /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
     pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
         match self {
@@ -1159,7 +1159,7 @@ pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the default if empty, and returns
     /// a mutable reference to the value in the entry.
-    pub fn default(self, default: V) -> &'a mut V {
+    pub fn or_insert(self, default: V) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default),
@@ -1170,7 +1170,7 @@ pub fn default(self, default: V) -> &'a mut V {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the result of the default function if empty,
     /// and returns a mutable reference to the value in the entry.
-    pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
+    pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default()),
@@ -1592,7 +1592,7 @@ pub fn range_mut<'a>(&'a mut self, min: Bound<&K>, max: Bound<&K>) -> RangeMut<'
     ///
     /// // count the number of occurrences of letters in the vec
     /// for x in vec!["a","b","a","c","a","b"] {
-    ///     *count.entry(x).default(0) += 1;
+    ///     *count.entry(x).or_insert(0) += 1;
     /// }
     ///
     /// assert_eq!(count["a"], 3);
index 94dd997947c39556465645dedc26a41c9d43f251..58f9101d1d366046597aa756dcc5ab7eafc19f39 100644 (file)
@@ -637,7 +637,7 @@ pub fn remove(&mut self, key: &usize) -> Option<V> {
     ///
     /// // count the number of occurrences of numbers in the vec
     /// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4] {
-    ///     *count.entry(x).default(0) += 1;
+    ///     *count.entry(x).or_insert(0) += 1;
     /// }
     ///
     /// assert_eq!(count[1], 3);
@@ -667,7 +667,7 @@ impl<'a, V> Entry<'a, V> {
     #[unstable(feature = "collections",
                reason = "will soon be replaced by or_insert")]
     #[deprecated(since = "1.0",
-                reason = "replaced with more ergonomic `default` and `default_with`")]
+                reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
     /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
     pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
         match self {
@@ -680,7 +680,7 @@ pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the default if empty, and returns
     /// a mutable reference to the value in the entry.
-    pub fn default(self, default: V) -> &'a mut V {
+    pub fn or_insert(self, default: V) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default),
@@ -691,7 +691,7 @@ pub fn default(self, default: V) -> &'a mut V {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the result of the default function if empty,
     /// and returns a mutable reference to the value in the entry.
-    pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
+    pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default()),
index a36d425c03e582d76aec7252072d1e10e20b38e6..80fc3769453427f4815464ccbca410dd2c4129d4 100644 (file)
@@ -426,7 +426,8 @@ fn find_library_crate(&mut self) -> Option<Library> {
             info!("lib candidate: {}", path.display());
 
             let hash_str = hash.to_string();
-            let slot = candidates.entry(hash_str).default_with(|| (HashMap::new(), HashMap::new()));
+            let slot = candidates.entry(hash_str)
+                                 .or_insert_with(|| (HashMap::new(), HashMap::new()));
             let (ref mut rlibs, ref mut dylibs) = *slot;
             if rlib {
                 rlibs.insert(fs::realpath(path).unwrap(), kind);
index 71b36e21d3e6fe676b8713c7953b755b38b525e6..0d58fd2702f680e692933464c594e232ec1d1188 100644 (file)
@@ -160,7 +160,7 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>,
 
     cfg.graph.each_node(|node_idx, node| {
         if let cfg::CFGNodeData::AST(id) = node.data {
-            index.entry(id).default(vec![]).push(node_idx);
+            index.entry(id).or_insert(vec![]).push(node_idx);
         }
         true
     });
@@ -180,7 +180,7 @@ struct Formals<'a> {
         visit::walk_fn_decl(&mut formals, decl);
         impl<'a, 'v> visit::Visitor<'v> for Formals<'a> {
             fn visit_pat(&mut self, p: &ast::Pat) {
-                self.index.entry(p.id).default(vec![]).push(self.entry);
+                self.index.entry(p.id).or_insert(vec![]).push(self.entry);
                 visit::walk_pat(self, p)
             }
         }
index 76050d53a744808cf7222ef245e0d66d70c9f434..3d46f93914a589c53d21354b1aeff8fde7c63deb 100644 (file)
@@ -436,7 +436,7 @@ fn register_region_obligation<'tcx>(tcx: &ty::ctxt<'tcx>,
     debug!("register_region_obligation({})",
            region_obligation.repr(tcx));
 
-    region_obligations.entry(region_obligation.cause.body_id).default(vec![])
+    region_obligations.entry(region_obligation.cause.body_id).or_insert(vec![])
         .push(region_obligation);
 
 }
index 975d1560d6cfbf1872b53442fb6a91595cc3c807..23fba5ead22598df14a75fa8eced8f960053ed28 100644 (file)
@@ -5669,7 +5669,7 @@ pub fn lookup_field_type<'tcx>(tcx: &ctxt<'tcx>,
         node_id_to_type(tcx, id.node)
     } else {
         let mut tcache = tcx.tcache.borrow_mut();
-        tcache.entry(id).default_with(|| csearch::get_field_type(tcx, struct_id, id)).ty
+        tcache.entry(id).or_insert_with(|| csearch::get_field_type(tcx, struct_id, id)).ty
     };
     ty.subst(tcx, substs)
 }
@@ -6817,7 +6817,7 @@ pub fn replace_late_bound_regions<'tcx, T, F>(
         debug!("region={}", region.repr(tcx));
         match region {
             ty::ReLateBound(debruijn, br) if debruijn.depth == current_depth => {
-                let region = *map.entry(br).default_with(|| mapf(br));
+                let region = *map.entry(br).or_insert_with(|| mapf(br));
 
                 if let ty::ReLateBound(debruijn1, br) = region {
                     // If the callback returns a late-bound region,
index 5f0ab10488557499f48be64c4206db9045a82b4b..931cfc7999281cecd767328b1b6a47126f958d47 100644 (file)
@@ -1036,7 +1036,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
             None => early_error("--extern value must be of the format `foo=bar`"),
         };
 
-        externs.entry(name.to_string()).default(vec![]).push(location.to_string());
+        externs.entry(name.to_string()).or_insert(vec![]).push(location.to_string());
     }
 
     let crate_name = matches.opt_str("crate-name");
index 566af2590e6c07cd0ec1a256856951ee36478222..5bf561c218d044365f88de58687a99b0a078a6ac 100644 (file)
@@ -26,7 +26,6 @@
 #![feature(rustc_diagnostic_macros)]
 #![feature(rustc_private)]
 #![feature(staged_api)]
-#![feature(std_misc)]
 
 #[macro_use] extern crate log;
 #[macro_use] extern crate syntax;
index 46451019760dd478aa179449473532a32d15fe63..662b5a366431ca785460742cc0775e2fb0ca6f42 100644 (file)
@@ -836,11 +836,8 @@ fn merge_import_resolution(&mut self,
         let is_public = import_directive.is_public;
 
         let mut import_resolutions = module_.import_resolutions.borrow_mut();
-        let dest_import_resolution = import_resolutions.entry(name).get().unwrap_or_else(
-            |vacant_entry| {
-                // Create a new import resolution from this child.
-                vacant_entry.insert(ImportResolution::new(id, is_public))
-            });
+        let dest_import_resolution = import_resolutions.entry(name)
+            .or_insert_with(|| ImportResolution::new(id, is_public));
 
         debug!("(resolving glob import) writing resolution `{}` in `{}` \
                to `{}`",
index 4aa5f09c1427c3cdc4cbc196e409d54dc0f40cb2..0f9836bc0734606cd504c05f52229fe9010f5ab5 100644 (file)
@@ -1361,7 +1361,7 @@ fn record_deferred_call_resolution(&self,
                                        closure_def_id: ast::DefId,
                                        r: DeferredCallResolutionHandler<'tcx>) {
         let mut deferred_call_resolutions = self.inh.deferred_call_resolutions.borrow_mut();
-        deferred_call_resolutions.entry(closure_def_id).default(vec![]).push(r);
+        deferred_call_resolutions.entry(closure_def_id).or_insert(vec![]).push(r);
     }
 
     fn remove_deferred_call_resolutions(&self,
index 5ca31ae26e1264646918432c5f76d89b0b8ea9d0..d36124247945bf936f473641e49f704e82a0c7e7 100644 (file)
@@ -876,7 +876,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
         if let clean::ImplItem(ref i) = item.inner {
             match i.trait_ {
                 Some(clean::ResolvedPath{ did, .. }) => {
-                    self.implementors.entry(did).default(vec![]).push(Implementor {
+                    self.implementors.entry(did).or_insert(vec![]).push(Implementor {
                         def_id: item.def_id,
                         generics: i.generics.clone(),
                         trait_: i.trait_.as_ref().unwrap().clone(),
@@ -1078,7 +1078,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                         };
 
                         if let Some(did) = did {
-                            self.impls.entry(did).default(vec![]).push(Impl {
+                            self.impls.entry(did).or_insert(vec![]).push(Impl {
                                 impl_: i,
                                 dox: dox,
                                 stability: item.stability.clone(),
@@ -1330,7 +1330,7 @@ fn build_sidebar_items(&self, m: &clean::Module) -> HashMap<String, Vec<NameDoc>
                 Some(ref s) => s.to_string(),
             };
             let short = short.to_string();
-            map.entry(short).default(vec![])
+            map.entry(short).or_insert(vec![])
                 .push((myname, Some(plain_summary_line(item.doc_value()))));
         }
 
index 4db5a262c2ccf36b171db74e28ced9708453421f..a85f770f63ca49fceaea83886ab68397ee181985 100644 (file)
@@ -352,7 +352,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
             }
         };
         let name = name.to_string();
-        externs.entry(name).default(vec![]).push(location.to_string());
+        externs.entry(name).or_insert(vec![]).push(location.to_string());
     }
     Ok(externs)
 }
index b3557529a668fcc0d1a58b2f45c208f3a802fad5..91225891338a58a42dc19542377103de57ff457f 100644 (file)
@@ -1489,7 +1489,8 @@ impl<'a, K, V> Entry<'a, K, V> {
     #[unstable(feature = "std_misc",
                reason = "will soon be replaced by or_insert")]
     #[deprecated(since = "1.0",
-                reason = "replaced with more ergonomic `default` and `default_with`")]
+                reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
+    /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
     pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
         match self {
             Occupied(entry) => Ok(entry.into_mut()),
@@ -1501,7 +1502,7 @@ pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the default if empty, and returns
     /// a mutable reference to the value in the entry.
-    pub fn default(self, default: V) -> &'a mut V {
+    pub fn or_insert(self, default: V) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default),
@@ -1512,7 +1513,7 @@ pub fn default(self, default: V) -> &'a mut V {
                reason = "matches entry v3 specification, waiting for dust to settle")]
     /// Ensures a value is in the entry by inserting the result of the default function if empty,
     /// and returns a mutable reference to the value in the entry.
-    pub fn default_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
+    pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
         match self {
             Occupied(entry) => entry.into_mut(),
             Vacant(entry) => entry.insert(default()),
index b51948c160b5503f03ba64ee026be5d7dc8866ef..0ac97b71298b85df6c737c6bec041bb512522544 100644 (file)
 //! let message = "she sells sea shells by the sea shore";
 //!
 //! for c in message.chars() {
-//!     *count.entry(c).default(0) += 1;
+//!     *count.entry(c).or_insert(0) += 1;
 //! }
 //!
 //! assert_eq!(count.get(&'s'), Some(&8));
 //! for id in orders.into_iter() {
 //!     // If this is the first time we've seen this customer, initialize them
 //!     // with no blood alcohol. Otherwise, just retrieve them.
-//!     let person = blood_alcohol.entry(id).default(Person{id: id, blood_alcohol: 0.0});
+//!     let person = blood_alcohol.entry(id).or_insert(Person{id: id, blood_alcohol: 0.0});
 //!
 //!     // Reduce their blood alcohol level. It takes time to order and drink a beer!
 //!     person.blood_alcohol *= 0.9;
index 2b811ce914f7e57952463421e2877270412cdb3d..a2023d6832efbce2fe48cf33ed7e85962fc9c431 100644 (file)
@@ -67,7 +67,7 @@ pub fn apply_mark(m: Mrk, ctxt: SyntaxContext) -> SyntaxContext {
 fn apply_mark_internal(m: Mrk, ctxt: SyntaxContext, table: &SCTable) -> SyntaxContext {
     let key = (ctxt, m);
     * table.mark_memo.borrow_mut().entry(key)
-        .default_with(|| idx_push(&mut *table.table.borrow_mut(), Mark(m, ctxt)))
+        .or_insert_with(|| idx_push(&mut *table.table.borrow_mut(), Mark(m, ctxt)))
 }
 
 /// Extend a syntax context with a given rename
@@ -84,7 +84,7 @@ fn apply_rename_internal(id: Ident,
     let key = (ctxt, id, to);
 
     * table.rename_memo.borrow_mut().entry(key)
-        .default_with(|| idx_push(&mut *table.table.borrow_mut(), Rename(id, to, ctxt)))
+        .or_insert_with(|| idx_push(&mut *table.table.borrow_mut(), Rename(id, to, ctxt)))
 }
 
 /// Apply a list of renamings to a context
index 9af7b9ab633116619c2e9ff3cc12b4ad28e5ad74..72498afa3201e7c9383c46edd05ca78ded6d5bb3 100644 (file)
@@ -35,7 +35,6 @@
 #![feature(quote, unsafe_destructor)]
 #![feature(rustc_private)]
 #![feature(staged_api)]
-#![feature(std_misc)]
 #![feature(unicode)]
 #![feature(path_ext)]
 #![feature(str_char)]