if target.contains("-none-") {
if build.no_std(*target).is_none() {
let target = build.config.target_config.entry(target.clone())
- .or_insert(Default::default());
+ .or_default();
target.no_std = true;
}
// fall back to the system toolchain in /usr before giving up
if build.musl_root(*target).is_none() && build.config.build == *target {
let target = build.config.target_config.entry(target.clone())
- .or_insert(Default::default());
+ .or_default();
target.musl_root = Some("/usr".into());
}
match build.musl_root(*target) {
let mut artifacts = builder.tool_artifacts.borrow_mut();
let prev_artifacts = artifacts
.entry(target)
- .or_insert_with(Default::default);
+ .or_default();
if let Some(prev) = prev_artifacts.get(&*id) {
if prev.1 != val.1 {
duplicates.push((
// FIXME: This could probably be done with less rightward drift. Also looks like two control
// paths where report_error is called are also the only paths that advance to after
// the match statement, so the error reporting could probably just be moved there.
- let mut add_bounds = NodeMap();
+ let mut add_bounds: NodeMap<Vec<_>> = NodeMap();
for pred in &generics.where_clause.predicates {
if let WherePredicate::BoundPredicate(ref bound_pred) = *pred {
'next_bound: for bound in &bound_pred.bounds {
GenericParamKind::Type { .. } => {
if node_id == param.id {
add_bounds.entry(param.id)
- .or_insert(Vec::new())
+ .or_default()
.push(bound.clone());
continue 'next_bound;
}
if let Some(ref trait_ref) = trait_ref {
if let Def::Trait(def_id) = trait_ref.path.def {
- this.trait_impls.entry(def_id).or_insert(vec![]).push(id);
+ this.trait_impls.entry(def_id).or_default().push(id);
}
}
msg: msg.to_string(),
diagnostic
};
- let arr = self.map.entry(id).or_insert(Vec::new());
+ let arr = self.map.entry(id).or_default();
if !arr.contains(&early_lint) {
arr.push(early_lint);
}
let named_region_map = krate(tcx);
- let mut defs = FxHashMap();
+ let mut rl = ResolveLifetimes {
+ defs: FxHashMap(),
+ late_bound: FxHashMap(),
+ object_lifetime_defaults: FxHashMap(),
+ };
+
for (k, v) in named_region_map.defs {
let hir_id = tcx.hir.node_to_hir_id(k);
- let map = defs.entry(hir_id.owner_local_def_id())
- .or_insert_with(|| Lrc::new(FxHashMap()));
+ let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
}
- let mut late_bound = FxHashMap();
for k in named_region_map.late_bound {
let hir_id = tcx.hir.node_to_hir_id(k);
- let map = late_bound
- .entry(hir_id.owner_local_def_id())
- .or_insert_with(|| Lrc::new(FxHashSet()));
+ let map = rl.late_bound.entry(hir_id.owner_local_def_id()).or_default();
Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
}
- let mut object_lifetime_defaults = FxHashMap();
for (k, v) in named_region_map.object_lifetime_defaults {
let hir_id = tcx.hir.node_to_hir_id(k);
- let map = object_lifetime_defaults
+ let map = rl.object_lifetime_defaults
.entry(hir_id.owner_local_def_id())
- .or_insert_with(|| Lrc::new(FxHashMap()));
+ .or_default();
Lrc::get_mut(map)
.unwrap()
.insert(hir_id.local_id, Lrc::new(v));
}
- Lrc::new(ResolveLifetimes {
- defs,
- late_bound,
- object_lifetime_defaults,
- })
+ Lrc::new(rl)
}
fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
);
}
- let mut externs = BTreeMap::new();
+ let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
for arg in &matches.opt_strs("extern") {
let mut parts = arg.splitn(2, '=');
let name = match parts.next() {
externs
.entry(name.to_string())
- .or_insert_with(BTreeSet::new)
+ .or_default()
.insert(location.to_string());
}
{
let deps1 = vid_map
.entry(RegionTarget::RegionVid(r1))
- .or_insert_with(|| Default::default());
+ .or_default();
deps1.larger.insert(RegionTarget::RegionVid(r2));
}
let deps2 = vid_map
.entry(RegionTarget::RegionVid(r2))
- .or_insert_with(|| Default::default());
+ .or_default();
deps2.smaller.insert(RegionTarget::RegionVid(r1));
}
&Constraint::RegSubVar(region, vid) => {
{
let deps1 = vid_map
.entry(RegionTarget::Region(region))
- .or_insert_with(|| Default::default());
+ .or_default();
deps1.larger.insert(RegionTarget::RegionVid(vid));
}
let deps2 = vid_map
.entry(RegionTarget::RegionVid(vid))
- .or_insert_with(|| Default::default());
+ .or_default();
deps2.smaller.insert(RegionTarget::Region(region));
}
&Constraint::VarSubReg(vid, region) => {
{
let deps1 = vid_map
.entry(RegionTarget::Region(r1))
- .or_insert_with(|| Default::default());
+ .or_default();
deps1.larger.insert(RegionTarget::Region(r2));
}
let deps2 = vid_map
.entry(RegionTarget::Region(r2))
- .or_insert_with(|| Default::default());
+ .or_default();
deps2.smaller.insert(RegionTarget::Region(r1));
}
}
index: Option<usize>, // None if this is an old error
}
- let mut error_map : FxHashMap<_, _> =
+ let mut error_map : FxHashMap<_, Vec<_>> =
self.reported_trait_errors.borrow().iter().map(|(&span, predicates)| {
(span, predicates.iter().map(|predicate| ErrorDescriptor {
predicate: predicate.clone(),
}).collect();
for (index, error) in errors.iter().enumerate() {
- error_map.entry(error.obligation.cause.span).or_insert(Vec::new()).push(
+ error_map.entry(error.obligation.cause.span).or_default().push(
ErrorDescriptor {
predicate: error.obligation.predicate.clone(),
index: Some(index)
});
self.reported_trait_errors.borrow_mut()
- .entry(error.obligation.cause.span).or_insert(Vec::new())
+ .entry(error.obligation.cause.span).or_default()
.push(error.obligation.predicate.clone());
}
/// Children of a given impl, grouped into blanket/non-blanket varieties as is
/// done in `TraitDef`.
-#[derive(RustcEncodable, RustcDecodable)]
+#[derive(Default, RustcEncodable, RustcDecodable)]
struct Children {
// Impls of a trait (or specializations of a given impl). To allow for
// quicker lookup, the impls are indexed by a simplified version of their
}
impl<'a, 'gcx, 'tcx> Children {
- fn new() -> Children {
- Children {
- nonblanket_impls: FxHashMap(),
- blanket_impls: vec![],
- }
- }
-
/// Insert an impl into this set of children without comparing to any existing impls
fn insert_blindly(&mut self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
if let Some(sty) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false) {
debug!("insert_blindly: impl_def_id={:?} sty={:?}", impl_def_id, sty);
- self.nonblanket_impls.entry(sty).or_insert(vec![]).push(impl_def_id)
+ self.nonblanket_impls.entry(sty).or_default().push(impl_def_id)
} else {
debug!("insert_blindly: impl_def_id={:?} sty=None", impl_def_id);
self.blanket_impls.push(impl_def_id)
}
fn filtered(&mut self, sty: SimplifiedType) -> Box<dyn Iterator<Item = DefId> + '_> {
- let nonblanket = self.nonblanket_impls.entry(sty).or_insert(vec![]).iter();
+ let nonblanket = self.nonblanket_impls.entry(sty).or_default().iter();
Box::new(self.blanket_impls.iter().chain(nonblanket).cloned())
}
}
trait_ref, impl_def_id, trait_def_id);
self.parent.insert(impl_def_id, trait_def_id);
- self.children.entry(trait_def_id).or_insert(Children::new())
+ self.children.entry(trait_def_id).or_default()
.insert_blindly(tcx, impl_def_id);
return Ok(None);
}
loop {
use self::Inserted::*;
- let insert_result = self.children.entry(parent).or_insert(Children::new())
+ let insert_result = self.children.entry(parent).or_default()
.insert(tcx, impl_def_id, simplified)?;
match insert_result {
self.parent.insert(impl_def_id, parent);
// Add G as N's child.
- let mut grand_children = Children::new();
- grand_children.insert_blindly(tcx, grand_child_to_be);
- self.children.insert(impl_def_id, grand_children);
+ self.children.entry(impl_def_id).or_default()
+ .insert_blindly(tcx, grand_child_to_be);
break;
}
ShouldRecurseOn(new_parent) => {
was already present.");
}
- self.children.entry(parent).or_insert(Children::new()).insert_blindly(tcx, child);
+ self.children.entry(parent).or_default().insert_blindly(tcx, child);
}
/// The parent of a given impl, which is the def id of the trait when the
None
};
- let mut trait_map = FxHashMap();
+ let mut trait_map: FxHashMap<_, Lrc<FxHashMap<_, _>>> = FxHashMap();
for (k, v) in resolutions.trait_map {
let hir_id = hir.node_to_hir_id(k);
- let map = trait_map.entry(hir_id.owner)
- .or_insert_with(|| Lrc::new(FxHashMap()));
+ let map = trait_map.entry(hir_id.owner).or_default();
Lrc::get_mut(map).unwrap()
.insert(hir_id.local_id,
Lrc::new(StableVec::new(v)));
match self.sty {
TyAdt(def, substs) => {
{
- let substs_set = visited.entry(def.did).or_insert(FxHashSet::default());
+ let substs_set = visited.entry(def.did).or_default();
if !substs_set.insert(substs) {
// We are already calculating the inhabitedness of this type.
// The type must contain a reference to itself. Break the
pub def_path_hash: DefPathHash,
}
+#[derive(Default)]
pub struct TraitImpls {
blanket_impls: Vec<DefId>,
/// Impls indexed by their simplified self-type, for fast lookup.
pub(super) fn trait_impls_of_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_id: DefId)
-> Lrc<TraitImpls> {
- let mut remote_impls = Vec::new();
-
- // Traits defined in the current crate can't have impls in upstream
- // crates, so we don't bother querying the cstore.
- if !trait_id.is_local() {
- for &cnum in tcx.crates().iter() {
- let impls = tcx.implementations_of_trait((cnum, trait_id));
- remote_impls.extend(impls.iter().cloned());
- }
- }
-
- let mut blanket_impls = Vec::new();
- let mut non_blanket_impls = FxHashMap();
+ let mut impls = TraitImpls::default();
- let local_impls = tcx.hir
- .trait_impls(trait_id)
- .into_iter()
- .map(|&node_id| tcx.hir.local_def_id(node_id));
+ {
+ let mut add_impl = |impl_def_id| {
+ let impl_self_ty = tcx.type_of(impl_def_id);
+ if impl_def_id.is_local() && impl_self_ty.references_error() {
+ return;
+ }
- for impl_def_id in local_impls.chain(remote_impls.into_iter()) {
- let impl_self_ty = tcx.type_of(impl_def_id);
- if impl_def_id.is_local() && impl_self_ty.references_error() {
- continue
+ if let Some(simplified_self_ty) =
+ fast_reject::simplify_type(tcx, impl_self_ty, false)
+ {
+ impls.non_blanket_impls
+ .entry(simplified_self_ty)
+ .or_default()
+ .push(impl_def_id);
+ } else {
+ impls.blanket_impls.push(impl_def_id);
+ }
+ };
+
+ // Traits defined in the current crate can't have impls in upstream
+ // crates, so we don't bother querying the cstore.
+ if !trait_id.is_local() {
+ for &cnum in tcx.crates().iter() {
+ for &def_id in tcx.implementations_of_trait((cnum, trait_id)).iter() {
+ add_impl(def_id);
+ }
+ }
}
- if let Some(simplified_self_ty) =
- fast_reject::simplify_type(tcx, impl_self_ty, false)
- {
- non_blanket_impls
- .entry(simplified_self_ty)
- .or_insert(vec![])
- .push(impl_def_id);
- } else {
- blanket_impls.push(impl_def_id);
+ for &node_id in tcx.hir.trait_impls(trait_id) {
+ add_impl(tcx.hir.local_def_id(node_id));
}
}
- Lrc::new(TraitImpls {
- blanket_impls: blanket_impls,
- non_blanket_impls: non_blanket_impls,
- })
+ Lrc::new(impls)
}
impl<'a> HashStable<StableHashingContext<'a>> for TraitImpls {
impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> {
fn check_unused_mut_pat(&self, pats: &[P<hir::Pat>]) {
let tcx = self.bccx.tcx;
- let mut mutables = FxHashMap();
+ let mut mutables: FxHashMap<_, Vec<_>> = FxHashMap();
for p in pats {
p.each_binding(|_, hir_id, span, ident| {
// Skip anything that looks like `_foo`
_ => return,
}
- mutables.entry(ident.name).or_insert(Vec::new()).push((hir_id, span));
+ mutables.entry(ident.name).or_default().push((hir_id, span));
} else {
tcx.sess.delay_span_bug(span, "missing binding mode");
}
cfg.graph.each_node(|node_idx, node| {
if let cfg::CFGNodeData::AST(id) = node.data {
- index.entry(id).or_insert(vec![]).push(node_idx);
+ index.entry(id).or_default().push(node_idx);
}
true
});
}
fn visit_pat(&mut self, p: &hir::Pat) {
- self.index.entry(p.hir_id.local_id).or_insert(vec![]).push(self.entry);
+ self.index.entry(p.hir_id.local_id).or_default().push(self.entry);
intravisit::walk_pat(self, p)
}
}
let cnums = tcx.all_crate_nums(LOCAL_CRATE);
- let mut instances = DefIdMap();
+ let mut instances: DefIdMap<FxHashMap<_, _>> = DefIdMap();
let cnum_stable_ids: IndexVec<CrateNum, Fingerprint> = {
let mut cnum_stable_ids = IndexVec::from_elem_n(Fingerprint::ZERO,
for &cnum in cnums.iter() {
for &(ref exported_symbol, _) in tcx.exported_symbols(cnum).iter() {
if let &ExportedSymbol::Generic(def_id, substs) = exported_symbol {
- let substs_map = instances.entry(def_id)
- .or_insert_with(|| FxHashMap());
+ let substs_map = instances.entry(def_id).or_default();
match substs_map.entry(substs) {
Occupied(mut e) => {
}).collect();
if tcx.sess.opts.debugging_opts.print_mono_items.is_some() {
- let mut item_to_cgus = FxHashMap();
+ let mut item_to_cgus: FxHashMap<_, Vec<_>> = FxHashMap();
for cgu in &codegen_units {
for (&mono_item, &linkage) in cgu.items() {
item_to_cgus.entry(mono_item)
- .or_insert(Vec::new())
+ .or_default()
.push((cgu.name().clone(), linkage));
}
}
for &(source, target) in edges {
graph.num_nodes = max(graph.num_nodes, source + 1);
graph.num_nodes = max(graph.num_nodes, target + 1);
- graph.successors.entry(source).or_insert(vec![]).push(target);
- graph.predecessors.entry(target).or_insert(vec![]).push(source);
+ graph.successors.entry(source).or_default().push(target);
+ graph.predecessors.entry(target).or_default().push(source);
}
for node in 0..graph.num_nodes {
- graph.successors.entry(node).or_insert(vec![]);
- graph.predecessors.entry(node).or_insert(vec![]);
+ graph.successors.entry(node).or_default();
+ graph.predecessors.entry(node).or_default();
}
graph
}
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_id) {
self.impls
.entry(trait_ref.def_id)
- .or_insert(vec![])
+ .or_default()
.push(impl_id.index);
}
}
let rlib_prefix = format!("lib{}{}", self.crate_name, extra_prefix);
let staticlib_prefix = format!("{}{}{}", staticpair.0, self.crate_name, extra_prefix);
- let mut candidates = FxHashMap();
+ let mut candidates: FxHashMap<
+ _,
+ (FxHashMap<_, _>, FxHashMap<_, _>, FxHashMap<_, _>),
+ > = FxHashMap();
let mut staticlibs = vec![];
// First, find all possible candidate rlibs and dylibs purely based on
info!("lib candidate: {}", path.display());
let hash_str = hash.to_string();
- let slot = candidates.entry(hash_str)
- .or_insert_with(|| (FxHashMap(), FxHashMap(), FxHashMap()));
+ let slot = candidates.entry(hash_str).or_default();
let (ref mut rlibs, ref mut rmetas, ref mut dylibs) = *slot;
fs::canonicalize(path)
.map(|p| {
self.activation_map
.entry(location)
- .or_insert(Vec::new())
+ .or_default()
.push(borrow_index);
TwoPhaseActivation::ActivatedAt(location)
}
debug!("borrow {:?} gets killed at {:?}", borrow_index, location);
borrows_out_of_scope_at_location
.entry(location)
- .or_insert(vec![])
+ .or_default()
.push(borrow_index);
continue;
}
inlining_map.iter_accesses(|accessor, accessees| {
for accessee in accessees {
accessor_map.entry(*accessee)
- .or_insert(Vec::new())
+ .or_default()
.push(accessor);
}
});
if let Some(parent) = scope_data.parent_scope {
scope_tree
.entry(parent)
- .or_insert(vec![])
+ .or_default()
.push(SourceScope::new(index));
} else {
// Only the argument scope has no parent, because it's the root.
// Check later.
return;
}
- self.unused_imports.entry(item_id).or_insert_with(NodeMap).insert(id, span);
+ self.unused_imports.entry(item_id).or_default().insert(id, span);
} else {
// This trait import is definitely used, in a way other than
// method resolution.
if items.len() == 0 {
self.unused_imports
.entry(self.base_id)
- .or_insert_with(NodeMap)
+ .or_default()
.insert(id, span);
}
} else {
fn add_to_glob_map(&mut self, id: NodeId, ident: Ident) {
if self.make_glob_map {
- self.glob_map.entry(id).or_insert_with(FxHashSet).insert(ident.name);
+ self.glob_map.entry(id).or_default().insert(ident.name);
}
}
let seen = self.freevars_seen
.entry(function_id)
- .or_insert_with(|| NodeMap());
+ .or_default();
if let Some(&index) = seen.get(&node_id) {
def = Def::Upvar(node_id, index, function_id);
continue;
}
let vec = self.freevars
.entry(function_id)
- .or_insert_with(|| vec![]);
+ .or_default();
let depth = vec.len();
def = Def::Upvar(node_id, depth, function_id);
closure_def_id: DefId,
r: DeferredCallResolution<'gcx, 'tcx>) {
let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
- deferred_call_resolutions.entry(closure_def_id).or_insert(vec![]).push(r);
+ deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
}
fn remove_deferred_call_resolutions(&self,
.borrow_mut()
.adjustments_mut()
.entry(rhs_expr.hir_id)
- .or_insert(vec![])
+ .or_default()
.push(autoref);
}
}
let impl_def_id = self.tcx.hir.local_def_id(item.id);
let mut rc_vec = self.impls_map.inherent_impls
.entry(def_id)
- .or_insert_with(|| Lrc::new(vec![]));
+ .or_default();
// At this point, there should not be any clones of the
// `Lrc`, so we can still safely push into it in place:
// all intermediate RegionVids. At the end, all constraints should
// be between Regions (aka region variables). This gives us the information
// we need to create the Generics.
- let mut finished = FxHashMap();
+ let mut finished: FxHashMap<_, Vec<_>> = FxHashMap();
let mut vid_map: FxHashMap<RegionTarget, RegionDeps> = FxHashMap();
{
let deps1 = vid_map
.entry(RegionTarget::RegionVid(r1))
- .or_insert_with(|| Default::default());
+ .or_default();
deps1.larger.insert(RegionTarget::RegionVid(r2));
}
let deps2 = vid_map
.entry(RegionTarget::RegionVid(r2))
- .or_insert_with(|| Default::default());
+ .or_default();
deps2.smaller.insert(RegionTarget::RegionVid(r1));
}
&Constraint::RegSubVar(region, vid) => {
let deps = vid_map
.entry(RegionTarget::RegionVid(vid))
- .or_insert_with(|| Default::default());
+ .or_default();
deps.smaller.insert(RegionTarget::Region(region));
}
&Constraint::VarSubReg(vid, region) => {
let deps = vid_map
.entry(RegionTarget::RegionVid(vid))
- .or_insert_with(|| Default::default());
+ .or_default();
deps.larger.insert(RegionTarget::Region(region));
}
&Constraint::RegSubReg(r1, r2) => {
if self.region_name(r1) != self.region_name(r2) {
finished
.entry(self.region_name(r2).expect("no region_name found"))
- .or_insert_with(|| Vec::new())
+ .or_default()
.push(r1);
}
}
if self.region_name(r1) != self.region_name(r2) {
finished
.entry(self.region_name(r2).expect("no region name found"))
- .or_insert_with(|| Vec::new())
+ .or_default()
.push(r1) // Larger, smaller
}
}
} = full_generics.clean(self.cx);
let mut has_sized = FxHashSet();
- let mut ty_to_bounds = FxHashMap();
- let mut lifetime_to_bounds = FxHashMap();
+ let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = FxHashMap();
+ let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = FxHashMap();
let mut ty_to_traits: FxHashMap<Type, FxHashSet<Type>> = FxHashMap();
let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = FxHashMap();
ty_to_bounds
.entry(ty.clone())
- .or_insert_with(|| FxHashSet());
+ .or_default();
} else {
ty_to_bounds
.entry(ty.clone())
- .or_insert_with(|| FxHashSet())
+ .or_default()
.insert(b.clone());
}
}
WherePredicate::RegionPredicate { lifetime, bounds } => {
lifetime_to_bounds
.entry(lifetime)
- .or_insert_with(|| FxHashSet())
+ .or_default()
.extend(bounds);
}
WherePredicate::EqPredicate { lhs, rhs } => {
let bounds = ty_to_bounds
.entry(*ty.clone())
- .or_insert_with(|| FxHashSet());
+ .or_default();
bounds.insert(GenericBound::TraitBound(
PolyTrait {
// loop
ty_to_traits
.entry(*ty.clone())
- .or_insert_with(|| FxHashSet())
+ .or_default()
.insert(*trait_.clone());
}
_ => panic!("Unexpected trait {:?} for {:?}", trait_, did),
pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
// First, partition the where clause into its separate components
- let mut params = BTreeMap::new();
+ let mut params: BTreeMap<_, Vec<_>> = BTreeMap::new();
let mut lifetimes = Vec::new();
let mut equalities = Vec::new();
let mut tybounds = Vec::new();
match clause {
WP::BoundPredicate { ty, bounds } => {
match ty {
- clean::Generic(s) => params.entry(s).or_insert(Vec::new())
+ clean::Generic(s) => params.entry(s).or_default()
.extend(bounds),
t => tybounds.push((t, ty_bounds(bounds))),
}
// Collect all the implementors of traits.
if let clean::ImplItem(ref i) = item.inner {
if let Some(did) = i.trait_.def_id() {
- self.implementors.entry(did).or_insert(vec![]).push(Impl {
+ self.implementors.entry(did).or_default().push(Impl {
impl_item: item.clone(),
});
}
unreachable!()
};
for did in dids {
- self.impls.entry(did).or_insert(vec![]).push(Impl {
+ self.impls.entry(did).or_default().push(Impl {
impl_item: item.clone(),
});
}
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
// BTreeMap instead of HashMap to get a sorted output
- let mut map = BTreeMap::new();
+ let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
for item in &m.items {
if item.is_stripped() { continue }
Some(ref s) => s.to_string(),
};
let short = short.to_string();
- map.entry(short).or_insert(vec![])
+ map.entry(short).or_default()
.push((myname, Some(plain_summary_line(item.doc_value()))));
}
/// returns a map mapping crate names to their paths or else an
/// error message.
fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
- let mut externs = BTreeMap::new();
+ let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
for arg in &matches.opt_strs("extern") {
let mut parts = arg.splitn(2, '=');
let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
.ok_or("--extern value must be of the format `foo=bar`"
.to_string())?;
let name = name.to_string();
- externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
+ externs.entry(name).or_default().insert(location.to_string());
}
Ok(Externs::new(externs))
}
// Unresolved macros produce dummy outputs as a recovery measure.
invocations.reverse();
let mut expanded_fragments = Vec::new();
- let mut derives = HashMap::new();
+ let mut derives: HashMap<Mark, Vec<_>> = HashMap::new();
let mut undetermined_invocations = Vec::new();
let (mut progress, mut force) = (false, !self.monotonic);
loop {
.map_attrs(|mut attrs| { attrs.retain(|a| a.path != "derive"); attrs });
let item_with_markers =
add_derived_markers(&mut self.cx, item.span(), &traits, item.clone());
- let derives = derives.entry(invoc.expansion_data.mark).or_insert_with(Vec::new);
+ let derives = derives.entry(invoc.expansion_data.mark).or_default();
for path in &traits {
let mark = Mark::fresh(self.cx.current_expansion.mark);
fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
- let values: &mut Vec<String> = cx.expansions.entry(sp).or_insert_with(Vec::new);
- values.push(message);
+ cx.expansions.entry(sp).or_default().push(message);
}
/// Given `lhses` and `rhses`, this is the new macro we create
// "cargo", // FIXME(#53005)
"rustc-ap-syntax",
];
- let mut name_to_id = HashMap::new();
+ let mut name_to_id: HashMap<_, Vec<_>> = HashMap::new();
for node in resolve.nodes.iter() {
name_to_id.entry(node.id.split_whitespace().next().unwrap())
- .or_insert(Vec::new())
+ .or_default()
.push(&node.id);
}
pub fn check(path: &Path, bad: &mut bool) {
let mut contents = String::new();
- let mut map = HashMap::new();
+ let mut map: HashMap<_, Vec<_>> = HashMap::new();
super::walk(path,
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
&mut |file| {
Ok(n) => n,
Err(..) => continue,
};
- map.entry(code).or_insert(Vec::new())
+ map.entry(code).or_default()
.push((file.to_owned(), num + 1, line.to_owned()));
break
}