Skip to content

Commit eb15d2f

Browse files
committed
Derive Default for ExternEntry
1 parent 7d3eba3 commit eb15d2f

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

src/librustc/session/config.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl OutputTypes {
270270
#[derive(Clone, Hash)]
271271
pub struct Externs(BTreeMap<String, ExternEntry>);
272272

273-
#[derive(Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
273+
#[derive(Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug, Default)]
274274
pub struct ExternEntry {
275275
pub locations: BTreeSet<Option<String>>,
276276
pub is_private_dep: bool
@@ -2310,26 +2310,17 @@ pub fn build_session_options_and_crate_config(
23102310
);
23112311
};
23122312

2313-
2314-
externs
2313+
let entry = externs
23152314
.entry(name.to_owned())
2316-
.and_modify(|e| {
2317-
e.locations.insert(location.clone());
2318-
2319-
// Crates start out being not private,
2320-
// and go to being private if we see an '--extern-private'
2321-
// flag
2322-
e.is_private_dep |= private;
2323-
})
2324-
.or_insert_with(|| {
2325-
let mut locations = BTreeSet::new();
2326-
locations.insert(location);
2327-
2328-
ExternEntry {
2329-
locations: locations,
2330-
is_private_dep: private
2331-
}
2332-
});
2315+
.or_default();
2316+
2317+
2318+
entry.locations.insert(location.clone());
2319+
2320+
// Crates start out being not private,
2321+
// and go to being private if we see an '--extern-private'
2322+
// flag
2323+
entry.is_private_dep |= private;
23332324
}
23342325

23352326
let crate_name = matches.opt_str("crate-name");

src/librustc_typeck/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn require_same_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
176176
})
177177
}
178178

179-
pub fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) {
179+
fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) {
180180
let main_id = tcx.hir().as_local_hir_id(main_def_id).unwrap();
181181
let main_span = tcx.def_span(main_def_id);
182182
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
241241
}
242242
}
243243

244-
pub fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: DefId) {
244+
fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: DefId) {
245245
let start_id = tcx.hir().as_local_hir_id(start_def_id).unwrap();
246246
let start_span = tcx.def_span(start_def_id);
247247
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
298298
}
299299
}
300300

301-
pub fn check_for_entry_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
301+
fn check_for_entry_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
302302
match tcx.entry_fn(LOCAL_CRATE) {
303303
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
304304
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),

src/librustdoc/config.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::{BTreeMap, BTreeSet};
1+
use std::collections::BTreeMap;
22
use std::fmt;
33
use std::path::PathBuf;
44

@@ -590,12 +590,8 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
590590
let name = name.to_string();
591591
// For Rustdoc purposes, we can treat all externs as public
592592
externs.entry(name)
593-
.and_modify(|e| { e.locations.insert(location.clone()); } )
594-
.or_insert_with(|| {
595-
let mut locations = BTreeSet::new();
596-
locations.insert(location);
597-
ExternEntry { locations, is_private_dep: false }
598-
});
593+
.or_default()
594+
.locations.insert(location.clone());
599595
}
600596
Ok(Externs::new(externs))
601597
}

0 commit comments

Comments
 (0)