diff --git a/src/librustc/infer/lexical_region_resolve/graphviz.rs b/src/librustc/infer/lexical_region_resolve/graphviz.rs index 3b92d032bdc5a..a210d63f129e3 100644 --- a/src/librustc/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc/infer/lexical_region_resolve/graphviz.rs @@ -230,10 +230,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> { type Node = Node; type Edge = Edge<'tcx>; fn nodes(&self) -> dot::Nodes<'_, Node> { - let mut set = FxHashSet::default(); - for node in self.node_ids.keys() { - set.insert(*node); - } + let set = self.node_ids.keys().cloned().collect::>(); debug!("constraint graph has {} nodes", set.len()); set.into_iter().collect() } diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 8b5c6d147d781..e3f9c51a1235e 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -94,12 +94,11 @@ pub enum Linkage { pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let sess = &tcx.sess; - let mut fmts = FxHashMap::default(); - for &ty in sess.crate_types.borrow().iter() { + let fmts = sess.crate_types.borrow().iter().map(|&ty| { let linkage = calculate_type(tcx, ty); verify_ok(tcx, &linkage); - fmts.insert(ty, linkage); - } + (ty, linkage) + }).collect::>(); sess.abort_if_errors(); sess.dependency_formats.set(fmts); } diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index d6f7531855122..3dc31c517169f 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -174,10 +174,13 @@ impl<'sess> OnDiskCache<'sess> { tcx.dep_graph.with_ignore(|| { // Allocate SourceFileIndices let (file_to_file_index, file_index_to_stable_id) = { - let mut file_to_file_index = FxHashMap::default(); - let mut file_index_to_stable_id = FxHashMap::default(); + let files = tcx.sess.source_map().files(); + let mut file_to_file_index = FxHashMap::with_capacity_and_hasher( + files.len(), Default::default()); + let mut file_index_to_stable_id = FxHashMap::with_capacity_and_hasher( + files.len(), Default::default()); - for (index, file) in tcx.sess.source_map().files().iter().enumerate() { + for (index, file) in files.iter().enumerate() { let index = SourceFileIndex(index as u32); let file_ptr: *const SourceFile = &**file as *const _; file_to_file_index.insert(file_ptr, index); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7e25694d5598f..4851938653b53 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3510,10 +3510,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { _ => span_bug!(span, "non-ADT passed to check_expr_struct_fields") }; - let mut remaining_fields = FxHashMap::default(); - for (i, field) in variant.fields.iter().enumerate() { - remaining_fields.insert(field.ident.modern(), (i, field)); - } + let mut remaining_fields = variant.fields.iter().enumerate().map(|(i, field)| + (field.ident.modern(), (i, field)) + ).collect::>(); let mut seen_fields = FxHashMap::default(); @@ -5051,10 +5050,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // provided (if any) into their appropriate spaces. We'll also report // errors if type parameters are provided in an inappropriate place. - let mut generic_segs = FxHashSet::default(); - for PathSeg(_, index) in &path_segs { - generic_segs.insert(index); - } + let generic_segs = path_segs.iter().map(|PathSeg(_, index)| index) + .collect::>(); AstConv::prohibit_generics(self, segments.iter().enumerate().filter_map(|(index, seg)| { if !generic_segs.contains(&index) { Some(seg)