Skip to content

Commit

Permalink
Derive Default for ExternEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Apr 14, 2019
1 parent 872c20d commit 4dfce34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
31 changes: 11 additions & 20 deletions src/librustc/session/config.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/lib.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 3 additions & 7 deletions src/librustdoc/config.rs
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;

Expand Down Expand Up @@ -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))
}

0 comments on commit 4dfce34

Please sign in to comment.