]> git.lizzy.rs Git - rust.git/commitdiff
Use the new Entry::or_default method where possible.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Sat, 21 Jul 2018 19:43:31 +0000 (22:43 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Sat, 18 Aug 2018 17:19:45 +0000 (20:19 +0300)
36 files changed:
src/bootstrap/sanity.rs
src/bootstrap/tool.rs
src/librustc/hir/lowering.rs
src/librustc/lint/mod.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/session/config.rs
src/librustc/traits/auto_trait.rs
src/librustc/traits/error_reporting.rs
src/librustc/traits/specialize/specialization_graph.rs
src/librustc/ty/context.rs
src/librustc/ty/inhabitedness/mod.rs
src/librustc/ty/trait_def.rs
src/librustc_borrowck/borrowck/unused.rs
src/librustc_borrowck/dataflow.rs
src/librustc_codegen_llvm/back/symbol_export.rs
src/librustc_codegen_llvm/base.rs
src/librustc_data_structures/graph/test.rs
src/librustc_metadata/encoder.rs
src/librustc_metadata/locator.rs
src/librustc_mir/borrow_check/borrow_set.rs
src/librustc_mir/dataflow/impls/borrows.rs
src/librustc_mir/monomorphize/partitioning.rs
src/librustc_mir/util/pretty.rs
src/librustc_resolve/check_unused.rs
src/librustc_resolve/lib.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/op.rs
src/librustc_typeck/coherence/inherent_impls.rs
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/simplify.rs
src/librustdoc/html/render.rs
src/librustdoc/lib.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/tt/macro_rules.rs
src/tools/tidy/src/deps.rs
src/tools/tidy/src/errors.rs

index c7f514da939a60639b7082ed5a8b7b64a2a80f0f..c2610de23bebadf6678a5c5bf7187b3311398dd2 100644 (file)
@@ -176,7 +176,7 @@ pub fn check(build: &mut Build) {
         if target.contains("-none-") {
             if build.no_std(*target).is_none() {
                 let target = build.config.target_config.entry(target.clone())
-                    .or_insert(Default::default());
+                    .or_default();
 
                 target.no_std = true;
             }
@@ -192,7 +192,7 @@ pub fn check(build: &mut Build) {
             // fall back to the system toolchain in /usr before giving up
             if build.musl_root(*target).is_none() && build.config.build == *target {
                 let target = build.config.target_config.entry(target.clone())
-                                 .or_insert(Default::default());
+                    .or_default();
                 target.musl_root = Some("/usr".into());
             }
             match build.musl_root(*target) {
index eaa316494477e73eb6ac8934fb22c6bd4c96a0c6..23ef031dcb703b094e09bceb0d9678283df5d51b 100644 (file)
@@ -183,7 +183,7 @@ fn run(self, builder: &Builder) -> Option<PathBuf> {
                 let mut artifacts = builder.tool_artifacts.borrow_mut();
                 let prev_artifacts = artifacts
                     .entry(target)
-                    .or_insert_with(Default::default);
+                    .or_default();
                 if let Some(prev) = prev_artifacts.get(&*id) {
                     if prev.1 != val.1 {
                         duplicates.push((
index 9ae5ab7f8be2e161631230486a3641c6d4e90608..09f76552279f7575ce21d688abbd5c946f462465 100644 (file)
@@ -2334,7 +2334,7 @@ fn lower_generics(
         // FIXME: This could probably be done with less rightward drift. Also looks like two control
         //        paths where report_error is called are also the only paths that advance to after
         //        the match statement, so the error reporting could probably just be moved there.
-        let mut add_bounds = NodeMap();
+        let mut add_bounds: NodeMap<Vec<_>> = NodeMap();
         for pred in &generics.where_clause.predicates {
             if let WherePredicate::BoundPredicate(ref bound_pred) = *pred {
                 'next_bound: for bound in &bound_pred.bounds {
@@ -2364,7 +2364,7 @@ fn lower_generics(
                                                 GenericParamKind::Type { .. } => {
                                                     if node_id == param.id {
                                                         add_bounds.entry(param.id)
-                                                            .or_insert(Vec::new())
+                                                            .or_default()
                                                             .push(bound.clone());
                                                         continue 'next_bound;
                                                     }
@@ -2730,7 +2730,7 @@ fn lower_item_kind(
 
                         if let Some(ref trait_ref) = trait_ref {
                             if let Def::Trait(def_id) = trait_ref.path.def {
-                                this.trait_impls.entry(def_id).or_insert(vec![]).push(id);
+                                this.trait_impls.entry(def_id).or_default().push(id);
                             }
                         }
 
index 231a70f873fdc833bb9f2a1163063f28db59e7de..c36d674566ad8549f0d2cff2d47d59cf290d1dbb 100644 (file)
@@ -512,7 +512,7 @@ pub fn add_lint(&mut self,
             msg: msg.to_string(),
             diagnostic
         };
-        let arr = self.map.entry(id).or_insert(Vec::new());
+        let arr = self.map.entry(id).or_default();
         if !arr.contains(&early_lint) {
             arr.push(early_lint);
         }
index f2d39a905ee5f496d4a33e1a4d2e1413015d6632..6ae027dac7e225ca0d67bb426f4dcd2f202a9bfb 100644 (file)
@@ -391,37 +391,33 @@ fn resolve_lifetimes<'tcx>(
 
     let named_region_map = krate(tcx);
 
-    let mut defs = FxHashMap();
+    let mut rl = ResolveLifetimes {
+        defs: FxHashMap(),
+        late_bound: FxHashMap(),
+        object_lifetime_defaults: FxHashMap(),
+    };
+
     for (k, v) in named_region_map.defs {
         let hir_id = tcx.hir.node_to_hir_id(k);
-        let map = defs.entry(hir_id.owner_local_def_id())
-            .or_insert_with(|| Lrc::new(FxHashMap()));
+        let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
         Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
     }
-    let mut late_bound = FxHashMap();
     for k in named_region_map.late_bound {
         let hir_id = tcx.hir.node_to_hir_id(k);
-        let map = late_bound
-            .entry(hir_id.owner_local_def_id())
-            .or_insert_with(|| Lrc::new(FxHashSet()));
+        let map = rl.late_bound.entry(hir_id.owner_local_def_id()).or_default();
         Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
     }
-    let mut object_lifetime_defaults = FxHashMap();
     for (k, v) in named_region_map.object_lifetime_defaults {
         let hir_id = tcx.hir.node_to_hir_id(k);
-        let map = object_lifetime_defaults
+        let map = rl.object_lifetime_defaults
             .entry(hir_id.owner_local_def_id())
-            .or_insert_with(|| Lrc::new(FxHashMap()));
+            .or_default();
         Lrc::get_mut(map)
             .unwrap()
             .insert(hir_id.local_id, Lrc::new(v));
     }
 
-    Lrc::new(ResolveLifetimes {
-        defs,
-        late_bound,
-        object_lifetime_defaults,
-    })
+    Lrc::new(rl)
 }
 
 fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
index ef1052d562e5584db33003e9672eb28d6f42bc9a..3926ebedd37199db8d8321d765f1c04397344e9e 100644 (file)
@@ -2174,7 +2174,7 @@ pub fn build_session_options_and_crate_config(
         );
     }
 
-    let mut externs = BTreeMap::new();
+    let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
     for arg in &matches.opt_strs("extern") {
         let mut parts = arg.splitn(2, '=');
         let name = match parts.next() {
@@ -2191,7 +2191,7 @@ pub fn build_session_options_and_crate_config(
 
         externs
             .entry(name.to_string())
-            .or_insert_with(BTreeSet::new)
+            .or_default()
             .insert(location.to_string());
     }
 
index 1ffe8157a0fb43a764ef0918940e325d36ffee6a..fd8c2d45e644a6f384db7f9e43c74a08a1b3f44d 100644 (file)
@@ -513,26 +513,26 @@ pub fn map_vid_to_region<'cx>(
                     {
                         let deps1 = vid_map
                             .entry(RegionTarget::RegionVid(r1))
-                            .or_insert_with(|| Default::default());
+                            .or_default();
                         deps1.larger.insert(RegionTarget::RegionVid(r2));
                     }
 
                     let deps2 = vid_map
                         .entry(RegionTarget::RegionVid(r2))
-                        .or_insert_with(|| Default::default());
+                        .or_default();
                     deps2.smaller.insert(RegionTarget::RegionVid(r1));
                 }
                 &Constraint::RegSubVar(region, vid) => {
                     {
                         let deps1 = vid_map
                             .entry(RegionTarget::Region(region))
-                            .or_insert_with(|| Default::default());
+                            .or_default();
                         deps1.larger.insert(RegionTarget::RegionVid(vid));
                     }
 
                     let deps2 = vid_map
                         .entry(RegionTarget::RegionVid(vid))
-                        .or_insert_with(|| Default::default());
+                        .or_default();
                     deps2.smaller.insert(RegionTarget::Region(region));
                 }
                 &Constraint::VarSubReg(vid, region) => {
@@ -542,13 +542,13 @@ pub fn map_vid_to_region<'cx>(
                     {
                         let deps1 = vid_map
                             .entry(RegionTarget::Region(r1))
-                            .or_insert_with(|| Default::default());
+                            .or_default();
                         deps1.larger.insert(RegionTarget::Region(r2));
                     }
 
                     let deps2 = vid_map
                         .entry(RegionTarget::Region(r2))
-                        .or_insert_with(|| Default::default());
+                        .or_default();
                     deps2.smaller.insert(RegionTarget::Region(r1));
                 }
             }
index 99b2f3e59feb66253d2f4bbffe67a5a6fc2af0bc..113adda3ccb298ecfc2e31dfe18482deb134a12f 100644 (file)
@@ -57,7 +57,7 @@ struct ErrorDescriptor<'tcx> {
             index: Option<usize>, // None if this is an old error
         }
 
-        let mut error_map : FxHashMap<_, _> =
+        let mut error_map : FxHashMap<_, Vec<_>> =
             self.reported_trait_errors.borrow().iter().map(|(&span, predicates)| {
                 (span, predicates.iter().map(|predicate| ErrorDescriptor {
                     predicate: predicate.clone(),
@@ -66,14 +66,14 @@ struct ErrorDescriptor<'tcx> {
             }).collect();
 
         for (index, error) in errors.iter().enumerate() {
-            error_map.entry(error.obligation.cause.span).or_insert(Vec::new()).push(
+            error_map.entry(error.obligation.cause.span).or_default().push(
                 ErrorDescriptor {
                     predicate: error.obligation.predicate.clone(),
                     index: Some(index)
                 });
 
             self.reported_trait_errors.borrow_mut()
-                .entry(error.obligation.cause.span).or_insert(Vec::new())
+                .entry(error.obligation.cause.span).or_default()
                 .push(error.obligation.predicate.clone());
         }
 
index f9c0581d3ca377223cb90a51e096c0c3426c1dd5..a7652574c1a2e9cb855f20234febb849be7c3d00 100644 (file)
@@ -49,7 +49,7 @@ pub struct Graph {
 
 /// Children of a given impl, grouped into blanket/non-blanket varieties as is
 /// done in `TraitDef`.
-#[derive(RustcEncodable, RustcDecodable)]
+#[derive(Default, RustcEncodable, RustcDecodable)]
 struct Children {
     // Impls of a trait (or specializations of a given impl). To allow for
     // quicker lookup, the impls are indexed by a simplified version of their
@@ -81,13 +81,6 @@ enum Inserted {
 }
 
 impl<'a, 'gcx, 'tcx> Children {
-    fn new() -> Children {
-        Children {
-            nonblanket_impls: FxHashMap(),
-            blanket_impls: vec![],
-        }
-    }
-
     /// Insert an impl into this set of children without comparing to any existing impls
     fn insert_blindly(&mut self,
                       tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -95,7 +88,7 @@ fn insert_blindly(&mut self,
         let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
         if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) {
             debug!("insert_blindly: impl_def_id={:?} sty={:?}", impl_def_id, sty);
-            self.nonblanket_impls.entry(sty).or_insert(vec![]).push(impl_def_id)
+            self.nonblanket_impls.entry(sty).or_default().push(impl_def_id)
         } else {
             debug!("insert_blindly: impl_def_id={:?} sty=None", impl_def_id);
             self.blanket_impls.push(impl_def_id)
@@ -230,7 +223,7 @@ fn iter(&mut self) -> Box<dyn Iterator<Item = DefId> + '_> {
     }
 
     fn filtered(&mut self, sty: SimplifiedType) -> Box<dyn Iterator<Item = DefId> + '_> {
-        let nonblanket = self.nonblanket_impls.entry(sty).or_insert(vec![]).iter();
+        let nonblanket = self.nonblanket_impls.entry(sty).or_default().iter();
         Box::new(self.blanket_impls.iter().chain(nonblanket).cloned())
     }
 }
@@ -268,7 +261,7 @@ pub fn insert(&mut self,
                    trait_ref, impl_def_id, trait_def_id);
 
             self.parent.insert(impl_def_id, trait_def_id);
-            self.children.entry(trait_def_id).or_insert(Children::new())
+            self.children.entry(trait_def_id).or_default()
                 .insert_blindly(tcx, impl_def_id);
             return Ok(None);
         }
@@ -281,7 +274,7 @@ pub fn insert(&mut self,
         loop {
             use self::Inserted::*;
 
-            let insert_result = self.children.entry(parent).or_insert(Children::new())
+            let insert_result = self.children.entry(parent).or_default()
                 .insert(tcx, impl_def_id, simplified)?;
 
             match insert_result {
@@ -318,9 +311,8 @@ pub fn insert(&mut self,
                     self.parent.insert(impl_def_id, parent);
 
                     // Add G as N's child.
-                    let mut grand_children = Children::new();
-                    grand_children.insert_blindly(tcx, grand_child_to_be);
-                    self.children.insert(impl_def_id, grand_children);
+                    self.children.entry(impl_def_id).or_default()
+                        .insert_blindly(tcx, grand_child_to_be);
                     break;
                 }
                 ShouldRecurseOn(new_parent) => {
@@ -343,7 +335,7 @@ pub fn record_impl_from_cstore(&mut self,
                   was already present.");
         }
 
-        self.children.entry(parent).or_insert(Children::new()).insert_blindly(tcx, child);
+        self.children.entry(parent).or_default().insert_blindly(tcx, child);
     }
 
     /// The parent of a given impl, which is the def id of the trait when the
index bb14af29a7afe4d71bf4d6747c57296cc2d9c088..42948a3f5f18ee16878d5cab07e4434bbb676ab3 100644 (file)
@@ -1132,11 +1132,10 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
             None
         };
 
-        let mut trait_map = FxHashMap();
+        let mut trait_map: FxHashMap<_, Lrc<FxHashMap<_, _>>> = FxHashMap();
         for (k, v) in resolutions.trait_map {
             let hir_id = hir.node_to_hir_id(k);
-            let map = trait_map.entry(hir_id.owner)
-                .or_insert_with(|| Lrc::new(FxHashMap()));
+            let map = trait_map.entry(hir_id.owner).or_default();
             Lrc::get_mut(map).unwrap()
                             .insert(hir_id.local_id,
                                     Lrc::new(StableVec::new(v)));
index 19e5406cd0d0a0aadf1d14224914d7280cac8dcb..0ace44dca77b40f0f996fcf2c9345e21bc9ff369 100644 (file)
@@ -228,7 +228,7 @@ fn uninhabited_from(
         match self.sty {
             TyAdt(def, substs) => {
                 {
-                    let substs_set = visited.entry(def.did).or_insert(FxHashSet::default());
+                    let substs_set = visited.entry(def.did).or_default();
                     if !substs_set.insert(substs) {
                         // We are already calculating the inhabitedness of this type.
                         // The type must contain a reference to itself. Break the
index 32f0d3384c4dcea44d47bb5cd3086369b851dfcd..6332080a1836c427f8308a5a0843c6cd288de1d2 100644 (file)
@@ -41,6 +41,7 @@ pub struct TraitDef {
     pub def_path_hash: DefPathHash,
 }
 
+#[derive(Default)]
 pub struct TraitImpls {
     blanket_impls: Vec<DefId>,
     /// Impls indexed by their simplified self-type, for fast lookup.
@@ -143,47 +144,43 @@ pub fn for_each_relevant_impl<F: FnMut(DefId)>(self,
 pub(super) fn trait_impls_of_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                                 trait_id: DefId)
                                                 -> Lrc<TraitImpls> {
-    let mut remote_impls = Vec::new();
-
-    // Traits defined in the current crate can't have impls in upstream
-    // crates, so we don't bother querying the cstore.
-    if !trait_id.is_local() {
-        for &cnum in tcx.crates().iter() {
-            let impls = tcx.implementations_of_trait((cnum, trait_id));
-            remote_impls.extend(impls.iter().cloned());
-        }
-    }
-
-    let mut blanket_impls = Vec::new();
-    let mut non_blanket_impls = FxHashMap();
+    let mut impls = TraitImpls::default();
 
-    let local_impls = tcx.hir
-                         .trait_impls(trait_id)
-                         .into_iter()
-                         .map(|&node_id| tcx.hir.local_def_id(node_id));
+    {
+        let mut add_impl = |impl_def_id| {
+            let impl_self_ty = tcx.type_of(impl_def_id);
+            if impl_def_id.is_local() && impl_self_ty.references_error() {
+                return;
+            }
 
-     for impl_def_id in local_impls.chain(remote_impls.into_iter()) {
-        let impl_self_ty = tcx.type_of(impl_def_id);
-        if impl_def_id.is_local() && impl_self_ty.references_error() {
-            continue
+            if let Some(simplified_self_ty) =
+                fast_reject::simplify_type(tcx, impl_self_ty, false)
+            {
+                impls.non_blanket_impls
+                    .entry(simplified_self_ty)
+                    .or_default()
+                    .push(impl_def_id);
+            } else {
+                impls.blanket_impls.push(impl_def_id);
+            }
+        };
+
+        // Traits defined in the current crate can't have impls in upstream
+        // crates, so we don't bother querying the cstore.
+        if !trait_id.is_local() {
+            for &cnum in tcx.crates().iter() {
+                for &def_id in tcx.implementations_of_trait((cnum, trait_id)).iter() {
+                    add_impl(def_id);
+                }
+            }
         }
 
-        if let Some(simplified_self_ty) =
-            fast_reject::simplify_type(tcx, impl_self_ty, false)
-        {
-            non_blanket_impls
-                .entry(simplified_self_ty)
-                .or_insert(vec![])
-                .push(impl_def_id);
-        } else {
-            blanket_impls.push(impl_def_id);
+        for &node_id in tcx.hir.trait_impls(trait_id) {
+            add_impl(tcx.hir.local_def_id(node_id));
         }
     }
 
-    Lrc::new(TraitImpls {
-        blanket_impls: blanket_impls,
-        non_blanket_impls: non_blanket_impls,
-    })
+    Lrc::new(impls)
 }
 
 impl<'a> HashStable<StableHashingContext<'a>> for TraitImpls {
index 475ff0b744349abfb01cd4ef6f959705fe0f864f..88545c12415c69319a3bec1c393239b8ad1f6268 100644 (file)
@@ -44,7 +44,7 @@ struct UnusedMutCx<'a, 'tcx: 'a> {
 impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
     fn check_unused_mut_pat(&self, pats: &[P<hir::Pat>]) {
         let tcx = self.bccx.tcx;
-        let mut mutables = FxHashMap();
+        let mut mutables: FxHashMap<_, Vec<_>> = FxHashMap();
         for p in pats {
             p.each_binding(|_, hir_id, span, ident| {
                 // Skip anything that looks like `_foo`
@@ -60,7 +60,7 @@ fn check_unused_mut_pat(&self, pats: &[P<hir::Pat>]) {
                         _ => return,
                     }
 
-                    mutables.entry(ident.name).or_insert(Vec::new()).push((hir_id, span));
+                    mutables.entry(ident.name).or_default().push((hir_id, span));
                 } else {
                     tcx.sess.delay_span_bug(span, "missing binding mode");
                 }
index d5f30c1dcd42da8d4f7ec94a03ebee820765f8e2..75dee2b78fddb1c24ce1070f080e044616f208f1 100644 (file)
@@ -181,7 +181,7 @@ fn build_local_id_to_index(body: Option<&hir::Body>,
 
     cfg.graph.each_node(|node_idx, node| {
         if let cfg::CFGNodeData::AST(id) = node.data {
-            index.entry(id).or_insert(vec![]).push(node_idx);
+            index.entry(id).or_default().push(node_idx);
         }
         true
     });
@@ -209,7 +209,7 @@ fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'thi
             }
 
             fn visit_pat(&mut self, p: &hir::Pat) {
-                self.index.entry(p.hir_id.local_id).or_insert(vec![]).push(self.entry);
+                self.index.entry(p.hir_id.local_id).or_default().push(self.entry);
                 intravisit::walk_pat(self, p)
             }
         }
index c78d061a39badc0c8ca9e69585a5db3c8b849607..edb1da0b5582ee9306fbf394072f01c0f0703872 100644 (file)
@@ -299,7 +299,7 @@ fn upstream_monomorphizations_provider<'a, 'tcx>(
 
     let cnums = tcx.all_crate_nums(LOCAL_CRATE);
 
-    let mut instances = DefIdMap();
+    let mut instances: DefIdMap<FxHashMap<_, _>> = DefIdMap();
 
     let cnum_stable_ids: IndexVec<CrateNum, Fingerprint> = {
         let mut cnum_stable_ids = IndexVec::from_elem_n(Fingerprint::ZERO,
@@ -318,8 +318,7 @@ fn upstream_monomorphizations_provider<'a, 'tcx>(
     for &cnum in cnums.iter() {
         for &(ref exported_symbol, _) in tcx.exported_symbols(cnum).iter() {
             if let &ExportedSymbol::Generic(def_id, substs) = exported_symbol {
-                let substs_map = instances.entry(def_id)
-                                          .or_insert_with(|| FxHashMap());
+                let substs_map = instances.entry(def_id).or_default();
 
                 match substs_map.entry(substs) {
                     Occupied(mut e) => {
index bd0c62e4766aed81588e0a0cdef2a048e7cbb337..0330a0598268ce842c4076c5b92fa83e6c8a3c8d 100644 (file)
@@ -1020,12 +1020,12 @@ fn collect_and_partition_mono_items<'a, 'tcx>(
     }).collect();
 
     if tcx.sess.opts.debugging_opts.print_mono_items.is_some() {
-        let mut item_to_cgus = FxHashMap();
+        let mut item_to_cgus: FxHashMap<_, Vec<_>> = FxHashMap();
 
         for cgu in &codegen_units {
             for (&mono_item, &linkage) in cgu.items() {
                 item_to_cgus.entry(mono_item)
-                            .or_insert(Vec::new())
+                            .or_default()
                             .push((cgu.name().clone(), linkage));
             }
         }
index 48b654726b8f262e2a27d67f4f8b04e36dfd6958..b72d011c99bad9ea84a98c35e9f368c29d888799 100644 (file)
@@ -33,12 +33,12 @@ pub fn new(start_node: usize, edges: &[(usize, usize)]) -> Self {
         for &(source, target) in edges {
             graph.num_nodes = max(graph.num_nodes, source + 1);
             graph.num_nodes = max(graph.num_nodes, target + 1);
-            graph.successors.entry(source).or_insert(vec![]).push(target);
-            graph.predecessors.entry(target).or_insert(vec![]).push(source);
+            graph.successors.entry(source).or_default().push(target);
+            graph.predecessors.entry(target).or_default().push(source);
         }
         for node in 0..graph.num_nodes {
-            graph.successors.entry(node).or_insert(vec![]);
-            graph.predecessors.entry(node).or_insert(vec![]);
+            graph.successors.entry(node).or_default();
+            graph.predecessors.entry(node).or_default();
         }
         graph
     }
index 7c445cb715e7cd4d8ed8da3239a52766a67246c9..02a41e68f68cb15a353e228ddc17a2eeb030d363 100644 (file)
@@ -1788,7 +1788,7 @@ fn visit_item(&mut self, item: &hir::Item) {
             if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) {
                 self.impls
                     .entry(trait_ref.def_id)
-                    .or_insert(vec![])
+                    .or_default()
                     .push(impl_id.index);
             }
         }
index 52777e5f6b90df7452eabe701565dcdcae660e83..f78a19403acf8b06cf2ae638cf63c12d1bcc152b 100644 (file)
@@ -451,7 +451,10 @@ fn find_library_crate(&mut self,
         let rlib_prefix = format!("lib{}{}", self.crate_name, extra_prefix);
         let staticlib_prefix = format!("{}{}{}", staticpair.0, self.crate_name, extra_prefix);
 
-        let mut candidates = FxHashMap();
+        let mut candidates: FxHashMap<
+            _,
+            (FxHashMap<_, _>, FxHashMap<_, _>, FxHashMap<_, _>),
+        > = FxHashMap();
         let mut staticlibs = vec![];
 
         // First, find all possible candidate rlibs and dylibs purely based on
@@ -493,8 +496,7 @@ fn find_library_crate(&mut self,
             info!("lib candidate: {}", path.display());
 
             let hash_str = hash.to_string();
-            let slot = candidates.entry(hash_str)
-                .or_insert_with(|| (FxHashMap(), FxHashMap(), FxHashMap()));
+            let slot = candidates.entry(hash_str).or_default();
             let (ref mut rlibs, ref mut rmetas, ref mut dylibs) = *slot;
             fs::canonicalize(path)
                 .map(|p| {
index 2e0cbf4326bc1e03acce2e5b14d67ddae1dd971f..454f89e5d06fccbbd24e20e9fc9a4318f44058b9 100644 (file)
@@ -248,7 +248,7 @@ fn visit_place(
 
                             self.activation_map
                                 .entry(location)
-                                .or_insert(Vec::new())
+                                .or_default()
                                 .push(borrow_index);
                             TwoPhaseActivation::ActivatedAt(location)
                         }
index b0c4d37814e8b02b84118cfb0edf36e8a21f5b78..8f3595b17848cbacafe184635e66a6343f6e8491 100644 (file)
@@ -80,7 +80,7 @@ fn precompute_borrows_out_of_scope<'tcx>(
             debug!("borrow {:?} gets killed at {:?}", borrow_index, location);
             borrows_out_of_scope_at_location
                 .entry(location)
-                .or_insert(vec![])
+                .or_default()
                 .push(borrow_index);
             continue;
         }
index 73d5d1d0948bfab6a27b8f3639b98e158bd8d27a..7d7be69b35559915fe3456df1978a181e3ff3f51 100644 (file)
@@ -696,7 +696,7 @@ fn internalize_symbols<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
     inlining_map.iter_accesses(|accessor, accessees| {
         for accessee in accessees {
             accessor_map.entry(*accessee)
-                        .or_insert(Vec::new())
+                        .or_default()
                         .push(accessor);
         }
     });
index 4bb74c60974505890bc9f02ad5ad24ad5f93db49..01ad85cf66830e28764f9011098198b34ecf1ef3 100644 (file)
@@ -528,7 +528,7 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>(
         if let Some(parent) = scope_data.parent_scope {
             scope_tree
                 .entry(parent)
-                .or_insert(vec![])
+                .or_default()
                 .push(SourceScope::new(index));
         } else {
             // Only the argument scope has no parent, because it's the root.
index 77005a83e42c3113a6629002efda842c71ef7f04..cafacf99c3d0d495b39fccaeb39cd3450ecded30 100644 (file)
@@ -65,7 +65,7 @@ fn check_import(&mut self, item_id: ast::NodeId, id: ast::NodeId, span: Span) {
                 // Check later.
                 return;
             }
-            self.unused_imports.entry(item_id).or_insert_with(NodeMap).insert(id, span);
+            self.unused_imports.entry(item_id).or_default().insert(id, span);
         } else {
             // This trait import is definitely used, in a way other than
             // method resolution.
@@ -112,7 +112,7 @@ fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: ast::NodeId, nested
             if items.len() == 0 {
                 self.unused_imports
                     .entry(self.base_id)
-                    .or_insert_with(NodeMap)
+                    .or_default()
                     .insert(id, span);
             }
         } else {
index bc8ee2a8adb0b0dd346876064174781d7edbb0e1..4b2a96be4ddcb7f0b61e082c03a9ff7acbf017f3 100644 (file)
@@ -1819,7 +1819,7 @@ fn record_use(&mut self, ident: Ident, ns: Namespace, binding: &'a NameBinding<'
 
     fn add_to_glob_map(&mut self, id: NodeId, ident: Ident) {
         if self.make_glob_map {
-            self.glob_map.entry(id).or_insert_with(FxHashSet).insert(ident.name);
+            self.glob_map.entry(id).or_default().insert(ident.name);
         }
     }
 
@@ -3703,14 +3703,14 @@ fn adjust_local_def(&mut self,
 
                             let seen = self.freevars_seen
                                            .entry(function_id)
-                                           .or_insert_with(|| NodeMap());
+                                           .or_default();
                             if let Some(&index) = seen.get(&node_id) {
                                 def = Def::Upvar(node_id, index, function_id);
                                 continue;
                             }
                             let vec = self.freevars
                                           .entry(function_id)
-                                          .or_insert_with(|| vec![]);
+                                          .or_default();
                             let depth = vec.len();
                             def = Def::Upvar(node_id, depth, function_id);
 
index 4fac11189a40004951629cd2c9e344247a677344..189859aad07e296e06cedbbfa11f27b35db189c0 100644 (file)
@@ -2005,7 +2005,7 @@ fn record_deferred_call_resolution(&self,
                                        closure_def_id: DefId,
                                        r: DeferredCallResolution<'gcx, 'tcx>) {
         let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
-        deferred_call_resolutions.entry(closure_def_id).or_insert(vec![]).push(r);
+        deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
     }
 
     fn remove_deferred_call_resolutions(&self,
index cdf2b6ae4473678a07415f01a2335fbc3068d4b8..3adcd638a62f18f744dde1b39ca3c052f3ba942c 100644 (file)
@@ -242,7 +242,7 @@ fn check_overloaded_binop(&self,
                             .borrow_mut()
                             .adjustments_mut()
                             .entry(rhs_expr.hir_id)
-                            .or_insert(vec![])
+                            .or_default()
                             .push(autoref);
                     }
                 }
index 02a18fa47dff16fce4f66e35d574381b64a6a9e2..f37167d1f6688cb2ab0b31e959fffa249bffd9c6 100644 (file)
@@ -304,7 +304,7 @@ fn check_def_id(&mut self, item: &hir::Item, def_id: DefId) {
             let impl_def_id = self.tcx.hir.local_def_id(item.id);
             let mut rc_vec = self.impls_map.inherent_impls
                                            .entry(def_id)
-                                           .or_insert_with(|| Lrc::new(vec![]));
+                                           .or_default();
 
             // At this point, there should not be any clones of the
             // `Lrc`, so we can still safely push into it in place:
index 5fd0b88870736c0d82d0a265458d1a0d7deec4ad..1331bd5186f19ba5dee8a70cc9c53edecbe26070 100644 (file)
@@ -267,7 +267,7 @@ fn handle_lifetimes<'cx>(
         // all intermediate RegionVids. At the end, all constraints should
         // be between Regions (aka region variables). This gives us the information
         // we need to create the Generics.
-        let mut finished = FxHashMap();
+        let mut finished: FxHashMap<_, Vec<_>> = FxHashMap();
 
         let mut vid_map: FxHashMap<RegionTarget, RegionDeps> = FxHashMap();
 
@@ -281,25 +281,25 @@ fn handle_lifetimes<'cx>(
                     {
                         let deps1 = vid_map
                             .entry(RegionTarget::RegionVid(r1))
-                            .or_insert_with(|| Default::default());
+                            .or_default();
                         deps1.larger.insert(RegionTarget::RegionVid(r2));
                     }
 
                     let deps2 = vid_map
                         .entry(RegionTarget::RegionVid(r2))
-                        .or_insert_with(|| Default::default());
+                        .or_default();
                     deps2.smaller.insert(RegionTarget::RegionVid(r1));
                 }
                 &Constraint::RegSubVar(region, vid) => {
                     let deps = vid_map
                         .entry(RegionTarget::RegionVid(vid))
-                        .or_insert_with(|| Default::default());
+                        .or_default();
                     deps.smaller.insert(RegionTarget::Region(region));
                 }
                 &Constraint::VarSubReg(vid, region) => {
                     let deps = vid_map
                         .entry(RegionTarget::RegionVid(vid))
-                        .or_insert_with(|| Default::default());
+                        .or_default();
                     deps.larger.insert(RegionTarget::Region(region));
                 }
                 &Constraint::RegSubReg(r1, r2) => {
@@ -308,7 +308,7 @@ fn handle_lifetimes<'cx>(
                     if self.region_name(r1) != self.region_name(r2) {
                         finished
                             .entry(self.region_name(r2).expect("no region_name found"))
-                            .or_insert_with(|| Vec::new())
+                            .or_default()
                             .push(r1);
                     }
                 }
@@ -343,7 +343,7 @@ fn handle_lifetimes<'cx>(
                             if self.region_name(r1) != self.region_name(r2) {
                                 finished
                                     .entry(self.region_name(r2).expect("no region name found"))
-                                    .or_insert_with(|| Vec::new())
+                                    .or_default()
                                     .push(r1) // Larger, smaller
                             }
                         }
@@ -577,8 +577,8 @@ fn param_env_to_generics<'b, 'c, 'cx>(
         } = full_generics.clean(self.cx);
 
         let mut has_sized = FxHashSet();
-        let mut ty_to_bounds = FxHashMap();
-        let mut lifetime_to_bounds = FxHashMap();
+        let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = FxHashMap();
+        let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = FxHashMap();
         let mut ty_to_traits: FxHashMap<Type, FxHashSet<Type>> = FxHashMap();
 
         let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = FxHashMap();
@@ -647,11 +647,11 @@ fn param_env_to_generics<'b, 'c, 'cx>(
 
                             ty_to_bounds
                                 .entry(ty.clone())
-                                .or_insert_with(|| FxHashSet());
+                                .or_default();
                         } else {
                             ty_to_bounds
                                 .entry(ty.clone())
-                                .or_insert_with(|| FxHashSet())
+                                .or_default()
                                 .insert(b.clone());
                         }
                     }
@@ -659,7 +659,7 @@ fn param_env_to_generics<'b, 'c, 'cx>(
                 WherePredicate::RegionPredicate { lifetime, bounds } => {
                     lifetime_to_bounds
                         .entry(lifetime)
-                        .or_insert_with(|| FxHashSet())
+                        .or_default()
                         .extend(bounds);
                 }
                 WherePredicate::EqPredicate { lhs, rhs } => {
@@ -722,7 +722,7 @@ fn param_env_to_generics<'b, 'c, 'cx>(
 
                                     let bounds = ty_to_bounds
                                         .entry(*ty.clone())
-                                        .or_insert_with(|| FxHashSet());
+                                        .or_default();
 
                                     bounds.insert(GenericBound::TraitBound(
                                         PolyTrait {
@@ -752,7 +752,7 @@ fn param_env_to_generics<'b, 'c, 'cx>(
                                     // loop
                                     ty_to_traits
                                         .entry(*ty.clone())
-                                        .or_insert_with(|| FxHashSet())
+                                        .or_default()
                                         .insert(*trait_.clone());
                                 }
                                 _ => panic!("Unexpected trait {:?} for {:?}", trait_, did),
index 9ea8bc536352a2d61d8458f7ec4cca7e042a811d..e938d2d0a16526353208a31dad59163cc40d44a3 100644 (file)
@@ -34,7 +34,7 @@
 
 pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
     // First, partition the where clause into its separate components
-    let mut params = BTreeMap::new();
+    let mut params: BTreeMap<_, Vec<_>> = BTreeMap::new();
     let mut lifetimes = Vec::new();
     let mut equalities = Vec::new();
     let mut tybounds = Vec::new();
@@ -43,7 +43,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
         match clause {
             WP::BoundPredicate { ty, bounds } => {
                 match ty {
-                    clean::Generic(s) => params.entry(s).or_insert(Vec::new())
+                    clean::Generic(s) => params.entry(s).or_default()
                                                .extend(bounds),
                     t => tybounds.push((t, ty_bounds(bounds))),
                 }
index 470aa2c10e977898f31b54d6c95d3c17c68dc33c..33b3934e3a447d87ca5e9fb896c619035bac5c12 100644 (file)
@@ -1245,7 +1245,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
         // Collect all the implementors of traits.
         if let clean::ImplItem(ref i) = item.inner {
             if let Some(did) = i.trait_.def_id() {
-                self.implementors.entry(did).or_insert(vec![]).push(Impl {
+                self.implementors.entry(did).or_default().push(Impl {
                     impl_item: item.clone(),
                 });
             }
@@ -1440,7 +1440,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                     unreachable!()
                 };
                 for did in dids {
-                    self.impls.entry(did).or_insert(vec![]).push(Impl {
+                    self.impls.entry(did).or_default().push(Impl {
                         impl_item: item.clone(),
                     });
                 }
@@ -1971,7 +1971,7 @@ fn item<F>(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result
 
     fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
         // BTreeMap instead of HashMap to get a sorted output
-        let mut map = BTreeMap::new();
+        let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
         for item in &m.items {
             if item.is_stripped() { continue }
 
@@ -1981,7 +1981,7 @@ fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc
                 Some(ref s) => s.to_string(),
             };
             let short = short.to_string();
-            map.entry(short).or_insert(vec![])
+            map.entry(short).or_default()
                 .push((myname, Some(plain_summary_line(item.doc_value()))));
         }
 
index 7581965cc0cadc49c6d8a860f2f23c637b711d49..a8ae6a94d5c4d329ebac5199dc239e346afd6cca 100644 (file)
@@ -599,7 +599,7 @@ fn acquire_input<R, F>(input: PathBuf,
 /// returns a map mapping crate names to their paths or else an
 /// error message.
 fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
-    let mut externs = BTreeMap::new();
+    let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
     for arg in &matches.opt_strs("extern") {
         let mut parts = arg.splitn(2, '=');
         let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
@@ -607,7 +607,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
                                  .ok_or("--extern value must be of the format `foo=bar`"
                                     .to_string())?;
         let name = name.to_string();
-        externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
+        externs.entry(name).or_default().insert(location.to_string());
     }
     Ok(Externs::new(externs))
 }
index 90b46268045e7df77c021a30f06de5aa8a4a2d69..ffa2730d68678f36550172d993bce876d85042d9 100644 (file)
@@ -327,7 +327,7 @@ fn expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment {
         // Unresolved macros produce dummy outputs as a recovery measure.
         invocations.reverse();
         let mut expanded_fragments = Vec::new();
-        let mut derives = HashMap::new();
+        let mut derives: HashMap<Mark, Vec<_>> = HashMap::new();
         let mut undetermined_invocations = Vec::new();
         let (mut progress, mut force) = (false, !self.monotonic);
         loop {
@@ -388,7 +388,7 @@ fn expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment {
                         .map_attrs(|mut attrs| { attrs.retain(|a| a.path != "derive"); attrs });
                     let item_with_markers =
                         add_derived_markers(&mut self.cx, item.span(), &traits, item.clone());
-                    let derives = derives.entry(invoc.expansion_data.mark).or_insert_with(Vec::new);
+                    let derives = derives.entry(invoc.expansion_data.mark).or_default();
 
                     for path in &traits {
                         let mark = Mark::fresh(self.cx.current_expansion.mark);
index f51d079a6c058fca39408024557156c80a6634b0..770561fe3269a3d8228ad9f7167cf566614db4fc 100644 (file)
@@ -88,8 +88,7 @@ fn expand<'cx>(&self,
 
 fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
     let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
-    let values: &mut Vec<String> = cx.expansions.entry(sp).or_insert_with(Vec::new);
-    values.push(message);
+    cx.expansions.entry(sp).or_default().push(message);
 }
 
 /// Given `lhses` and `rhses`, this is the new macro we create
index d63f479f29d9467c67f0fbb798960b771f4aab78..03bcda513fd8494ed60e599c468a6b55410175e4 100644 (file)
@@ -355,10 +355,10 @@ fn check_crate_duplicate(resolve: &Resolve, bad: &mut bool) {
         // "cargo", // FIXME(#53005)
         "rustc-ap-syntax",
     ];
-    let mut name_to_id = HashMap::new();
+    let mut name_to_id: HashMap<_, Vec<_>> = HashMap::new();
     for node in resolve.nodes.iter() {
         name_to_id.entry(node.id.split_whitespace().next().unwrap())
-            .or_insert(Vec::new())
+            .or_default()
             .push(&node.id);
     }
 
index 5bf7c894cda66ecbc2e361d5549c31f787966c3e..3dccffddf938872e682ed63b426fc1182991e1bd 100644 (file)
@@ -20,7 +20,7 @@
 
 pub fn check(path: &Path, bad: &mut bool) {
     let mut contents = String::new();
-    let mut map = HashMap::new();
+    let mut map: HashMap<_, Vec<_>> = HashMap::new();
     super::walk(path,
                 &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
                 &mut |file| {
@@ -61,7 +61,7 @@ pub fn check(path: &Path, bad: &mut bool) {
                     Ok(n) => n,
                     Err(..) => continue,
                 };
-                map.entry(code).or_insert(Vec::new())
+                map.entry(code).or_default()
                    .push((file.to_owned(), num + 1, line.to_owned()));
                 break
             }