diff --git a/src/Cargo.lock b/src/Cargo.lock index e7b42a038a3..0dd693e7217 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -659,6 +659,14 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ena" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "env_logger" version = "0.5.12" @@ -2196,7 +2204,7 @@ name = "rustc_data_structures" version = "0.0.0" dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ena 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "graphviz 0.0.0", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3261,6 +3269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" "checksum elasticlunr-rs 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4837d77a1e157489a3933b743fd774ae75074e0e390b2b7f071530048a0d87ee" +"checksum ena 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "25b4e5febb25f08c49f1b07dc33a182729a6b21edfb562b5aef95f78e0dbe5bb" "checksum ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dc8393b3c7352f94092497f6b52019643e493b6b890eb417cdb7c46117e621" "checksum env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)" = "f4d7e69c283751083d53d01eac767407343b8b69c4bd70058e08adc2637cb257" "checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e" diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index ddc5676c74e..63b749c548e 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(Default::default()), + dep_node_debug: Default::default(), current: Lock::new(CurrentDepGraph::new()), previous: prev_graph, colors: Lock::new(DepNodeColorMap::new(prev_graph_node_count)), - loaded_from_cache: Lock::new(Default::default()), + loaded_from_cache: Default::default(), })), fingerprints: Lrc::new(Lock::new(fingerprints)), } diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 6be7444136e..eb9bd183fd9 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -36,6 +36,7 @@ use util::nodemap::NodeMap; /// Internally the DefPathTable holds a tree of DefKeys, where each DefKey /// stores the DefIndex of its parent. /// There is one DefPathTable for each crate. +#[derive(Default)] pub struct DefPathTable { index_to_key: [Vec; 2], def_path_hashes: [Vec; 2], @@ -153,7 +154,7 @@ impl Decodable for DefPathTable { /// The definition table containing node definitions. /// It holds the DefPathTable for local DefIds/DefPaths and it also stores a /// mapping from NodeIds to local DefIds. -#[derive(Clone)] +#[derive(Clone, Default)] pub struct Definitions { table: DefPathTable, node_to_def_index: NodeMap, @@ -412,20 +413,8 @@ impl Definitions { /// ascending order. /// /// FIXME: there is probably a better place to put this comment. - pub fn new() -> Definitions { - Definitions { - table: DefPathTable { - index_to_key: [vec![], vec![]], - def_path_hashes: [vec![], vec![]], - }, - node_to_def_index: Default::default(), - def_index_to_node: [vec![], vec![]], - node_to_hir_id: IndexVec::new(), - parent_modules_of_macro_defs: Default::default(), - expansions_that_defined: Default::default(), - next_disambiguator: Default::default(), - def_index_to_span: Default::default(), - } + pub fn new() -> Self { + Self::default() } pub fn def_path_table(&self) -> &DefPathTable { diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 1c7c1b854da..7c623a1874e 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -369,8 +369,7 @@ impl<'a> HashStable> for Span { // times, we cache a stable hash of it and hash that instead of // recursing every time. thread_local! { - static CACHE: RefCell> = - RefCell::new(Default::default()); + static CACHE: RefCell> = Default::default(); } let sub_hash: u64 = CACHE.with(|cache| { diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index 46b12d01829..391bfc428c3 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -29,6 +29,7 @@ use std::{cmp, fmt, mem, u32}; mod taint; +#[derive(Default)] pub struct RegionConstraintCollector<'tcx> { /// For each `RegionVid`, the corresponding `RegionVariableOrigin`. var_infos: IndexVec, @@ -341,17 +342,8 @@ impl TaintDirections { } impl<'tcx> RegionConstraintCollector<'tcx> { - pub fn new() -> RegionConstraintCollector<'tcx> { - RegionConstraintCollector { - var_infos: VarInfos::default(), - data: RegionConstraintData::default(), - lubs: Default::default(), - glbs: Default::default(), - bound_count: 0, - undo_log: Vec::new(), - unification_table: ut::UnificationTable::new(), - any_unifications: false, - } + pub fn new() -> Self { + Self::default() } pub fn num_region_vars(&self) -> usize { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 8acbaaa844d..469d77403a3 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1233,7 +1233,7 @@ pub fn check_ast_crate( let (passes, buffered) = if pre_expansion { ( sess.lint_store.borrow_mut().pre_expansion_passes.take(), - LintBuffer::new(), + LintBuffer::default(), ) } else { ( diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index c43cdb24c33..4b878b86252 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -490,15 +490,12 @@ mod levels; pub use self::levels::{LintLevelSets, LintLevelMap}; +#[derive(Default)] pub struct LintBuffer { map: NodeMap>, } impl LintBuffer { - pub fn new() -> LintBuffer { - LintBuffer { map: ::std::default::Default::default() } - } - pub fn add_lint(&mut self, lint: &'static Lint, id: ast::NodeId, diff --git a/src/librustc/middle/borrowck.rs b/src/librustc/middle/borrowck.rs index c8d513a59f0..633c5841378 100644 --- a/src/librustc/middle/borrowck.rs +++ b/src/librustc/middle/borrowck.rs @@ -18,9 +18,15 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, #[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] pub enum SignalledError { SawSomeError, NoErrorsSeen } +impl Default for SignalledError { + fn default() -> SignalledError { + SignalledError::NoErrorsSeen + } +} + impl_stable_hash_for!(enum self::SignalledError { SawSomeError, NoErrorsSeen }); -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, Default, RustcEncodable, RustcDecodable)] pub struct BorrowCheckResult { pub used_mut_nodes: FxHashSet, pub signalled_any_error: SignalledError, diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index b7f4e380815..6ff450508d1 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -2741,9 +2741,7 @@ fn insert_late_bound_lifetimes( constrained_by_input.visit_ty(arg_ty); } - let mut appears_in_output = AllCollector { - regions: Default::default(), - }; + let mut appears_in_output = AllCollector::default(); intravisit::walk_fn_ret_ty(&mut appears_in_output, &decl.output); debug!( @@ -2755,9 +2753,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: Default::default(), - }; + let mut appears_in_where_clause = AllCollector::default(); appears_in_where_clause.visit_generics(generics); for param in &generics.params { @@ -2854,6 +2850,7 @@ fn insert_late_bound_lifetimes( } } + #[derive(Default)] struct AllCollector { regions: FxHashSet, } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 8582900b72c..d688d93b808 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -1149,7 +1149,7 @@ pub fn build_session_( local_crate_source_file, working_dir, lint_store: RwLock::new(lint::LintStore::new()), - buffered_lints: Lock::new(Some(lint::LintBuffer::new())), + buffered_lints: Lock::new(Some(Default::default())), one_time_diagnostics: Default::default(), plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())), plugin_attributes: OneThread::new(RefCell::new(Vec::new())), diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index dfdffa2d547..ad200449f89 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -3183,7 +3183,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { /// rather, you should request the vector for a specific type via /// `tcx.inherent_impls(def_id)` so as to minimize your dependencies /// (constructing this map requires touching the entire crate). -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct CrateInherentImpls { pub inherent_impls: DefIdMap>>, } diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 10dd1de8b78..0463da00c89 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -64,7 +64,7 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { - return Lrc::new(Default::default()) + return Default::default(); } // Check to see if this crate is a "special runtime crate". These diff --git a/src/librustc_data_structures/Cargo.toml b/src/librustc_data_structures/Cargo.toml index 79f073d643d..5b3dd38adf2 100644 --- a/src/librustc_data_structures/Cargo.toml +++ b/src/librustc_data_structures/Cargo.toml @@ -9,7 +9,7 @@ path = "lib.rs" crate-type = ["dylib"] [dependencies] -ena = "0.9.3" +ena = "0.10.1" log = "0.4" rustc_cratesio_shim = { path = "../librustc_cratesio_shim" } serialize = { path = "../libserialize" } diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs index f8663cd4fd4..0b42cb1eddd 100644 --- a/src/librustc_data_structures/snapshot_map/mod.rs +++ b/src/librustc_data_structures/snapshot_map/mod.rs @@ -23,6 +23,18 @@ pub struct SnapshotMap undo_log: Vec>, } +// HACK(eddyb) manual impl avoids `Default` bounds on `K` and `V`. +impl Default for SnapshotMap + where K: Hash + Clone + Eq +{ + fn default() -> Self { + SnapshotMap { + map: Default::default(), + undo_log: Default::default(), + } + } +} + pub struct Snapshot { len: usize, } @@ -35,17 +47,6 @@ enum UndoLog { Noop, } -impl Default for SnapshotMap - where K: Hash + Clone + Eq -{ - fn default() -> Self { - SnapshotMap { - map: FxHashMap::default(), - undo_log: vec![], - } - } -} - impl SnapshotMap where K: Hash + Clone + Eq { diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index e1318eb54d5..fd5dfab9e61 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -42,6 +42,18 @@ pub struct TransitiveRelation { closure: Lock>>, } +// HACK(eddyb) manual impl avoids `Default` bound on `T`. +impl Default for TransitiveRelation { + fn default() -> Self { + TransitiveRelation { + elements: Default::default(), + map: Default::default(), + edges: Default::default(), + closure: Default::default(), + } + } +} + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] struct Index(usize); @@ -51,17 +63,6 @@ struct Edge { target: Index, } -impl Default for TransitiveRelation { - fn default() -> TransitiveRelation { - TransitiveRelation { - elements: vec![], - map: FxHashMap::default(), - edges: vec![], - closure: Lock::new(None), - } - } -} - impl TransitiveRelation { pub fn is_empty(&self) -> bool { self.edges.is_empty() diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 79e4abc4c0e..d9dff144129 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -22,7 +22,6 @@ use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::{self, CrateInherentImpls, TyCtxt}; -use rustc::util::nodemap::DefIdMap; use rustc_data_structures::sync::Lrc; use syntax::ast; @@ -37,9 +36,7 @@ pub fn crate_inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let krate = tcx.hir.krate(); let mut collect = InherentCollect { tcx, - impls_map: CrateInherentImpls { - inherent_impls: DefIdMap::default() - } + impls_map: Default::default(), }; krate.visit_all_item_likes(&mut collect); Lrc::new(collect.impls_map)