Derive Default for ExternEntry

This commit is contained in:
Aaron Hill 2019-04-09 17:24:24 -04:00
parent 872c20d415
commit 4dfce34912
No known key found for this signature in database
GPG key ID: B4087E510E98B164
3 changed files with 15 additions and 28 deletions

View file

@ -285,7 +285,7 @@ impl OutputTypes {
#[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());
.or_default();
// 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
}
});
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");

View 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),

View 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))
}