From ee81739dc1e0f1c4dff9480b52528fb688ef9251 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 16 Oct 2018 10:44:26 +0200 Subject: Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack --- src/librustc_codegen_utils/codegen_backend.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/librustc_codegen_utils') diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index d693e088360..48e1292d435 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -132,7 +132,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { ::symbol_names::provide(providers); providers.target_features_whitelist = |_tcx, _cnum| { - Lrc::new(FxHashMap()) // Just a dummy + Lrc::new(FxHashMap::default()) // Just a dummy }; providers.is_reachable_non_generic = |_tcx, _defid| true; providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new()); -- cgit 1.4.1-3-g733a5 From 3c9258e604c7f5d3b7e86c34da1f067ff0a60257 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 16 Oct 2018 16:57:53 +0200 Subject: Prefer `Default::default` over `FxHash*::default` in struct constructors --- src/bootstrap/cache.rs | 20 +++--------- src/libarena/lib.rs | 32 +++++++----------- src/librustc/dep_graph/cgu_reuse_tracker.rs | 4 +-- src/librustc/dep_graph/dep_tracking_map.rs | 2 +- src/librustc/dep_graph/graph.rs | 10 +++--- src/librustc/dep_graph/prev.rs | 2 +- src/librustc/dep_graph/serialized.rs | 12 +------ src/librustc/hir/map/definitions.rs | 8 ++--- src/librustc/hir/map/hir_id_validator.rs | 2 +- src/librustc/ich/hcx.rs | 2 +- src/librustc/ich/impls_ty.rs | 2 +- src/librustc/infer/freshen.rs | 2 +- src/librustc/infer/lexical_region_resolve/mod.rs | 2 +- src/librustc/infer/mod.rs | 10 +++--- src/librustc/infer/outlives/env.rs | 4 +-- src/librustc/infer/outlives/free_region_map.rs | 6 +--- src/librustc/infer/region_constraints/mod.rs | 4 +-- src/librustc/lint/context.rs | 6 ++-- src/librustc/lint/levels.rs | 2 +- src/librustc/middle/dead.rs | 3 +- src/librustc/middle/lib_features.rs | 4 +-- src/librustc/middle/region.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 18 ++++------ src/librustc/middle/stability.rs | 6 ++-- src/librustc/mir/interpret/mod.rs | 4 +-- src/librustc/mir/mono.rs | 4 +-- src/librustc/session/code_stats.rs | 4 +-- src/librustc/session/mod.rs | 6 ++-- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/mod.rs | 2 +- src/librustc/traits/project.rs | 7 +--- src/librustc/traits/select.rs | 20 +++--------- src/librustc/traits/specialize/mod.rs | 22 +------------ src/librustc/traits/util.rs | 2 +- src/librustc/ty/context.rs | 38 +++++++--------------- src/librustc/ty/fold.rs | 2 +- src/librustc/ty/mod.rs | 3 +- src/librustc/ty/query/on_disk_cache.rs | 26 +++++++-------- src/librustc/ty/query/plumbing.rs | 6 ++-- src/librustc/util/nodemap.rs | 4 +-- src/librustc/util/ppaux.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 6 ++-- src/librustc_borrowck/borrowck/unused.rs | 2 +- src/librustc_codegen_llvm/back/lto.rs | 14 ++------ src/librustc_codegen_llvm/base.rs | 18 +++++----- src/librustc_codegen_llvm/context.rs | 18 +++++----- src/librustc_codegen_llvm/debuginfo/metadata.rs | 10 +----- src/librustc_codegen_llvm/debuginfo/mod.rs | 8 ++--- src/librustc_codegen_utils/codegen_backend.rs | 4 +-- .../obligation_forest/mod.rs | 8 ++--- src/librustc_data_structures/snapshot_map/mod.rs | 8 +++-- src/librustc_data_structures/sync.rs | 4 +-- .../transitive_relation.rs | 8 +++-- src/librustc_errors/lib.rs | 8 ++--- src/librustc_incremental/persist/dirty_clean.rs | 2 +- src/librustc_incremental/persist/load.rs | 6 ++-- src/librustc_metadata/cstore.rs | 2 +- src/librustc_metadata/locator.rs | 2 +- src/librustc_mir/borrow_check/borrow_set.rs | 10 +++--- src/librustc_mir/borrow_check/mod.rs | 8 ++--- .../nll/type_check/free_region_relations.rs | 4 +-- .../borrow_check/nll/type_check/mod.rs | 4 +-- src/librustc_mir/build/matches/test.rs | 2 +- src/librustc_mir/build/scope.rs | 2 +- src/librustc_mir/dataflow/move_paths/builder.rs | 3 +- src/librustc_mir/hair/pattern/_match.rs | 2 +- src/librustc_mir/monomorphize/partitioning.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- .../transform/cleanup_post_borrowck.rs | 10 +++--- src/librustc_mir/transform/elaborate_drops.rs | 2 +- src/librustc_mir/util/pretty.rs | 2 +- src/librustc_resolve/lib.rs | 20 ++++-------- src/librustc_typeck/check/wfcheck.rs | 3 +- src/librustc_typeck/collect.rs | 2 +- src/librustc_typeck/variance/mod.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 14 ++++---- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 5 ++- src/librustdoc/core.rs | 6 ++-- src/librustdoc/html/render.rs | 20 ++++++------ src/libsyntax/source_map.rs | 11 ++----- src/libsyntax_pos/symbol.rs | 14 ++------ 82 files changed, 237 insertions(+), 362 deletions(-) (limited to 'src/librustc_codegen_utils') diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index bca5ff85ba2..4a50f744e7a 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -169,19 +169,13 @@ impl Ord for Interned { } } -struct TyIntern { +#[derive(Default)] +struct TyIntern { items: Vec, set: HashMap>, } impl TyIntern { - fn new() -> TyIntern { - TyIntern { - items: Vec::new(), - set: HashMap::new(), - } - } - fn intern_borrow(&mut self, item: &B) -> Interned where B: Eq + Hash + ToOwned + ?Sized, @@ -212,19 +206,13 @@ impl TyIntern { } } +#[derive(Default)] pub struct Interner { strs: Mutex>, paths: Mutex>, } impl Interner { - fn new() -> Interner { - Interner { - strs: Mutex::new(TyIntern::new()), - paths: Mutex::new(TyIntern::new()), - } - } - pub fn intern_str(&self, s: &str) -> Interned { self.strs.lock().unwrap().intern_borrow(s) } @@ -238,7 +226,7 @@ impl Interner { } lazy_static! { - pub static ref INTERNER: Interner = Interner::new(); + pub static ref INTERNER: Interner = Interner::default(); } /// This is essentially a HashMap which allows storing any type in its input and diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index b02ae75eff8..a7b34b6dc40 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -114,10 +114,9 @@ impl TypedArenaChunk { const PAGE: usize = 4096; -impl TypedArena { +impl Default for TypedArena { /// Creates a new `TypedArena`. - #[inline] - pub fn new() -> TypedArena { + fn default() -> TypedArena { TypedArena { // We set both `ptr` and `end` to 0 so that the first call to // alloc() will trigger a grow(). @@ -127,7 +126,9 @@ impl TypedArena { _own: PhantomData, } } +} +impl TypedArena { /// Allocates an object in the `TypedArena`, returning a reference to it. #[inline] pub fn alloc(&self, object: T) -> &mut T { @@ -296,15 +297,17 @@ pub struct DroplessArena { unsafe impl Send for DroplessArena {} -impl DroplessArena { - pub fn new() -> DroplessArena { +impl Default for DroplessArena { + fn default() -> DroplessArena { DroplessArena { ptr: Cell::new(0 as *mut u8), end: Cell::new(0 as *mut u8), - chunks: RefCell::new(vec![]), + chunks: Default::default(), } } +} +impl DroplessArena { pub fn in_arena(&self, ptr: *const T) -> bool { let ptr = ptr as *const u8 as *mut u8; for chunk in &*self.chunks.borrow() { @@ -419,18 +422,13 @@ impl DroplessArena { } } +#[derive(Default)] +// FIXME(@Zoxc): this type is entirely unused in rustc pub struct SyncTypedArena { lock: MTLock>, } impl SyncTypedArena { - #[inline(always)] - pub fn new() -> SyncTypedArena { - SyncTypedArena { - lock: MTLock::new(TypedArena::new()) - } - } - #[inline(always)] pub fn alloc(&self, object: T) -> &mut T { // Extend the lifetime of the result since it's limited to the lock guard @@ -452,18 +450,12 @@ impl SyncTypedArena { } } +#[derive(Default)] pub struct SyncDroplessArena { lock: MTLock, } impl SyncDroplessArena { - #[inline(always)] - pub fn new() -> SyncDroplessArena { - SyncDroplessArena { - lock: MTLock::new(DroplessArena::new()) - } - } - #[inline(always)] pub fn in_arena(&self, ptr: *const T) -> bool { self.lock.lock().in_arena(ptr) diff --git a/src/librustc/dep_graph/cgu_reuse_tracker.rs b/src/librustc/dep_graph/cgu_reuse_tracker.rs index 8e6983e9ddf..99fc020bbe4 100644 --- a/src/librustc/dep_graph/cgu_reuse_tracker.rs +++ b/src/librustc/dep_graph/cgu_reuse_tracker.rs @@ -51,8 +51,8 @@ pub struct CguReuseTracker { impl CguReuseTracker { pub fn new() -> CguReuseTracker { let data = TrackerData { - actual_reuse: FxHashMap::default(), - expected_reuse: FxHashMap::default(), + actual_reuse: Default::default(), + expected_reuse: Default::default(), }; CguReuseTracker { diff --git a/src/librustc/dep_graph/dep_tracking_map.rs b/src/librustc/dep_graph/dep_tracking_map.rs index 33b10bcfc8a..a674b5df639 100644 --- a/src/librustc/dep_graph/dep_tracking_map.rs +++ b/src/librustc/dep_graph/dep_tracking_map.rs @@ -36,7 +36,7 @@ impl DepTrackingMap { DepTrackingMap { phantom: PhantomData, graph, - map: FxHashMap::default(), + map: Default::default(), } } } diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 971f4e86c5e..ddc5676c74e 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -101,11 +101,11 @@ impl DepGraph { DepGraph { data: Some(Lrc::new(DepGraphData { previous_work_products: prev_work_products, - dep_node_debug: Lock::new(FxHashMap::default()), + dep_node_debug: Lock::new(Default::default()), current: Lock::new(CurrentDepGraph::new()), previous: prev_graph, colors: Lock::new(DepNodeColorMap::new(prev_graph_node_count)), - loaded_from_cache: Lock::new(FxHashMap::default()), + loaded_from_cache: Lock::new(Default::default()), })), fingerprints: Lrc::new(Lock::new(fingerprints)), } @@ -209,7 +209,7 @@ impl DepGraph { |key| OpenTask::Regular(Lock::new(RegularOpenTask { node: key, reads: SmallVec::new(), - read_set: FxHashSet::default(), + read_set: Default::default(), })), |data, key, task| data.borrow_mut().complete_task(key, task)) } @@ -353,7 +353,7 @@ impl DepGraph { let (result, open_task) = ty::tls::with_context(|icx| { let task = OpenTask::Anon(Lock::new(AnonOpenTask { reads: SmallVec::new(), - read_set: FxHashSet::default(), + read_set: Default::default(), })); let r = { @@ -937,7 +937,7 @@ impl CurrentDepGraph { CurrentDepGraph { nodes: IndexVec::new(), edges: IndexVec::new(), - node_to_node_index: FxHashMap::default(), + node_to_node_index: Default::default(), anon_id_seed: stable_hasher.finish(), forbidden_edge, total_read_count: 0, diff --git a/src/librustc/dep_graph/prev.rs b/src/librustc/dep_graph/prev.rs index 669a99019aa..ebc50f4afb8 100644 --- a/src/librustc/dep_graph/prev.rs +++ b/src/librustc/dep_graph/prev.rs @@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap; use super::dep_node::DepNode; use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex}; -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, RustcEncodable, RustcDecodable, Default)] pub struct PreviousDepGraph { data: SerializedDepGraph, index: FxHashMap, diff --git a/src/librustc/dep_graph/serialized.rs b/src/librustc/dep_graph/serialized.rs index 4c896a33e59..0c6c224fa91 100644 --- a/src/librustc/dep_graph/serialized.rs +++ b/src/librustc/dep_graph/serialized.rs @@ -19,7 +19,7 @@ newtype_index! { } /// Data for use when recompiling the **current crate**. -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, RustcEncodable, RustcDecodable, Default)] pub struct SerializedDepGraph { /// The set of all DepNodes in the graph pub nodes: IndexVec, @@ -36,16 +36,6 @@ pub struct SerializedDepGraph { } impl SerializedDepGraph { - - pub fn new() -> SerializedDepGraph { - SerializedDepGraph { - nodes: IndexVec::new(), - fingerprints: IndexVec::new(), - edge_list_indices: IndexVec::new(), - edge_list_data: Vec::new(), - } - } - #[inline] pub fn edge_targets_from(&self, source: SerializedDepNodeIndex) diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 54d662cce33..dd689154086 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -421,10 +421,10 @@ impl Definitions { node_to_def_index: NodeMap(), def_index_to_node: [vec![], vec![]], node_to_hir_id: IndexVec::new(), - parent_modules_of_macro_defs: FxHashMap::default(), - expansions_that_defined: FxHashMap::default(), - next_disambiguator: FxHashMap::default(), - def_index_to_span: FxHashMap::default(), + parent_modules_of_macro_defs: Default::default(), + expansions_that_defined: Default::default(), + next_disambiguator: Default::default(), + def_index_to_span: Default::default(), } } diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index d8dc75a0590..087efbd4a22 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -51,7 +51,7 @@ impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> { HirIdValidator { hir_map, owner_def_index: None, - hir_ids_seen: FxHashMap::default(), + hir_ids_seen: Default::default(), errors: Vec::new(), } } diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index f0ab449b702..1c7c1b854da 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -370,7 +370,7 @@ impl<'a> HashStable> for Span { // recursing every time. thread_local! { static CACHE: RefCell> = - RefCell::new(FxHashMap::default()); + RefCell::new(Default::default()); } let sub_hash: u64 = CACHE.with(|cache| { diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 63a3534fb70..d8b3cbded13 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -32,7 +32,7 @@ for &'gcx ty::List hasher: &mut StableHasher) { thread_local! { static CACHE: RefCell> = - RefCell::new(FxHashMap::default()); + RefCell::new(Default::default()); } let hash = CACHE.with(|cache| { diff --git a/src/librustc/infer/freshen.rs b/src/librustc/infer/freshen.rs index 26c252cef09..c7785d83171 100644 --- a/src/librustc/infer/freshen.rs +++ b/src/librustc/infer/freshen.rs @@ -62,7 +62,7 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> { TypeFreshener { infcx, freshen_count: 0, - freshen_map: FxHashMap::default(), + freshen_map: Default::default(), } } diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 066951c930b..8f28e9a320d 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -614,7 +614,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> { dup_found: bool, } let mut state = WalkState { - set: FxHashSet::default(), + set: Default::default(), stack: vec![orig_node_idx], result: Vec::new(), dup_found: false, diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index c1c09a7e7fa..f5513acecf9 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -478,7 +478,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> { pub fn infer_ctxt(self) -> InferCtxtBuilder<'a, 'gcx, 'tcx> { InferCtxtBuilder { global_tcx: self, - arena: SyncDroplessArena::new(), + arena: SyncDroplessArena::default(), fresh_tables: None, } } @@ -526,15 +526,15 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> { f(InferCtxt { tcx, in_progress_tables, - projection_cache: RefCell::new(traits::ProjectionCache::new()), + projection_cache: Default::default(), type_variables: RefCell::new(type_variable::TypeVariableTable::new()), int_unification_table: RefCell::new(ut::UnificationTable::new()), float_unification_table: RefCell::new(ut::UnificationTable::new()), region_constraints: RefCell::new(Some(RegionConstraintCollector::new())), lexical_region_resolutions: RefCell::new(None), - selection_cache: traits::SelectionCache::new(), - evaluation_cache: traits::EvaluationCache::new(), - reported_trait_errors: RefCell::new(FxHashMap::default()), + selection_cache: Default::default(), + evaluation_cache: Default::default(), + reported_trait_errors: Default::default(), tainted_by_errors_flag: Cell::new(false), err_count_on_creation: tcx.sess.err_count(), in_snapshot: Cell::new(false), diff --git a/src/librustc/infer/outlives/env.rs b/src/librustc/infer/outlives/env.rs index 631ff58d3e3..726bb388252 100644 --- a/src/librustc/infer/outlives/env.rs +++ b/src/librustc/infer/outlives/env.rs @@ -81,8 +81,8 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { pub fn new(param_env: ty::ParamEnv<'tcx>) -> Self { let mut env = OutlivesEnvironment { param_env, - free_region_map: FreeRegionMap::new(), - region_bound_pairs_map: FxHashMap::default(), + free_region_map: Default::default(), + region_bound_pairs_map: Default::default(), region_bound_pairs_accum: vec![], }; diff --git a/src/librustc/infer/outlives/free_region_map.rs b/src/librustc/infer/outlives/free_region_map.rs index e19ecfd427b..588a00eb503 100644 --- a/src/librustc/infer/outlives/free_region_map.rs +++ b/src/librustc/infer/outlives/free_region_map.rs @@ -11,7 +11,7 @@ use ty::{self, Lift, TyCtxt, Region}; use rustc_data_structures::transitive_relation::TransitiveRelation; -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)] pub struct FreeRegionMap<'tcx> { // Stores the relation `a < b`, where `a` and `b` are regions. // @@ -21,10 +21,6 @@ pub struct FreeRegionMap<'tcx> { } impl<'tcx> FreeRegionMap<'tcx> { - pub fn new() -> Self { - FreeRegionMap { relation: TransitiveRelation::new() } - } - pub fn is_empty(&self) -> bool { self.relation.is_empty() } diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index d631ddbf31d..a38be941b9a 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -345,8 +345,8 @@ impl<'tcx> RegionConstraintCollector<'tcx> { RegionConstraintCollector { var_infos: VarInfos::default(), data: RegionConstraintData::default(), - lubs: FxHashMap::default(), - glbs: FxHashMap::default(), + lubs: Default::default(), + glbs: Default::default(), bound_count: 0, undo_log: Vec::new(), unification_table: ut::UnificationTable::new(), diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 730f85a3dd0..7e2532bb1c4 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -159,9 +159,9 @@ impl LintStore { pre_expansion_passes: Some(vec![]), early_passes: Some(vec![]), late_passes: Some(vec![]), - by_name: FxHashMap::default(), - future_incompatible: FxHashMap::default(), - lint_groups: FxHashMap::default(), + by_name: Default::default(), + future_incompatible: Default::default(), + lint_groups: Default::default(), } } diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index f775ddf210f..475ca8da6b9 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -175,7 +175,7 @@ impl<'a> LintLevelsBuilder<'a> { sess, sets, cur: 0, - id_to_set: FxHashMap::default(), + id_to_set: Default::default(), warn_about_weird_lints: sess.buffered_lints.borrow().is_some(), } } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 06547796972..cd85d5e3614 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -50,6 +50,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> { worklist: Vec, tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, + // TODO: remove this `Box` live_symbols: Box>, repr_has_repr_c: bool, in_pat: bool, @@ -429,7 +430,7 @@ fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, worklist, tcx, tables: &ty::TypeckTables::empty(None), - live_symbols: box FxHashSet::default(), + live_symbols: box Default::default(), repr_has_repr_c: false, in_pat: false, inherited_pub_visibility: false, diff --git a/src/librustc/middle/lib_features.rs b/src/librustc/middle/lib_features.rs index aaa218926f8..7d65d412e01 100644 --- a/src/librustc/middle/lib_features.rs +++ b/src/librustc/middle/lib_features.rs @@ -31,8 +31,8 @@ pub struct LibFeatures { impl LibFeatures { fn new() -> LibFeatures { LibFeatures { - stable: FxHashMap::default(), - unstable: FxHashSet::default(), + stable: Default::default(), + unstable: Default::default(), } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 3e49dec4401..d00fbdeca21 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -1347,7 +1347,7 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) parent: None, var_parent: None, }, - terminating_scopes: FxHashSet::default(), + terminating_scopes: Default::default(), }; let body = tcx.hir.body(body_id); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index d959029d120..e89ba8ac54f 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -216,6 +216,7 @@ struct NamedRegionMap { } /// See `NamedRegionMap`. +#[derive(Default)] pub struct ResolveLifetimes { defs: FxHashMap>>, late_bound: FxHashMap>>, @@ -392,11 +393,7 @@ fn resolve_lifetimes<'tcx>( let named_region_map = krate(tcx); - let mut rl = ResolveLifetimes { - defs: FxHashMap::default(), - late_bound: FxHashMap::default(), - object_lifetime_defaults: FxHashMap::default(), - }; + let mut rl = ResolveLifetimes::default(); for (k, v) in named_region_map.defs { let hir_id = tcx.hir.node_to_hir_id(k); @@ -2017,7 +2014,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { map: self.map, outer_index: ty::INNERMOST, have_bound_regions: false, - lifetimes: FxHashSet::default(), + lifetimes: Default::default(), }; gather.visit_ty(input); @@ -2536,15 +2533,13 @@ fn insert_late_bound_lifetimes( debug!("insert_late_bound_lifetimes(decl={:?}, generics={:?})", decl, generics); - let mut constrained_by_input = ConstrainedCollector { - regions: FxHashSet::default(), - }; + let mut constrained_by_input = ConstrainedCollector::default(); for arg_ty in &decl.inputs { constrained_by_input.visit_ty(arg_ty); } let mut appears_in_output = AllCollector { - regions: FxHashSet::default(), + regions: Default::default(), }; intravisit::walk_fn_ret_ty(&mut appears_in_output, &decl.output); @@ -2556,7 +2551,7 @@ fn insert_late_bound_lifetimes( // Subtle point: because we disallow nested bindings, we can just // ignore binders here and scrape up all names we see. let mut appears_in_where_clause = AllCollector { - regions: FxHashSet::default(), + regions: Default::default(), }; appears_in_where_clause.visit_generics(generics); @@ -2610,6 +2605,7 @@ fn insert_late_bound_lifetimes( return; + #[derive(Default)] struct ConstrainedCollector { regions: FxHashSet, } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index a5d3e8023bd..ba79cf66d08 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -405,9 +405,9 @@ impl<'a, 'tcx> Index<'tcx> { staged_api.insert(LOCAL_CRATE, is_staged_api); let mut index = Index { staged_api, - stab_map: FxHashMap::default(), - depr_map: FxHashMap::default(), - active_features: FxHashSet::default(), + stab_map: Default::default(), + depr_map: Default::default(), + active_features: Default::default(), }; let ref active_lib_features = tcx.features().declared_lib_features; diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index a5e37274b8e..8c8073080aa 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -453,8 +453,8 @@ pub struct AllocMap<'tcx, M> { impl<'tcx, M: fmt::Debug + Eq + Hash + Clone> AllocMap<'tcx, M> { pub fn new() -> Self { AllocMap { - id_to_type: FxHashMap::default(), - type_interner: FxHashMap::default(), + id_to_type: Default::default(), + type_interner: Default::default(), next_id: AllocId(0), } } diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 9b31d129815..ff2bf3d7807 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -121,7 +121,7 @@ impl<'tcx> CodegenUnit<'tcx> { pub fn new(name: InternedString) -> CodegenUnit<'tcx> { CodegenUnit { name: name, - items: FxHashMap::default(), + items: Default::default(), size_estimate: None, } } @@ -251,7 +251,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self { CodegenUnitNameBuilder { tcx, - cache: FxHashMap::default(), + cache: Default::default(), } } diff --git a/src/librustc/session/code_stats.rs b/src/librustc/session/code_stats.rs index eb9bfe98422..b1dcfdfcda0 100644 --- a/src/librustc/session/code_stats.rs +++ b/src/librustc/session/code_stats.rs @@ -54,14 +54,12 @@ pub struct TypeSizeInfo { pub variants: Vec, } -#[derive(PartialEq, Eq, Debug)] +#[derive(PartialEq, Eq, Debug, Default)] pub struct CodeStats { type_sizes: FxHashSet, } impl CodeStats { - pub fn new() -> Self { CodeStats { type_sizes: FxHashSet::default() } } - pub fn record_type_size(&mut self, kind: DataTypeKind, type_desc: S, diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index fccdbcb5c2f..a17825a877d 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -1147,7 +1147,7 @@ pub fn build_session_( working_dir, lint_store: RwLock::new(lint::LintStore::new()), buffered_lints: Lock::new(Some(lint::LintBuffer::new())), - one_time_diagnostics: Lock::new(FxHashSet::default()), + one_time_diagnostics: Default::default(), plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())), plugin_attributes: OneThread::new(RefCell::new(Vec::new())), crate_types: Once::new(), @@ -1173,7 +1173,7 @@ pub fn build_session_( normalize_ty_after_erasing_regions: AtomicUsize::new(0), normalize_projection_ty: AtomicUsize::new(0), }, - code_stats: Lock::new(CodeStats::new()), + code_stats: Default::default(), optimization_fuel_crate, optimization_fuel_limit, print_fuel_crate, @@ -1207,7 +1207,7 @@ pub fn build_session_( }, has_global_allocator: Once::new(), has_panic_handler: Once::new(), - driver_lint_caps: FxHashMap::default(), + driver_lint_caps: Default::default(), }; validate_commandline_args_with_session_available(&sess); diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 4bc24133571..28c59d65bec 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1404,7 +1404,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let cleaned_pred = pred.fold_with(&mut ParamToVarFolder { infcx: self, - var_map: FxHashMap::default() + var_map: Default::default() }); let cleaned_pred = super::project::normalize( diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index d129cd486cf..8bceebb2395 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -48,7 +48,7 @@ pub use self::on_unimplemented::{OnUnimplementedDirective, OnUnimplementedNote}; pub use self::select::{EvaluationCache, SelectionContext, SelectionCache}; pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError}; pub use self::specialize::{OverlapError, specialization_graph, translate_substs}; -pub use self::specialize::{SpecializesCache, find_associated_item}; +pub use self::specialize::find_associated_item; pub use self::engine::{TraitEngine, TraitEngineExt}; pub use self::util::elaborate_predicates; pub use self::util::supertraits; diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 7c1f87fbf3f..b29ee8f7cdc 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -1601,6 +1601,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>( /// FIXME: we probably also want some sort of cross-infcx cache here to /// reduce the amount of duplication. Let's see what we get with the Chalk /// reforms. +#[derive(Default)] pub struct ProjectionCache<'tcx> { map: SnapshotMap, ProjectionCacheEntry<'tcx>>, } @@ -1643,12 +1644,6 @@ pub struct ProjectionCacheSnapshot { } impl<'tcx> ProjectionCache<'tcx> { - pub fn new() -> Self { - ProjectionCache { - map: SnapshotMap::new() - } - } - pub fn clear(&mut self) { self.map.clear(); } diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 9e541799120..95683e0613e 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -166,7 +166,7 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> { previous: TraitObligationStackList<'prev, 'tcx>, } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct SelectionCache<'tcx> { hashmap: Lock< FxHashMap, WithDepNode>>>, @@ -444,7 +444,7 @@ impl<'tcx> From for SelectionError<'tcx> { } } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct EvaluationCache<'tcx> { hashmap: Lock, WithDepNode>>, } @@ -3789,26 +3789,14 @@ impl<'tcx> TraitObligation<'tcx> { } impl<'tcx> SelectionCache<'tcx> { - pub fn new() -> SelectionCache<'tcx> { - SelectionCache { - hashmap: Lock::new(FxHashMap::default()), - } - } - pub fn clear(&self) { - *self.hashmap.borrow_mut() = FxHashMap::default() + self.hashmap.borrow_mut().clear(); } } impl<'tcx> EvaluationCache<'tcx> { - pub fn new() -> EvaluationCache<'tcx> { - EvaluationCache { - hashmap: Lock::new(FxHashMap::default()), - } - } - pub fn clear(&self) { - *self.hashmap.borrow_mut() = FxHashMap::default() + self.hashmap.borrow_mut().clear(); } } diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 010b79f7d58..0ce1d8f8227 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -22,7 +22,7 @@ use super::{SelectionContext, FulfillmentContext}; use super::util::impl_trait_ref_and_oblig; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashSet; use hir::def_id::DefId; use infer::{InferCtxt, InferOk}; use ty::subst::{Subst, Substs}; @@ -284,26 +284,6 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, }) } -pub struct SpecializesCache { - map: FxHashMap<(DefId, DefId), bool>, -} - -impl SpecializesCache { - pub fn new() -> Self { - SpecializesCache { - map: FxHashMap::default() - } - } - - pub fn check(&self, a: DefId, b: DefId) -> Option { - self.map.get(&(a, b)).cloned() - } - - pub fn insert(&mut self, a: DefId, b: DefId, result: bool) { - self.map.insert((a, b), result); - } -} - // Query provider for `specialization_graph_of`. pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_id: DefId) diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 81fa1ea02b0..0b7526dd784 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -59,7 +59,7 @@ struct PredicateSet<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { impl<'a, 'gcx, 'tcx> PredicateSet<'a, 'gcx, 'tcx> { fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> PredicateSet<'a, 'gcx, 'tcx> { - PredicateSet { tcx: tcx, set: FxHashSet::default() } + PredicateSet { tcx: tcx, set: Default::default() } } fn insert(&mut self, pred: &ty::Predicate<'tcx>) -> bool { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 2325570c40f..64f87d077ba 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -89,13 +89,14 @@ pub struct AllArenas<'tcx> { impl<'tcx> AllArenas<'tcx> { pub fn new() -> Self { AllArenas { - global: WorkerLocal::new(|_| GlobalArenas::new()), - interner: SyncDroplessArena::new(), + global: WorkerLocal::new(|_| GlobalArenas::default()), + interner: SyncDroplessArena::default(), } } } /// Internal storage +#[derive(Default)] pub struct GlobalArenas<'tcx> { // internings layout: TypedArena, @@ -111,21 +112,6 @@ pub struct GlobalArenas<'tcx> { const_allocs: TypedArena, } -impl<'tcx> GlobalArenas<'tcx> { - pub fn new() -> GlobalArenas<'tcx> { - GlobalArenas { - layout: TypedArena::new(), - generics: TypedArena::new(), - trait_def: TypedArena::new(), - adt_def: TypedArena::new(), - steal_mir: TypedArena::new(), - mir: TypedArena::new(), - tables: TypedArena::new(), - const_allocs: TypedArena::new(), - } - } -} - type InternedSet<'tcx, T> = Lock>>; pub struct CtxtInterners<'tcx> { @@ -462,15 +448,15 @@ impl<'tcx> TypeckTables<'tcx> { adjustments: ItemLocalMap(), pat_binding_modes: ItemLocalMap(), pat_adjustments: ItemLocalMap(), - upvar_capture_map: FxHashMap::default(), + upvar_capture_map: Default::default(), closure_kind_origins: ItemLocalMap(), liberated_fn_sigs: ItemLocalMap(), fru_field_types: ItemLocalMap(), cast_kinds: ItemLocalMap(), used_trait_imports: Lrc::new(DefIdSet()), tainted_by_errors: false, - free_region_map: FreeRegionMap::new(), - concrete_existential_types: FxHashMap::default(), + free_region_map: Default::default(), + concrete_existential_types: Default::default(), } } @@ -1231,14 +1217,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { extern_providers, on_disk_query_result_cache, ), - rcache: Lock::new(FxHashMap::default()), - selection_cache: traits::SelectionCache::new(), - evaluation_cache: traits::EvaluationCache::new(), + rcache: Default::default(), + selection_cache: Default::default(), + evaluation_cache: Default::default(), crate_name: Symbol::intern(crate_name), data_layout, - layout_interner: Lock::new(FxHashSet::default()), - stability_interner: Lock::new(FxHashSet::default()), - allocation_interner: Lock::new(FxHashSet::default()), + layout_interner: Default::default(), + stability_interner: Default::default(), + allocation_interner: Default::default(), alloc_map: Lock::new(interpret::AllocMap::new()), tx_to_llvm_workers: Lock::new(tx), output_filenames: Arc::new(output_filenames.clone()), diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index cdb0500ec61..80dfd263af9 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -753,7 +753,7 @@ impl LateBoundRegionsCollector { fn new(just_constrained: bool) -> Self { LateBoundRegionsCollector { current_index: ty::INNERMOST, - regions: FxHashSet::default(), + regions: Default::default(), just_constrained, } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index aba488095bd..760114a5838 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1841,8 +1841,7 @@ impl<'a> HashStable> for AdtDef { hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { thread_local! { - static CACHE: RefCell> = - RefCell::new(FxHashMap::default()); + static CACHE: RefCell> = Default::default(); } let hash: Fingerprint = CACHE.with(|cache| { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 7deb8d77c31..62bdf40317d 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -136,14 +136,14 @@ impl<'sess> OnDiskCache<'sess> { OnDiskCache { serialized_data: data, file_index_to_stable_id: footer.file_index_to_stable_id, - file_index_to_file: Lock::new(FxHashMap::default()), + file_index_to_file: Default::default(), prev_cnums: footer.prev_cnums, cnum_map: Once::new(), source_map: sess.source_map(), - current_diagnostics: Lock::new(FxHashMap::default()), + current_diagnostics: Default::default(), query_result_index: footer.query_result_index.into_iter().collect(), prev_diagnostics_index: footer.diagnostics_index.into_iter().collect(), - synthetic_expansion_infos: Lock::new(FxHashMap::default()), + synthetic_expansion_infos: Default::default(), alloc_decoding_state: AllocDecodingState::new(footer.interpret_alloc_index), } } @@ -151,15 +151,15 @@ impl<'sess> OnDiskCache<'sess> { pub fn new_empty(source_map: &'sess SourceMap) -> OnDiskCache<'sess> { OnDiskCache { serialized_data: Vec::new(), - file_index_to_stable_id: FxHashMap::default(), - file_index_to_file: Lock::new(FxHashMap::default()), + file_index_to_stable_id: Default::default(), + file_index_to_file: Default::default(), prev_cnums: vec![], cnum_map: Once::new(), source_map, - current_diagnostics: Lock::new(FxHashMap::default()), - query_result_index: FxHashMap::default(), - prev_diagnostics_index: FxHashMap::default(), - synthetic_expansion_infos: Lock::new(FxHashMap::default()), + current_diagnostics: Default::default(), + query_result_index: Default::default(), + prev_diagnostics_index: Default::default(), + synthetic_expansion_infos: Default::default(), alloc_decoding_state: AllocDecodingState::new(Vec::new()), } } @@ -190,10 +190,10 @@ impl<'sess> OnDiskCache<'sess> { let mut encoder = CacheEncoder { tcx, encoder, - type_shorthands: FxHashMap::default(), - predicate_shorthands: FxHashMap::default(), - expn_info_shorthands: FxHashMap::default(), - interpret_allocs: FxHashMap::default(), + type_shorthands: Default::default(), + predicate_shorthands: Default::default(), + expn_info_shorthands: Default::default(), + interpret_allocs: Default::default(), interpret_allocs_inverse: Vec::new(), source_map: CachingSourceMapView::new(tcx.sess.source_map()), file_to_file_index, diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 461acd72865..71e435fea77 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -55,8 +55,8 @@ impl QueryValue { } } -impl<'tcx, M: QueryConfig<'tcx>> QueryCache<'tcx, M> { - pub(super) fn new() -> QueryCache<'tcx, M> { +impl<'tcx, M: QueryConfig<'tcx>> Default for QueryCache<'tcx, M> { + fn default() -> QueryCache<'tcx, M> { QueryCache { results: FxHashMap::default(), active: FxHashMap::default(), @@ -699,7 +699,7 @@ macro_rules! define_queries_inner { providers, fallback_extern_providers: Box::new(fallback_extern_providers), on_disk_cache, - $($name: Lock::new(QueryCache::new())),* + $($name: Default::default()),* } } diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index 7946d5a047c..dbd3e00d9fd 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -22,9 +22,9 @@ pub use rustc_data_structures::fx::FxHashSet; macro_rules! define_id_collections { ($map_name:ident, $set_name:ident, $key:ty) => { pub type $map_name = FxHashMap<$key, T>; - pub fn $map_name() -> $map_name { FxHashMap::default() } + pub fn $map_name() -> $map_name { Default::default() } pub type $set_name = FxHashSet<$key>; - pub fn $set_name() -> $set_name { FxHashSet::default() } + pub fn $set_name() -> $set_name { Default::default() } } } diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 17deede5327..bfa2203cc04 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -182,7 +182,7 @@ impl PrintContext { fn prepare_late_bound_region_info<'tcx, T>(&mut self, value: &ty::Binder) where T: TypeFoldable<'tcx> { - let mut collector = LateBoundRegionNameCollector(FxHashSet::default()); + let mut collector = LateBoundRegionNameCollector(Default::default()); value.visit_with(&mut collector); self.used_region_names = Some(collector.0); self.region_index = 0; diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index ca69eb90c37..da5c5f47c08 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -103,7 +103,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) // tuple structs/variants) do not have an associated body // and do not need borrowchecking. return Lrc::new(BorrowCheckResult { - used_mut_nodes: FxHashSet::default(), + used_mut_nodes: Default::default(), signalled_any_error: SignalledError::NoErrorsSeen, }) } @@ -120,7 +120,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) region_scope_tree, owner_def_id, body, - used_mut_nodes: RefCell::new(FxHashSet::default()), + used_mut_nodes: Default::default(), signalled_any_error: Cell::new(SignalledError::NoErrorsSeen), }; @@ -235,7 +235,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( region_scope_tree, owner_def_id, body, - used_mut_nodes: RefCell::new(FxHashSet::default()), + used_mut_nodes: Default::default(), signalled_any_error: Cell::new(SignalledError::NoErrorsSeen), }; diff --git a/src/librustc_borrowck/borrowck/unused.rs b/src/librustc_borrowck/borrowck/unused.rs index 7d2bcd61e15..85794c5b10a 100644 --- a/src/librustc_borrowck/borrowck/unused.rs +++ b/src/librustc_borrowck/borrowck/unused.rs @@ -45,7 +45,7 @@ struct UnusedMutCx<'a, 'tcx: 'a> { impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> { fn check_unused_mut_pat(&self, pats: &[P]) { let tcx = self.bccx.tcx; - let mut mutables: FxHashMap<_, Vec<_>> = FxHashMap::default(); + let mut mutables: FxHashMap<_, Vec<_>> = Default::default(); for p in pats { p.each_binding(|_, hir_id, span, ident| { // Skip anything that looks like `_foo` diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index f648efb47df..61856236a14 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -502,7 +502,7 @@ fn thin_lto(cgcx: &CodegenContext, // If we don't compile incrementally, we don't need to load the // import data from LLVM. assert!(green_modules.is_empty()); - ThinLTOImports::new() + ThinLTOImports::default() }; info!("thin LTO import map loaded"); timeline.record("import-map-loaded"); @@ -873,19 +873,13 @@ impl ThinModule { } } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct ThinLTOImports { // key = llvm name of importing module, value = list of modules it imports from imports: FxHashMap>, } impl ThinLTOImports { - fn new() -> ThinLTOImports { - ThinLTOImports { - imports: FxHashMap::default(), - } - } - fn modules_imported_by(&self, llvm_module_name: &str) -> &[String] { self.imports.get(llvm_module_name).map(|v| &v[..]).unwrap_or(&[]) } @@ -910,9 +904,7 @@ impl ThinLTOImports { .unwrap() .push(imported_module_name.to_owned()); } - let mut map = ThinLTOImports { - imports: FxHashMap::default(), - }; + let mut map = ThinLTOImports::default(); llvm::LLVMRustGetThinLTOModuleImports(data, imported_module_callback, &mut map as *mut _ as *mut libc::c_void); diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 5356014f671..614a562846e 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -70,7 +70,7 @@ use time_graph; use mono_item::{MonoItem, BaseMonoItemExt, MonoItemExt}; use type_::Type; use type_of::LayoutLlvmExt; -use rustc::util::nodemap::{FxHashMap, FxHashSet, DefIdSet}; +use rustc::util::nodemap::{FxHashMap, DefIdSet}; use CrateInfo; use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::sync::Lrc; @@ -1030,7 +1030,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>( }).collect(); if tcx.sess.opts.debugging_opts.print_mono_items.is_some() { - let mut item_to_cgus: FxHashMap<_, Vec<_>> = FxHashMap::default(); + let mut item_to_cgus: FxHashMap<_, Vec<_>> = Default::default(); for cgu in &codegen_units { for (&mono_item, &linkage) in cgu.items() { @@ -1092,17 +1092,17 @@ impl CrateInfo { compiler_builtins: None, profiler_runtime: None, sanitizer_runtime: None, - is_no_builtins: FxHashSet::default(), - native_libraries: FxHashMap::default(), + is_no_builtins: Default::default(), + native_libraries: Default::default(), used_libraries: tcx.native_libraries(LOCAL_CRATE), link_args: tcx.link_args(LOCAL_CRATE), - crate_name: FxHashMap::default(), + crate_name: Default::default(), used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic), used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic), - used_crate_source: FxHashMap::default(), - wasm_imports: FxHashMap::default(), - lang_item_to_crate: FxHashMap::default(), - missing_lang_items: FxHashMap::default(), + used_crate_source: Default::default(), + wasm_imports: Default::default(), + lang_item_to_crate: Default::default(), + missing_lang_items: Default::default(), }; let lang_items = tcx.lang_items(); diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 559ca6f0dfe..826df82193a 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -295,22 +295,22 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> { llcx, stats: RefCell::new(Stats::default()), codegen_unit, - instances: RefCell::new(FxHashMap::default()), - vtables: RefCell::new(FxHashMap::default()), - const_cstr_cache: RefCell::new(FxHashMap::default()), - const_unsized: RefCell::new(FxHashMap::default()), - const_globals: RefCell::new(FxHashMap::default()), + instances: Default::default(), + vtables: Default::default(), + const_cstr_cache: Default::default(), + const_unsized: Default::default(), + const_globals: Default::default(), statics_to_rauw: RefCell::new(Vec::new()), used_statics: RefCell::new(Vec::new()), - lltypes: RefCell::new(FxHashMap::default()), - scalar_lltypes: RefCell::new(FxHashMap::default()), - pointee_infos: RefCell::new(FxHashMap::default()), + lltypes: Default::default(), + scalar_lltypes: Default::default(), + pointee_infos: Default::default(), isize_ty, dbg_cx, eh_personality: Cell::new(None), eh_unwind_resume: Cell::new(None), rust_try_fn: Cell::new(None), - intrinsics: RefCell::new(FxHashMap::default()), + intrinsics: Default::default(), local_gen_sym_counter: Cell::new(0), } } diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 3c4e000854e..846d5056411 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -96,6 +96,7 @@ pub struct UniqueTypeId(ast::Name); // created so far. The metadata nodes are indexed by UniqueTypeId, and, for // faster lookup, also by Ty. The TypeMap is responsible for creating // UniqueTypeIds. +#[derive(Default)] pub struct TypeMap<'ll, 'tcx> { // The UniqueTypeIds created so far unique_id_interner: Interner, @@ -108,15 +109,6 @@ pub struct TypeMap<'ll, 'tcx> { } impl TypeMap<'ll, 'tcx> { - pub fn new() -> Self { - TypeMap { - unique_id_interner: Interner::new(), - type_to_metadata: FxHashMap::default(), - unique_id_to_metadata: FxHashMap::default(), - type_to_unique_id: FxHashMap::default(), - } - } - // Adds a Ty to metadata mapping to the TypeMap. The method will fail if // the mapping already exists. fn register_type_with_metadata( diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 2cd44b2a6c4..042e72e921e 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -100,11 +100,11 @@ impl<'a, 'tcx> CrateDebugContext<'a, 'tcx> { llcontext, llmod, builder, - created_files: RefCell::new(FxHashMap::default()), - created_enum_disr_types: RefCell::new(FxHashMap::default()), - type_map: RefCell::new(TypeMap::new()), + created_files: Default::default(), + created_enum_disr_types: Default::default(), + type_map: Default::default(), namespace_map: RefCell::new(DefIdMap()), - composite_types_completed: RefCell::new(FxHashSet::default()), + composite_types_completed: Default::default(), } } } diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs index 48e1292d435..046f0cccfee 100644 --- a/src/librustc_codegen_utils/codegen_backend.rs +++ b/src/librustc_codegen_utils/codegen_backend.rs @@ -28,7 +28,6 @@ use std::path::Path; use std::sync::{mpsc, Arc}; use rustc_data_structures::owning_ref::OwningRef; -use rustc_data_structures::sync::Lrc; use flate2::Compression; use flate2::write::DeflateEncoder; @@ -42,7 +41,6 @@ use rustc::middle::cstore::EncodedMetadata; use rustc::middle::cstore::MetadataLoader; use rustc::dep_graph::DepGraph; use rustc_target::spec::Target; -use rustc_data_structures::fx::FxHashMap; use rustc_mir::monomorphize::collector; use link::out_filename; @@ -132,7 +130,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { ::symbol_names::provide(providers); providers.target_features_whitelist = |_tcx, _cnum| { - Lrc::new(FxHashMap::default()) // Just a dummy + Default::default() // Just a dummy }; providers.is_reachable_non_generic = |_tcx, _defid| true; providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new()); diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 5bc0404a3da..ccf2a7f8159 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -187,11 +187,11 @@ impl ObligationForest { pub fn new() -> ObligationForest { ObligationForest { nodes: vec![], - done_cache: FxHashSet::default(), - waiting_cache: FxHashMap::default(), + done_cache: Default::default(), + waiting_cache: Default::default(), scratch: Some(vec![]), obligation_tree_id_generator: (0..).map(|i| ObligationTreeId(i)), - error_cache: FxHashMap::default(), + error_cache: Default::default(), } } @@ -303,7 +303,7 @@ impl ObligationForest { self.error_cache .entry(node.obligation_tree_id) - .or_insert_with(|| FxHashSet::default()) + .or_default() .insert(node.obligation.as_predicate().clone()); } diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs index 26528f44345..f8663cd4fd4 100644 --- a/src/librustc_data_structures/snapshot_map/mod.rs +++ b/src/librustc_data_structures/snapshot_map/mod.rs @@ -35,16 +35,20 @@ enum UndoLog { Noop, } -impl SnapshotMap +impl Default for SnapshotMap where K: Hash + Clone + Eq { - pub fn new() -> Self { + fn default() -> Self { SnapshotMap { map: FxHashMap::default(), undo_log: vec![], } } +} +impl SnapshotMap + where K: Hash + Clone + Eq +{ pub fn clear(&mut self) { self.map.clear(); self.undo_log.clear(); diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index a2893a60cb6..6a4012c8198 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -133,7 +133,7 @@ cfg_if! { pub type MTRef<'a, T> = &'a mut T; - #[derive(Debug)] + #[derive(Debug, Default)] pub struct MTLock(T); impl MTLock { @@ -228,7 +228,7 @@ cfg_if! { pub type MTRef<'a, T> = &'a T; - #[derive(Debug)] + #[derive(Debug, Default)] pub struct MTLock(Lock); impl MTLock { diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index a48b6f381a5..3cc467aa038 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -51,8 +51,8 @@ struct Edge { target: Index, } -impl TransitiveRelation { - pub fn new() -> TransitiveRelation { +impl Default for TransitiveRelation { + fn default() -> TransitiveRelation { TransitiveRelation { elements: vec![], map: FxHashMap::default(), @@ -60,7 +60,9 @@ impl TransitiveRelation { closure: Lock::new(None), } } +} +impl TransitiveRelation { pub fn is_empty(&self) -> bool { self.edges.is_empty() } @@ -95,7 +97,7 @@ impl TransitiveRelation { where F: FnMut(&T) -> Option, U: Clone + Debug + Eq + Hash + Clone, { - let mut result = TransitiveRelation::new(); + let mut result = TransitiveRelation::default(); for edge in &self.edges { result.add(f(&self.elements[edge.source.0])?, f(&self.elements[edge.target.0])?); } diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index bec8d2997f7..f02a5e2bc5d 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -382,9 +382,9 @@ impl Handler { emitter: Lock::new(e), continue_after_error: LockCell::new(true), delayed_span_bugs: Lock::new(Vec::new()), - taught_diagnostics: Lock::new(FxHashSet::default()), - emitted_diagnostic_codes: Lock::new(FxHashSet::default()), - emitted_diagnostics: Lock::new(FxHashSet::default()), + taught_diagnostics: Default::default(), + emitted_diagnostic_codes: Default::default(), + emitted_diagnostics: Default::default(), } } @@ -398,7 +398,7 @@ impl Handler { /// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as /// the overall count of emitted error diagnostics. pub fn reset_err_count(&self) { - *self.emitted_diagnostics.borrow_mut() = FxHashSet::default(); + self.emitted_diagnostics.borrow_mut().clear(); self.err_count.store(0, SeqCst); } diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index fa5eda69f76..58a799bb45f 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -226,7 +226,7 @@ pub fn check_dirty_clean_annotations<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let krate = tcx.hir.krate(); let mut dirty_clean_visitor = DirtyCleanVisitor { tcx, - checked_attrs: FxHashSet::default(), + checked_attrs: Default::default(), }; krate.visit_all_item_likes(&mut dirty_clean_visitor); diff --git a/src/librustc_incremental/persist/load.rs b/src/librustc_incremental/persist/load.rs index e2eaa59d627..2f7e1af1ff6 100644 --- a/src/librustc_incremental/persist/load.rs +++ b/src/librustc_incremental/persist/load.rs @@ -48,7 +48,7 @@ impl LoadResult<(PreviousDepGraph, WorkProductMap)> { match self { LoadResult::Error { message } => { sess.warn(&message); - (PreviousDepGraph::new(SerializedDepGraph::new()), FxHashMap::default()) + Default::default() }, LoadResult::DataOutOfDate => { if let Err(err) = delete_all_session_dir_contents(sess) { @@ -56,7 +56,7 @@ impl LoadResult<(PreviousDepGraph, WorkProductMap)> { incremental compilation session directory contents `{}`: {}.", dep_graph_path(sess).display(), err)); } - (PreviousDepGraph::new(SerializedDepGraph::new()), FxHashMap::default()) + Default::default() } LoadResult::Ok { data } => data } @@ -117,7 +117,7 @@ pub fn load_dep_graph(sess: &Session) -> if sess.opts.incremental.is_none() { // No incremental compilation. return MaybeAsync::Sync(LoadResult::Ok { - data: (PreviousDepGraph::new(SerializedDepGraph::new()), FxHashMap::default()) + data: Default::default(), }); } diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs index f102417c345..2be9883d03d 100644 --- a/src/librustc_metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -111,7 +111,7 @@ impl CStore { // corresponding `CrateNum`. This first entry will always remain // `None`. metas: RwLock::new(IndexVec::from_elem_n(None, 1)), - extern_mod_crate_map: Lock::new(FxHashMap::default()), + extern_mod_crate_map: Default::default(), metadata_loader, } } diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 0514755d782..e7e6dd71a76 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -459,7 +459,7 @@ impl<'a> Context<'a> { let mut candidates: FxHashMap< _, (FxHashMap<_, _>, FxHashMap<_, _>, FxHashMap<_, _>), - > = FxHashMap::default(); + > = Default::default(); let mut staticlibs = vec![]; // First, find all possible candidate rlibs and dylibs purely based on diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 6096f992391..ab44ebc052f 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -151,11 +151,11 @@ impl<'tcx> BorrowSet<'tcx> { tcx, mir, idx_vec: IndexVec::new(), - location_map: FxHashMap::default(), - activation_map: FxHashMap::default(), - region_map: FxHashMap::default(), - local_map: FxHashMap::default(), - pending_activations: FxHashMap::default(), + location_map: Default::default(), + activation_map: Default::default(), + region_map: Default::default(), + local_map: Default::default(), + pending_activations: Default::default(), locals_state_at_exit: LocalsStateAtExit::build(locals_are_invalidated_at_exit, mir, move_data), }; diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 818b71ded37..6ef8b155458 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -252,13 +252,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( location_table, movable_generator, locals_are_invalidated_at_exit, - access_place_error_reported: FxHashSet::default(), - reservation_error_reported: FxHashSet::default(), + access_place_error_reported: Default::default(), + reservation_error_reported: Default::default(), move_error_reported: BTreeMap::new(), - uninitialized_error_reported: FxHashSet::default(), + uninitialized_error_reported: Default::default(), errors_buffer, nonlexical_regioncx: regioncx, - used_mut: FxHashSet::default(), + used_mut: Default::default(), used_mut_upvars: SmallVec::new(), borrow_set, dominators, diff --git a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs index 35342b2129e..f8c839e4d3f 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs @@ -80,8 +80,8 @@ crate fn create( region_bound_pairs: Vec::new(), relations: UniversalRegionRelations { universal_regions: universal_regions.clone(), - outlives: TransitiveRelation::new(), - inverse_outlives: TransitiveRelation::new(), + outlives: Default::default(), + inverse_outlives: Default::default(), }, }.create() } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index bdaea23d22b..9d9588dd9b9 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -128,7 +128,7 @@ pub(crate) fn type_check<'gcx, 'tcx>( let mut constraints = MirTypeckRegionConstraints { liveness_constraints: LivenessValues::new(elements), outlives_constraints: ConstraintSet::default(), - closure_bounds_mapping: FxHashMap::default(), + closure_bounds_mapping: Default::default(), type_tests: Vec::default(), }; let mut placeholder_indices = PlaceholderIndices::default(); @@ -847,7 +847,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { region_bound_pairs, implicit_region_bound, borrowck_context, - reported_errors: FxHashSet::default(), + reported_errors: Default::default(), universal_region_relations, } } diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 06e394775e8..c7da9c4fbd7 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -55,7 +55,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // these maps are empty to start; cases are // added below in add_cases_to_switch options: vec![], - indices: FxHashMap::default(), + indices: Default::default(), } } } diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index afb3d00d461..b3e62788256 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -358,7 +358,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { needs_cleanup: false, drops: vec![], cached_generator_drop: None, - cached_exits: FxHashMap::default(), + cached_exits: Default::default(), cached_unwind: CachedBlock::default(), }); } diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index c5b1353d74b..08696dc098e 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -11,7 +11,6 @@ use rustc::ty::{self, TyCtxt}; use rustc::mir::*; use rustc::mir::tcx::RvalueInitializationState; -use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{IndexVec}; use std::collections::hash_map::Entry; @@ -53,7 +52,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { v, ) }).collect(), - projections: FxHashMap::default(), + projections: Default::default(), }, move_paths, path_map, diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index aa1c6902dce..04a297d0a83 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -320,7 +320,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { f: F) -> R where F: for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R { - let pattern_arena = TypedArena::new(); + let pattern_arena = TypedArena::default(); f(MatchCheckCtxt { tcx, diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index d16d900b11a..3a1108bb169 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -703,7 +703,7 @@ fn internalize_symbols<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>, // Build a map from every monomorphization to all the monomorphizations that // reference it. - let mut accessor_map: FxHashMap, Vec>> = FxHashMap::default(); + let mut accessor_map: FxHashMap, Vec>> = Default::default(); inlining_map.iter_accesses(|accessor, accessees| { for accessee in accessees { accessor_map.entry(*accessee) diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 77e580d5855..ae881bad58d 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -57,7 +57,7 @@ impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { }, tcx, param_env, - used_unsafe: FxHashSet::default(), + used_unsafe: Default::default(), inherited_blocks: vec![], } } diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index 56da1919beb..4d3b422ab28 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -41,6 +41,7 @@ use transform::{MirPass, MirSource}; pub struct CleanEndRegions; +#[derive(Default)] struct GatherBorrowedRegions { seen_regions: FxHashSet, } @@ -56,9 +57,7 @@ impl MirPass for CleanEndRegions { mir: &mut Mir<'tcx>) { if !tcx.emit_end_regions() { return; } - let mut gather = GatherBorrowedRegions { - seen_regions: FxHashSet::default() - }; + let mut gather = GatherBorrowedRegions::default(); gather.visit_mir(mir); let mut delete = DeleteTrivialEndRegions { seen_regions: &mut gather.seen_regions }; @@ -139,6 +138,7 @@ impl<'tcx> MutVisitor<'tcx> for DeleteAscribeUserType { pub struct CleanFakeReadsAndBorrows; +#[derive(Default)] pub struct DeleteAndRecordFakeReads { fake_borrow_temporaries: FxHashSet, } @@ -153,9 +153,7 @@ impl MirPass for CleanFakeReadsAndBorrows { _tcx: TyCtxt<'a, 'tcx, 'tcx>, _source: MirSource, mir: &mut Mir<'tcx>) { - let mut delete_reads = DeleteAndRecordFakeReads { - fake_borrow_temporaries: FxHashSet::default(), - }; + let mut delete_reads = DeleteAndRecordFakeReads::default(); delete_reads.visit_mir(mir); let mut delete_borrows = DeleteFakeBorrows { fake_borrow_temporaries: delete_reads.fake_borrow_temporaries, diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index e748500cd3a..e1165e865ce 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -75,7 +75,7 @@ impl MirPass for ElaborateDrops { env: &env, flow_inits, flow_uninits, - drop_flags: FxHashMap::default(), + drop_flags: Default::default(), patch: MirPatch::new(mir), }.elaborate() }; diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 7faef65d994..25bd02ff6dc 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -536,7 +536,7 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>( writeln!(w, "{{")?; // construct a scope tree and write it out - let mut scope_tree: FxHashMap> = FxHashMap::default(); + let mut scope_tree: FxHashMap> = Default::default(); for (index, scope_data) in mir.source_scopes.iter().enumerate() { if let Some(parent) = scope_data.parent_scope { scope_tree diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c7e440ba567..0f96ee6a688 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -930,7 +930,7 @@ struct Rib<'a> { impl<'a> Rib<'a> { fn new(kind: RibKind<'a>) -> Rib<'a> { Rib { - bindings: FxHashMap::default(), + bindings: Default::default(), kind, } } @@ -1053,11 +1053,11 @@ impl<'a> ModuleData<'a> { parent, kind, normal_ancestor_id, - resolutions: RefCell::new(FxHashMap::default()), + resolutions: Default::default(), legacy_macro_resolutions: RefCell::new(Vec::new()), macro_resolutions: RefCell::new(Vec::new()), builtin_attrs: RefCell::new(Vec::new()), - unresolved_invocations: RefCell::new(FxHashSet::default()), + unresolved_invocations: Default::default(), no_implicit_prelude: false, glob_importers: RefCell::new(Vec::new()), globs: RefCell::new(Vec::new()), @@ -1315,13 +1315,14 @@ impl<'a> NameBinding<'a> { /// /// All other types are defined somewhere and possibly imported, but the primitive ones need /// special handling, since they have no place of origin. +#[derive(Default)] struct PrimitiveTypeTable { primitive_types: FxHashMap, } impl PrimitiveTypeTable { fn new() -> PrimitiveTypeTable { - let mut table = PrimitiveTypeTable { primitive_types: FxHashMap::default() }; + let mut table = PrimitiveTypeTable::default(); table.intern("bool", Bool); table.intern("char", Char); @@ -1482,6 +1483,7 @@ pub struct Resolver<'a, 'b: 'a> { } /// Nothing really interesting here, it just provides memory for the rest of the crate. +#[derive(Default)] pub struct ResolverArenas<'a> { modules: arena::TypedArena>, local_modules: RefCell>>, @@ -1782,15 +1784,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { } pub fn arenas() -> ResolverArenas<'a> { - ResolverArenas { - modules: arena::TypedArena::new(), - local_modules: RefCell::new(Vec::new()), - name_bindings: arena::TypedArena::new(), - import_directives: arena::TypedArena::new(), - name_resolutions: arena::TypedArena::new(), - invocation_data: arena::TypedArena::new(), - legacy_bindings: arena::TypedArena::new(), - } + Default::default() } /// Runs the function on each namespace. diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 7e1507b7e1f..a251269b21d 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -475,6 +475,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( }); // Now we build the substituted predicates. let default_obligations = predicates.predicates.iter().flat_map(|&(pred, _)| { + #[derive(Default)] struct CountParams { params: FxHashSet } impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams { fn visit_ty(&mut self, t: Ty<'tcx>) -> bool { @@ -491,7 +492,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( true } } - let mut param_count = CountParams { params: FxHashSet::default() }; + let mut param_count = CountParams::default(); let has_region = pred.visit_with(&mut param_count); let substituted_pred = pred.subst(fcx.tcx, substs); // Don't check non-defaulted params, dependent defaults (including lifetimes) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 934db4b4435..eb52a013b05 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -561,7 +561,7 @@ fn convert_variant<'a, 'tcx>( adt_kind: ty::AdtKind, attribute_def_id: DefId ) -> ty::VariantDef { - let mut seen_fields: FxHashMap = FxHashMap::default(); + let mut seen_fields: FxHashMap = Default::default(); let node_id = tcx.hir.as_local_node_id(did).unwrap(); let fields = def .fields() diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index 25f6b259e96..7cc56bc192b 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -48,7 +48,7 @@ pub fn provide(providers: &mut Providers) { fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> Lrc { assert_eq!(crate_num, LOCAL_CRATE); - let mut arena = arena::TypedArena::new(); + let mut arena = arena::TypedArena::default(); let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &mut arena); let constraints_cx = constraints::add_constraints_from_crate(terms_cx); Lrc::new(solve::solve_constraints(constraints_cx)) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 16b4347d7eb..26487605bac 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -178,7 +178,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { inner: ImplItem(Impl { unsafety: hir::Unsafety::Normal, generics: new_generics, - provided_trait_methods: FxHashSet::default(), + provided_trait_methods: Default::default(), trait_: Some(trait_.clean(self.cx)), for_: ty.clean(self.cx), items: Vec::new(), @@ -267,9 +267,9 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { // 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<_, Vec<_>> = FxHashMap::default(); + let mut finished: FxHashMap<_, Vec<_>> = Default::default(); - let mut vid_map: FxHashMap = FxHashMap::default(); + let mut vid_map: FxHashMap = Default::default(); // Flattening is done in two parts. First, we insert all of the constraints // into a map. Each RegionTarget (either a RegionVid or a Region) maps @@ -577,11 +577,11 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> { } = full_generics.clean(self.cx); let mut has_sized = FxHashSet::default(); - let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = FxHashMap::default(); - let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = FxHashMap::default(); - let mut ty_to_traits: FxHashMap> = FxHashMap::default(); + let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default(); + let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default(); + let mut ty_to_traits: FxHashMap> = Default::default(); - let mut ty_to_fn: FxHashMap, Option)> = FxHashMap::default(); + let mut ty_to_fn: FxHashMap, Option)> = Default::default(); for (orig_p, p) in clean_where_predicates { match p { diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index ad0b633d03a..49cecd5b04b 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -368,7 +368,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec) { .into_iter() .map(|meth| meth.ident.to_string()) .collect() - }).unwrap_or(FxHashSet::default()); + }).unwrap_or_default(); debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id()); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2f9baf2d3ee..db605e57735 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -75,8 +75,7 @@ use self::cfg::Cfg; use self::auto_trait::AutoTraitFinder; use self::blanket_impl::BlanketImplFinder; -thread_local!(pub static MAX_DEF_ID: RefCell> = - RefCell::new(FxHashMap::default())); +thread_local!(pub static MAX_DEF_ID: RefCell> = Default::default()); const FN_OUTPUT_NAME: &'static str = "Output"; @@ -3388,7 +3387,7 @@ impl Clean> for doctree::Impl { .into_iter() .map(|meth| meth.ident.to_string()) .collect() - }).unwrap_or(FxHashSet::default()); + }).unwrap_or_default(); ret.push(Item { name: None, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 14160e14bbc..49f13df64d6 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -539,9 +539,9 @@ pub fn run_core(search_paths: SearchPaths, lt_substs: Default::default(), impl_trait_bounds: Default::default(), send_trait: send_trait, - fake_def_ids: RefCell::new(FxHashMap::default()), - all_fake_def_ids: RefCell::new(FxHashSet::default()), - generated_synthetics: RefCell::new(FxHashSet::default()), + fake_def_ids: Default::default(), + all_fake_def_ids: Default::default(), + generated_synthetics: Default::default(), all_traits: tcx.all_traits(LOCAL_CRATE).to_vec(), }; debug!("crate: {:?}", tcx.hir.krate()); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d484df00f37..dda0f37c3f9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -513,7 +513,7 @@ pub fn run(mut krate: clean::Crate, src_root, passes, include_sources: true, - local_sources: FxHashMap::default(), + local_sources: Default::default(), issue_tracker_base_url: None, layout: layout::Layout { logo: String::new(), @@ -522,7 +522,7 @@ pub fn run(mut krate: clean::Crate, krate: krate.name.clone(), }, css_file_extension: css_file_extension.clone(), - created_dirs: RefCell::new(FxHashSet::default()), + created_dirs: Default::default(), sort_modules_alphabetically, themes, resource_suffix, @@ -591,29 +591,29 @@ pub fn run(mut krate: clean::Crate, .collect(); let mut cache = Cache { - impls: FxHashMap::default(), + impls: Default::default(), external_paths, exact_paths, - paths: FxHashMap::default(), - implementors: FxHashMap::default(), + paths: Default::default(), + implementors: Default::default(), stack: Vec::new(), parent_stack: Vec::new(), search_index: Vec::new(), parent_is_trait_impl: false, - extern_locations: FxHashMap::default(), - primitive_locations: FxHashMap::default(), + extern_locations: Default::default(), + primitive_locations: Default::default(), stripped_mod: false, access_levels, crate_version: krate.version.take(), orphan_impl_items: Vec::new(), orphan_trait_impls: Vec::new(), - traits: krate.external_traits.lock().replace(FxHashMap::default()), + traits: krate.external_traits.lock().replace(Default::default()), deref_trait_did, deref_mut_trait_did, owned_box_did, - masked_crates: mem::replace(&mut krate.masked_crates, FxHashSet::default()), + masked_crates: mem::replace(&mut krate.masked_crates, Default::default()), typarams: external_typarams, - aliases: FxHashMap::default(), + aliases: Default::default(), }; // Cache where all our extern crates are located diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index c1274e74059..5054f18b020 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -124,6 +124,7 @@ impl StableFilemapId { // SourceMap // +#[derive(Default)] pub(super) struct SourceMapFiles { pub(super) file_maps: Vec>, stable_id_to_source_file: FxHashMap> @@ -143,10 +144,7 @@ pub struct SourceMap { impl SourceMap { pub fn new(path_mapping: FilePathMapping) -> SourceMap { SourceMap { - files: Lock::new(SourceMapFiles { - file_maps: Vec::new(), - stable_id_to_source_file: FxHashMap::default(), - }), + files: Default::default(), file_loader: Box::new(RealFileLoader), path_mapping, doctest_offset: None, @@ -166,10 +164,7 @@ impl SourceMap { path_mapping: FilePathMapping) -> SourceMap { SourceMap { - files: Lock::new(SourceMapFiles { - file_maps: Vec::new(), - stable_id_to_source_file: FxHashMap::default(), - }), + files: Default::default(), file_loader: file_loader, path_mapping, doctest_offset: None, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index d412412fc65..361353c82e2 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -224,6 +224,7 @@ impl> PartialEq for Symbol { } // The &'static strs in this type actually point into the arena +#[derive(Default)] pub struct Interner { arena: DroplessArena, names: FxHashMap<&'static str, Symbol>, @@ -232,17 +233,8 @@ pub struct Interner { } impl Interner { - pub fn new() -> Self { - Interner { - arena: DroplessArena::new(), - names: Default::default(), - strings: Default::default(), - gensyms: Default::default(), - } - } - fn prefill(init: &[&str]) -> Self { - let mut this = Interner::new(); + let mut this = Interner::default(); for &string in init { if string == "" { // We can't allocate empty strings in the arena, so handle this here @@ -697,7 +689,7 @@ mod tests { #[test] fn interner_tests() { - let mut i: Interner = Interner::new(); + let mut i: Interner = Interner::default(); // first one is zero: assert_eq!(i.intern("dog"), Symbol(0)); // re-use gets the same entry: -- cgit 1.4.1-3-g733a5