From 5deed7304ef055ad45b71554f51dd28d0a79e105 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 4 Apr 2018 10:06:19 +0200 Subject: [PATCH 1/3] Use Rc instead of Rc in HashMap docs --- src/libstd/collections/hash/map.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 452fa4e471c69..287f34023cd8f 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2416,14 +2416,14 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// use std::collections::hash_map::{Entry, HashMap}; /// use std::rc::Rc; /// - /// let mut map: HashMap, u32> = HashMap::new(); - /// map.insert(Rc::new("Stringthing".to_string()), 15); + /// let mut map: HashMap, u32> = HashMap::new(); + /// map.insert("Stringthing".into(), 15); /// - /// let my_key = Rc::new("Stringthing".to_string()); + /// let my_key: Rc = "Stringthing".into(); /// /// if let Entry::Occupied(entry) = map.entry(my_key) { /// // Also replace the key with a handle to our other key. - /// let (old_key, old_value): (Rc, u32) = entry.replace_entry(16); + /// let (old_key, old_value): (Rc, u32) = entry.replace_entry(16); /// } /// /// ``` @@ -2446,14 +2446,14 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// use std::collections::hash_map::{Entry, HashMap}; /// use std::rc::Rc; /// - /// let mut map: HashMap, u32> = HashMap::new(); - /// let mut known_strings: Vec> = Vec::new(); + /// let mut map: HashMap, u32> = HashMap::new(); + /// let mut known_strings: Vec> = Vec::new(); /// /// // Initialise known strings, run program, etc. /// /// reclaim_memory(&mut map, &known_strings); /// - /// fn reclaim_memory(map: &mut HashMap, u32>, known_strings: &[Rc] ) { + /// fn reclaim_memory(map: &mut HashMap, u32>, known_strings: &[Rc] ) { /// for s in known_strings { /// if let Entry::Occupied(entry) = map.entry(s.clone()) { /// // Replaces the entry's key with our version of it in `known_strings`. From 8ac8ba66286868b830deb982cd41d96835c13cc1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 4 Apr 2018 10:09:52 +0200 Subject: [PATCH 2/3] Use Lrc<[u8]/str> instead of Lrc/String> in libsyntax --- src/libsyntax/ast.rs | 2 +- src/libsyntax/ext/source_util.rs | 3 +-- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax/parse/mod.rs | 6 +++--- src/libsyntax_pos/lib.rs | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c90b0aecfc044..e1a1424e8049c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1299,7 +1299,7 @@ pub enum LitKind { /// A string literal (`"foo"`) Str(Symbol, StrStyle), /// A byte string (`b"foo"`) - ByteStr(Lrc>), + ByteStr(Lrc<[u8]>), /// A byte char (`b'f'`) Byte(u8), /// A character literal (`'a'`) diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index d6dce63ea5e4b..10da98291ad73 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -24,7 +24,6 @@ use util::small_vector::SmallVector; use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; -use rustc_data_structures::sync::Lrc; // These macros all relate to the file system; they either return // the column/row/filename of the expression, or they include @@ -184,7 +183,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke // dependency information, but don't enter it's contents cx.codemap().new_filemap_and_lines(&file, ""); - base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) + base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::from(bytes)))) } } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 068929c8948df..4eec58f08e6cc 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -61,7 +61,7 @@ pub struct StringReader<'a> { pub fatal_errs: Vec>, // cache a direct reference to the source text, so that we don't have to // retrieve it via `self.filemap.src.as_ref().unwrap()` all the time. - source_text: Lrc, + source_text: Lrc, /// Stack of open delimiters and their spans. Used for error message. token: token::Token, span: Span, diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 1483691a1eaee..c1357bb158534 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -428,7 +428,7 @@ pub fn lit_token(lit: token::Lit, suf: Option, diag: Option<(Span, &Hand (true, Some(LitKind::ByteStr(byte_str_lit(&i.as_str())))) } token::ByteStrRaw(i, _) => { - (true, Some(LitKind::ByteStr(Lrc::new(i.to_string().into_bytes())))) + (true, Some(LitKind::ByteStr(Lrc::from(i.as_str().as_bytes())))) } } } @@ -502,7 +502,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) { } } -pub fn byte_str_lit(lit: &str) -> Lrc> { +pub fn byte_str_lit(lit: &str) -> Lrc<[u8]> { let mut res = Vec::with_capacity(lit.len()); let error = |i| format!("lexer should have rejected {} at {}", lit, i); @@ -558,7 +558,7 @@ pub fn byte_str_lit(lit: &str) -> Lrc> { } } - Lrc::new(res) + Lrc::from(res) } pub fn integer_lit(s: &str, suffix: Option, diag: Option<(Span, &Handler)>) diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index eb345200f413d..5ab5537409b2a 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -705,7 +705,7 @@ pub struct FileMap { /// Indicates which crate this FileMap was imported from. pub crate_of_origin: u32, /// The complete source code - pub src: Option>, + pub src: Option>, /// The source code's hash pub src_hash: u128, /// The external source code (used for external crates, which will have a `None` @@ -891,7 +891,7 @@ impl FileMap { name_was_remapped, unmapped_path: Some(unmapped_path), crate_of_origin: 0, - src: Some(Lrc::new(src)), + src: Some(Lrc::from(src)), src_hash, external_src: Lock::new(ExternalSource::Unneeded), start_pos, From 639abc9579698389207b1634784a91a326f9d163 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 4 Apr 2018 10:38:20 +0200 Subject: [PATCH 3/3] Use Lrc<[T]> instead of Lrc> in librustc There is one instace where Lrc::get_mut().unwrap() is used on the reference to make a push, this cannot be converted. One instance of Lrc::make_mut() was removed -- the side effect of changing the original vector cannot have mattered since make_mut() might have cloned it. --- src/librustc/middle/cstore.rs | 5 ++-- src/librustc/middle/resolve_lifetime.rs | 4 +-- src/librustc/traits/mod.rs | 6 ++-- src/librustc/ty/context.rs | 18 +++++------ src/librustc/ty/maps/mod.rs | 40 ++++++++++++------------- src/librustc/ty/mod.rs | 9 +++--- src/librustc/ty/relate.rs | 2 +- src/librustc_metadata/cstore_impl.rs | 32 ++++++++++---------- src/librustc_metadata/encoder.rs | 2 +- src/librustc_traits/lowering.rs | 14 ++++----- src/librustc_trans/attributes.rs | 2 +- src/librustc_trans/lib.rs | 8 ++--- src/librustc_typeck/variance/mod.rs | 2 +- src/librustc_typeck/variance/solve.rs | 6 ++-- src/librustdoc/clean/mod.rs | 2 +- src/libsyntax/ext/source_util.rs | 1 + 16 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index add9b621596b6..64c4cf9c761f3 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -399,10 +399,9 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference) Some((cnum, path)) }) .collect::>(); - let mut ordering = tcx.postorder_cnums(LOCAL_CRATE); - Lrc::make_mut(&mut ordering).reverse(); + let ordering = tcx.postorder_cnums(LOCAL_CRATE); libs.sort_by_key(|&(a, _)| { - ordering.iter().position(|x| *x == a) + ordering.iter().rev().position(|x| *x == a) }); libs } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index ceda72dcd7ae0..ee5ad9d78bd2c 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -217,7 +217,7 @@ pub struct ResolveLifetimes { defs: FxHashMap>>, late_bound: FxHashMap>>, object_lifetime_defaults: - FxHashMap>>>>, + FxHashMap>>>, } impl_stable_hash_for!(struct ::middle::resolve_lifetime::ResolveLifetimes { @@ -406,7 +406,7 @@ fn resolve_lifetimes<'tcx>( .or_insert_with(|| Lrc::new(FxHashMap())); Lrc::get_mut(map) .unwrap() - .insert(hir_id.local_id, Lrc::new(v)); + .insert(hir_id.local_id, Lrc::from(v)); } Lrc::new(ResolveLifetimes { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 2ce1b75e3151f..0c510226a6dcd 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -803,11 +803,11 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx fn vtable_methods<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) - -> Lrc)>>> + -> Lrc<[Option<(DefId, &'tcx Substs<'tcx>)>]> { debug!("vtable_methods({:?})", trait_ref); - Lrc::new( + Lrc::from( supertraits(tcx, trait_ref).flat_map(move |trait_ref| { let trait_methods = tcx.associated_items(trait_ref.def_id()) .filter(|item| item.kind == ty::AssociatedKind::Method); @@ -850,7 +850,7 @@ fn vtable_methods<'a, 'tcx>( Some((def_id, substs)) }) - }).collect() + }).collect::>() ) } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index fdda2286da03b..968d2abd3e839 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -846,7 +846,7 @@ pub struct GlobalCtxt<'tcx> { Lrc>>>>, /// Export map produced by name resolution. - export_map: FxHashMap>>, + export_map: FxHashMap>, pub hir: hir_map::Map<'tcx>, @@ -859,7 +859,7 @@ pub struct GlobalCtxt<'tcx> { // Records the free variables refrenced by every closure // expression. Do not track deps for this, just recompute it from // scratch every time. - freevars: FxHashMap>>, + freevars: FxHashMap>, maybe_unused_trait_imports: FxHashSet, @@ -1254,10 +1254,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { types: common_types, trait_map, export_map: resolutions.export_map.into_iter().map(|(k, v)| { - (k, Lrc::new(v)) + (k, Lrc::from(v)) }).collect(), freevars: resolutions.freevars.into_iter().map(|(k, v)| { - (hir.local_def_id(k), Lrc::new(v)) + (hir.local_def_id(k), Lrc::from(v)) }).collect(), maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports @@ -1335,7 +1335,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.stability_index(LOCAL_CRATE) } - pub fn crates(self) -> Lrc> { + pub fn crates(self) -> Lrc<[CrateNum]> { self.all_crate_nums(LOCAL_CRATE) } @@ -2450,7 +2450,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn object_lifetime_defaults(self, id: HirId) - -> Option>> + -> Option> { self.object_lifetime_defaults_map(id.owner) .and_then(|map| map.get(&id.local_id).cloned()) @@ -2529,7 +2529,7 @@ pub fn provide(providers: &mut ty::maps::Providers) { }; providers.maybe_unused_extern_crates = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); - Lrc::new(tcx.maybe_unused_extern_crates.clone()) + Lrc::from(tcx.maybe_unused_extern_crates.clone()) }; providers.stability_index = |tcx, cnum| { @@ -2552,11 +2552,11 @@ pub fn provide(providers: &mut ty::maps::Providers) { }; providers.all_crate_nums = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); - Lrc::new(tcx.cstore.crates_untracked()) + Lrc::from(tcx.cstore.crates_untracked()) }; providers.postorder_cnums = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); - Lrc::new(tcx.cstore.postorder_cnums_untracked()) + Lrc::from(tcx.cstore.postorder_cnums_untracked()) }; providers.output_filenames = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); diff --git a/src/librustc/ty/maps/mod.rs b/src/librustc/ty/maps/mod.rs index 2bfb687032923..11bfb1b28ef14 100644 --- a/src/librustc/ty/maps/mod.rs +++ b/src/librustc/ty/maps/mod.rs @@ -132,13 +132,13 @@ define_maps! { <'tcx> /// Maps from def-id of a type or region parameter to its /// (inferred) variance. - [] fn variances_of: ItemVariances(DefId) -> Lrc>, + [] fn variances_of: ItemVariances(DefId) -> Lrc<[ty::Variance]>, /// Maps from def-id of a type to its (inferred) outlives. [] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Vec>, /// Maps from an impl/trait def-id to a list of the def-ids of its items - [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc>, + [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<[DefId]>, /// Maps from a trait item to the trait item "descriptor" [] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem, @@ -252,7 +252,7 @@ define_maps! { <'tcx> [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc, [] fn is_mir_available: IsMirAvailable(DefId) -> bool, [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>) - -> Lrc)>>>, + -> Lrc<[Option<(DefId, &'tcx Substs<'tcx>)>]>, [] fn trans_fulfill_obligation: fulfill_obligation_dep_node( (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>, @@ -279,7 +279,7 @@ define_maps! { <'tcx> ty::layout::LayoutError<'tcx>>, [] fn dylib_dependency_formats: DylibDepFormats(CrateNum) - -> Lrc>, + -> Lrc<[(CrateNum, LinkagePreference)]>, [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool, [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool, @@ -294,7 +294,7 @@ define_maps! { <'tcx> [] fn specializes: specializes_node((DefId, DefId)) -> bool, [] fn in_scope_traits_map: InScopeTraits(DefIndex) -> Option>>>>, - [] fn module_exports: ModuleExports(DefId) -> Option>>, + [] fn module_exports: ModuleExports(DefId) -> Option>, [] fn lint_levels: lint_levels_node(CrateNum) -> Lrc, [] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness, @@ -319,9 +319,9 @@ define_maps! { <'tcx> [] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool, - [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc>, + [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<[NativeLibrary]>, - [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc>, + [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<[ForeignModule]>, [] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option, [] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option, @@ -330,9 +330,9 @@ define_maps! { <'tcx> [] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol, [] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId)) - -> Lrc>, + -> Lrc<[DefId]>, [] fn all_trait_implementations: AllTraitImplementations(CrateNum) - -> Lrc>, + -> Lrc<[DefId]>, [] fn dllimport_foreign_items: DllimportForeignItems(CrateNum) -> Lrc>, @@ -340,7 +340,7 @@ define_maps! { <'tcx> [] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool, [] fn native_library_kind: NativeLibraryKind(DefId) -> Option, - [] fn link_args: link_args_node(CrateNum) -> Lrc>, + [] fn link_args: link_args_node(CrateNum) -> Lrc<[String]>, // Lifetime resolution. See `middle::resolve_lifetimes`. [] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc, @@ -349,31 +349,31 @@ define_maps! { <'tcx> [] fn is_late_bound_map: IsLateBound(DefIndex) -> Option>>, [] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex) - -> Option>>>>, + -> Option>>>, [] fn visibility: Visibility(DefId) -> ty::Visibility, [] fn dep_kind: DepKind(CrateNum) -> DepKind, [] fn crate_name: CrateName(CrateNum) -> Symbol, - [] fn item_children: ItemChildren(DefId) -> Lrc>, + [] fn item_children: ItemChildren(DefId) -> Lrc<[Export]>, [] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option, [] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc, - [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc>, - [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc>, + [] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<[(DefId, usize)]>, + [] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<[LangItem]>, [] fn extern_const_body: ExternConstBody(DefId) -> ExternConstBody<'tcx>, [] fn visible_parent_map: visible_parent_map_node(CrateNum) -> Lrc>, [] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool, [] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc, - [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc>, + [] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<[CrateNum]>, - [] fn freevars: Freevars(DefId) -> Option>>, + [] fn freevars: Freevars(DefId) -> Option>, [] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool, [] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum) - -> Lrc>, + -> Lrc<[(DefId, Span)]>, [] fn stability_index: stability_index_node(CrateNum) -> Lrc>, - [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc>, + [] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<[CrateNum]>, [] fn exported_symbols: ExportedSymbols(CrateNum) -> Arc>, @@ -425,9 +425,9 @@ define_maps! { <'tcx> [] fn features_query: features_node(CrateNum) -> Lrc, - [] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc>>, + [] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<[Clause<'tcx>]>, - [] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc>, + [] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<[DefId]>, [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum) -> Lrc>, } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 72ba199eb2412..996f786e9e603 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -337,10 +337,10 @@ pub struct CrateVariancesMap { /// For each item with generics, maps to a vector of the variance /// of its generics. If an item has no generics, it will have no /// entry. - pub variances: FxHashMap>>, + pub variances: FxHashMap>, /// An empty vector, useful for cloning. - pub empty_variance: Lrc>, + pub empty_variance: Lrc<[ty::Variance]>, } impl Variance { @@ -2641,7 +2641,7 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Lrc> { + -> Lrc<[DefId]> { let id = tcx.hir.as_local_node_id(def_id).unwrap(); let item = tcx.hir.expect_item(id); let vec: Vec<_> = match item.node { @@ -2660,7 +2660,7 @@ fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir::ItemTraitAlias(..) => vec![], _ => span_bug!(item.span, "associated_item_def_ids: not impl or trait") }; - Lrc::new(vec) + Lrc::from(vec) } fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span { @@ -2772,6 +2772,7 @@ pub fn provide(providers: &mut ty::maps::Providers) { /// (constructing this map requires touching the entire crate). #[derive(Clone, Debug)] pub struct CrateInherentImpls { + // Note: needs to be a Lrc> since get_mut().push() is used pub inherent_impls: DefIdMap>>, } diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 36eb3e3f94cfa..e14c0a311085f 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -131,7 +131,7 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> { } pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, - variances: Option<&Vec>, + variances: Option<&[ty::Variance]>, a_subst: &'tcx Substs<'tcx>, b_subst: &'tcx Substs<'tcx>) -> RelateResult<'tcx, &'tcx Substs<'tcx>> diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 5fd8ebaa9b4a6..9d3f16b0f4973 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -115,12 +115,12 @@ provide! { <'tcx> tcx, def_id, other, cdata, let _ = cdata; tcx.calculate_dtor(def_id, &mut |_,_| Ok(())) } - variances_of => { Lrc::new(cdata.get_item_variances(def_id.index)) } + variances_of => { Lrc::from(cdata.get_item_variances(def_id.index)) } associated_item_def_ids => { let mut result = vec![]; cdata.each_child_of_item(def_id.index, |child| result.push(child.def.def_id()), tcx.sess); - Lrc::new(result) + Lrc::from(result) } associated_item => { cdata.get_associated_item(def_id.index) } impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) } @@ -144,7 +144,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, } typeck_tables_of => { cdata.item_body_tables(def_id.index, tcx) } fn_sig => { cdata.fn_sig(def_id.index, tcx) } - inherent_impls => { Lrc::new(cdata.get_inherent_implementations_for_type(def_id.index)) } + inherent_impls => { Lrc::from(cdata.get_inherent_implementations_for_type(def_id.index)) } is_const_fn => { cdata.is_const_fn(def_id.index) } is_foreign_item => { cdata.is_foreign_item(def_id.index) } describe_def => { cdata.get_def(def_id.index) } @@ -169,7 +169,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, } is_mir_available => { cdata.is_item_mir_available(def_id.index) } - dylib_dependency_formats => { Lrc::new(cdata.get_dylib_dependency_formats()) } + dylib_dependency_formats => { Lrc::from(cdata.get_dylib_dependency_formats()) } is_panic_runtime => { cdata.is_panic_runtime(tcx.sess) } is_compiler_builtins => { cdata.is_compiler_builtins(tcx.sess) } has_global_allocator => { cdata.has_global_allocator() } @@ -197,8 +197,8 @@ provide! { <'tcx> tcx, def_id, other, cdata, Lrc::new(reachable_non_generics) } - native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) } - foreign_modules => { Lrc::new(cdata.get_foreign_modules(tcx.sess)) } + native_libraries => { Lrc::from(cdata.get_native_libraries(tcx.sess)) } + foreign_modules => { Lrc::from(cdata.get_foreign_modules(tcx.sess)) } plugin_registrar_fn => { cdata.root.plugin_registrar_fn.map(|index| { DefId { krate: def_id.krate, index } @@ -217,13 +217,13 @@ provide! { <'tcx> tcx, def_id, other, cdata, let mut result = vec![]; let filter = Some(other); cdata.get_implementations_for_trait(filter, &mut result); - Lrc::new(result) + Lrc::from(result) } all_trait_implementations => { let mut result = vec![]; cdata.get_implementations_for_trait(None, &mut result); - Lrc::new(result) + Lrc::from(result) } visibility => { cdata.get_visibility(def_id.index) } @@ -235,10 +235,10 @@ provide! { <'tcx> tcx, def_id, other, cdata, item_children => { let mut result = vec![]; cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess); - Lrc::new(result) + Lrc::from(result) } - defined_lang_items => { Lrc::new(cdata.get_lang_items()) } - missing_lang_items => { Lrc::new(cdata.get_missing_lang_items()) } + defined_lang_items => { Lrc::from(cdata.get_lang_items()) } + missing_lang_items => { Lrc::from(cdata.get_missing_lang_items()) } extern_const_body => { debug!("item_body({:?}): inlining item", def_id); @@ -268,7 +268,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, Arc::new(cdata.exported_symbols()) } - wasm_custom_sections => { Lrc::new(cdata.wasm_custom_sections()) } + wasm_custom_sections => { Lrc::from(cdata.wasm_custom_sections()) } } pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { @@ -318,15 +318,15 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { }, native_libraries: |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); - Lrc::new(native_libs::collect(tcx)) + Lrc::from(native_libs::collect(tcx)) }, foreign_modules: |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); - Lrc::new(foreign_modules::collect(tcx)) + Lrc::from(foreign_modules::collect(tcx)) }, link_args: |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); - Lrc::new(link_args::collect(tcx)) + Lrc::from(link_args::collect(tcx)) }, // Returns a map from a sufficiently visible external item (i.e. an @@ -359,7 +359,7 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { // which is to say, its not deterministic in general. But // we believe that libstd is consistently assigned crate // num 1, so it should be enough to resolve #46112. - let mut crates: Vec = (*tcx.crates()).clone(); + let mut crates: Vec = tcx.crates().to_vec(); crates.sort(); for &cnum in crates.iter() { diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 39de1ec852ec4..d368d0ce4cbd3 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -607,7 +607,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let data = ModData { reexports: match tcx.module_exports(def_id) { - Some(ref exports) => self.lazy_seq_from_slice(exports.as_slice()), + Some(ref exports) => self.lazy_seq_from_slice(&exports), _ => LazySeq::empty(), }, }; diff --git a/src/librustc_traits/lowering.rs b/src/librustc_traits/lowering.rs index 1092e826a35f9..dddb2772a5507 100644 --- a/src/librustc_traits/lowering.rs +++ b/src/librustc_traits/lowering.rs @@ -100,7 +100,7 @@ impl<'tcx> Lower> for ty::Predicate<'tcx> { } crate fn program_clauses_for<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Lrc>> + -> Lrc<[Clause<'tcx>]> { let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); let item = tcx.hir.expect_item(node_id); @@ -109,12 +109,12 @@ crate fn program_clauses_for<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI hir::ItemImpl(..) => program_clauses_for_impl(tcx, def_id), // FIXME: other constructions e.g. traits, associated types... - _ => Lrc::new(vec![]), + _ => Lrc::new([]), } } fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Lrc>> + -> Lrc<[Clause<'tcx>]> { // Rule Implemented-From-Env (see rustc guide) // @@ -140,14 +140,14 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI // `Implemented(Self: Trait) :- FromEnv(Self: Trait)` let clause = Clause::Implies(vec![from_env], impl_trait); - Lrc::new(vec![clause]) + Lrc::new([clause]) } fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Lrc>> + -> Lrc<[Clause<'tcx>]> { if let ImplPolarity::Negative = tcx.impl_polarity(def_id) { - return Lrc::new(vec![]); + return Lrc::new([]); } // Rule Implemented-From-Impl (see rustc guide) @@ -168,7 +168,7 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId // `Implemented(A0: Trait) :- WC` let clause = Clause::Implies(where_clauses, trait_pred); - Lrc::new(vec![clause]) + Lrc::new([clause]) } pub fn dump_program_clauses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { diff --git a/src/librustc_trans/attributes.rs b/src/librustc_trans/attributes.rs index c968b8525a5b1..5b2ed8bcf198d 100644 --- a/src/librustc_trans/attributes.rs +++ b/src/librustc_trans/attributes.rs @@ -188,7 +188,7 @@ pub fn provide(providers: &mut Providers) { assert_eq!(cnum, LOCAL_CRATE); let mut finder = WasmSectionFinder { tcx, list: Vec::new() }; tcx.hir.krate().visit_all_item_likes(&mut finder); - Lrc::new(finder.list) + Lrc::from(finder.list) }; provide_extern(providers); diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index e8a1eb3071a29..78f713c1539ef 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -397,17 +397,17 @@ struct CrateInfo { profiler_runtime: Option, sanitizer_runtime: Option, is_no_builtins: FxHashSet, - native_libraries: FxHashMap>>, + native_libraries: FxHashMap>, crate_name: FxHashMap, - used_libraries: Lrc>, - link_args: Lrc>, + used_libraries: Lrc<[NativeLibrary]>, + link_args: Lrc<[String]>, used_crate_source: FxHashMap>, used_crates_static: Vec<(CrateNum, LibSource)>, used_crates_dynamic: Vec<(CrateNum, LibSource)>, wasm_custom_sections: BTreeMap>, wasm_imports: FxHashMap, lang_item_to_crate: FxHashMap, - missing_lang_items: FxHashMap>>, + missing_lang_items: FxHashMap>, } __build_diagnostic_array! { librustc_trans, DIAGNOSTICS } diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index fd2b964103a30..252ef0c2302a4 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -54,7 +54,7 @@ fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) } fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId) - -> Lrc> { + -> Lrc<[ty::Variance]> { let id = tcx.hir.as_local_node_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index 340a7b1d08ede..ef9a1d63b4575 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -51,7 +51,7 @@ pub fn solve_constraints(constraints_cx: ConstraintContext) -> ty::CrateVariance }; solutions_cx.solve(); let variances = solutions_cx.create_map(); - let empty_variance = Lrc::new(Vec::new()); + let empty_variance = Lrc::new([]); ty::CrateVariancesMap { variances, empty_variance } } @@ -88,7 +88,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { } } - fn create_map(&self) -> FxHashMap>> { + fn create_map(&self) -> FxHashMap> { let tcx = self.terms_cx.tcx; let solutions = &self.solutions; @@ -109,7 +109,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { } } - (def_id, Lrc::new(variances)) + (def_id, Lrc::from(variances)) }).collect() } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e3ba482eecfee..09ee4d5a35ca5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -4079,7 +4079,7 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option { None => return None, }; - for item in mem::replace(&mut items, Lrc::new(vec![])).iter() { + for item in mem::replace(&mut items, Lrc::new([])).iter() { if item.ident.name == *segment { if path_it.peek().is_none() { return match item.def { diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 10da98291ad73..ff0d22cd2870a 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -24,6 +24,7 @@ use util::small_vector::SmallVector; use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; +use rustc_data_structures::sync::Lrc; // These macros all relate to the file system; they either return // the column/row/filename of the expression, or they include