]> git.lizzy.rs Git - rust.git/commitdiff
Derive Default for ExternEntry
authorAaron Hill <aa1ronham@gmail.com>
Tue, 9 Apr 2019 21:24:24 +0000 (17:24 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sun, 14 Apr 2019 19:45:18 +0000 (15:45 -0400)
src/librustc/session/config.rs
src/librustc_typeck/lib.rs
src/librustdoc/config.rs

index 00dfe9aca3940fe0b39430a0eaacacb21f7c0f35..d3a734cbc6eadc8d8df3bf764f6bb2ae0891a3dd 100644 (file)
@@ -285,7 +285,7 @@ pub fn should_codegen(&self) -> bool {
 #[derive(Clone, Hash)]
 pub struct Externs(BTreeMap<String, ExternEntry>);
 
-#[derive(Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
+#[derive(Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug, Default)]
 pub struct ExternEntry {
     pub locations: BTreeSet<Option<String>>,
     pub is_private_dep: bool
@@ -2337,26 +2337,17 @@ pub fn build_session_options_and_crate_config(
             );
         };
 
-
-        externs
+        let entry = externs
             .entry(name.to_owned())
-            .and_modify(|e| {
-                e.locations.insert(location.clone());
-
-                // Crates start out being not private,
-                // and go to being private if we see an '--extern-private'
-                // flag
-                e.is_private_dep |= private;
-            })
-            .or_insert_with(|| {
-                let mut locations = BTreeSet::new();
-                locations.insert(location);
-
-                ExternEntry {
-                    locations: locations,
-                    is_private_dep: private
-                }
-            });
+            .or_default();
+
+
+        entry.locations.insert(location.clone());
+
+        // Crates start out being not private,
+        // and go to being private if we see an '--extern-private'
+        // flag
+        entry.is_private_dep |= private;
     }
 
     let crate_name = matches.opt_str("crate-name");
index 401d7457517e6373fad1351b2cd3e67a9750b452..21d1af229ddc2815a4536ed9499cff0adf4378e6 100644 (file)
@@ -176,7 +176,7 @@ fn require_same_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     })
 }
 
-pub fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) {
+fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) {
     let main_id = tcx.hir().as_local_hir_id(main_def_id).unwrap();
     let main_span = tcx.def_span(main_def_id);
     let main_t = tcx.type_of(main_def_id);
@@ -241,7 +241,7 @@ pub fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefI
     }
 }
 
-pub fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: DefId) {
+fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: DefId) {
     let start_id = tcx.hir().as_local_hir_id(start_def_id).unwrap();
     let start_span = tcx.def_span(start_def_id);
     let start_t = tcx.type_of(start_def_id);
@@ -298,7 +298,7 @@ pub fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: De
     }
 }
 
-pub fn check_for_entry_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
+fn check_for_entry_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
     match tcx.entry_fn(LOCAL_CRATE) {
         Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
         Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
index 8a669cad514b54f51e3cf608be463c664861487a..a4d2a3be863300aef1f5c7f1ca2e48cc403a4c15 100644 (file)
@@ -1,4 +1,4 @@
-use std::collections::{BTreeMap, BTreeSet};
+use std::collections::BTreeMap;
 use std::fmt;
 use std::path::PathBuf;
 
@@ -590,12 +590,8 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
         let name = name.to_string();
         // For Rustdoc purposes, we can treat all externs as public
         externs.entry(name)
-            .and_modify(|e| { e.locations.insert(location.clone()); } )
-            .or_insert_with(|| {
-                let mut locations = BTreeSet::new();
-                locations.insert(location);
-                ExternEntry { locations, is_private_dep: false }
-            });
+            .or_default()
+            .locations.insert(location.clone());
     }
     Ok(Externs::new(externs))
 }