Skip to content

Commit 14e7974

Browse files
committed
Use Lrc<[T]> instead of Lrc<Vec<T>> 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.
1 parent 30b5d76 commit 14e7974

File tree

15 files changed

+76
-76
lines changed

15 files changed

+76
-76
lines changed

src/librustc/middle/cstore.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,9 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
399399
Some((cnum, path))
400400
})
401401
.collect::<Vec<_>>();
402-
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
403-
Lrc::make_mut(&mut ordering).reverse();
402+
let ordering = tcx.postorder_cnums(LOCAL_CRATE);
404403
libs.sort_by_key(|&(a, _)| {
405-
ordering.iter().position(|x| *x == a)
404+
ordering.iter().rev().position(|x| *x == a)
406405
});
407406
libs
408407
}

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub struct ResolveLifetimes {
217217
defs: FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Region>>>,
218218
late_bound: FxHashMap<LocalDefId, Lrc<FxHashSet<ItemLocalId>>>,
219219
object_lifetime_defaults:
220-
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
220+
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<[ObjectLifetimeDefault]>>>>,
221221
}
222222

223223
impl_stable_hash_for!(struct ::middle::resolve_lifetime::ResolveLifetimes {
@@ -406,7 +406,7 @@ fn resolve_lifetimes<'tcx>(
406406
.or_insert_with(|| Lrc::new(FxHashMap()));
407407
Lrc::get_mut(map)
408408
.unwrap()
409-
.insert(hir_id.local_id, Lrc::new(v));
409+
.insert(hir_id.local_id, Lrc::from(v));
410410
}
411411

412412
Lrc::new(ResolveLifetimes {

src/librustc/traits/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,11 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
824824
fn vtable_methods<'a, 'tcx>(
825825
tcx: TyCtxt<'a, 'tcx, 'tcx>,
826826
trait_ref: ty::PolyTraitRef<'tcx>)
827-
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
827+
-> Lrc<[Option<(DefId, &'tcx Substs<'tcx>)>]>
828828
{
829829
debug!("vtable_methods({:?})", trait_ref);
830830

831-
Lrc::new(
831+
Lrc::from(
832832
supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
833833
let trait_methods = tcx.associated_items(trait_ref.def_id())
834834
.filter(|item| item.kind == ty::AssociatedKind::Method);
@@ -871,7 +871,7 @@ fn vtable_methods<'a, 'tcx>(
871871

872872
Some((def_id, substs))
873873
})
874-
}).collect()
874+
}).collect::<Vec<_>>()
875875
)
876876
}
877877

src/librustc/ty/context.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ pub struct GlobalCtxt<'tcx> {
847847
Lrc<StableVec<TraitCandidate>>>>>,
848848

849849
/// Export map produced by name resolution.
850-
export_map: FxHashMap<DefId, Lrc<Vec<Export>>>,
850+
export_map: FxHashMap<DefId, Lrc<[Export]>>,
851851

852852
pub hir: hir_map::Map<'tcx>,
853853

@@ -860,7 +860,7 @@ pub struct GlobalCtxt<'tcx> {
860860
// Records the free variables refrenced by every closure
861861
// expression. Do not track deps for this, just recompute it from
862862
// scratch every time.
863-
freevars: FxHashMap<DefId, Lrc<Vec<hir::Freevar>>>,
863+
freevars: FxHashMap<DefId, Lrc<[hir::Freevar]>>,
864864

865865
maybe_unused_trait_imports: FxHashSet<DefId>,
866866

@@ -1255,10 +1255,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12551255
types: common_types,
12561256
trait_map,
12571257
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
1258-
(k, Lrc::new(v))
1258+
(k, Lrc::from(v))
12591259
}).collect(),
12601260
freevars: resolutions.freevars.into_iter().map(|(k, v)| {
1261-
(hir.local_def_id(k), Lrc::new(v))
1261+
(hir.local_def_id(k), Lrc::from(v))
12621262
}).collect(),
12631263
maybe_unused_trait_imports:
12641264
resolutions.maybe_unused_trait_imports
@@ -1338,7 +1338,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13381338
self.stability_index(LOCAL_CRATE)
13391339
}
13401340

1341-
pub fn crates(self) -> Lrc<Vec<CrateNum>> {
1341+
pub fn crates(self) -> Lrc<[CrateNum]> {
13421342
self.all_crate_nums(LOCAL_CRATE)
13431343
}
13441344

@@ -2617,7 +2617,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26172617
}
26182618

26192619
pub fn object_lifetime_defaults(self, id: HirId)
2620-
-> Option<Lrc<Vec<ObjectLifetimeDefault>>>
2620+
-> Option<Lrc<[ObjectLifetimeDefault]>>
26212621
{
26222622
self.object_lifetime_defaults_map(id.owner)
26232623
.and_then(|map| map.get(&id.local_id).cloned())
@@ -2696,7 +2696,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
26962696
};
26972697
providers.maybe_unused_extern_crates = |tcx, cnum| {
26982698
assert_eq!(cnum, LOCAL_CRATE);
2699-
Lrc::new(tcx.maybe_unused_extern_crates.clone())
2699+
Lrc::from(tcx.maybe_unused_extern_crates.clone())
27002700
};
27012701

27022702
providers.stability_index = |tcx, cnum| {
@@ -2719,11 +2719,11 @@ pub fn provide(providers: &mut ty::maps::Providers) {
27192719
};
27202720
providers.all_crate_nums = |tcx, cnum| {
27212721
assert_eq!(cnum, LOCAL_CRATE);
2722-
Lrc::new(tcx.cstore.crates_untracked())
2722+
Lrc::from(tcx.cstore.crates_untracked())
27232723
};
27242724
providers.postorder_cnums = |tcx, cnum| {
27252725
assert_eq!(cnum, LOCAL_CRATE);
2726-
Lrc::new(tcx.cstore.postorder_cnums_untracked())
2726+
Lrc::from(tcx.cstore.postorder_cnums_untracked())
27272727
};
27282728
providers.output_filenames = |tcx, cnum| {
27292729
assert_eq!(cnum, LOCAL_CRATE);

src/librustc/ty/maps/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ define_maps! { <'tcx>
136136

137137
/// Maps from def-id of a type or region parameter to its
138138
/// (inferred) variance.
139-
[] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
139+
[] fn variances_of: ItemVariances(DefId) -> Lrc<[ty::Variance]>,
140140

141141
/// Maps from def-id of a type to its (inferred) outlives.
142142
[] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Vec<ty::Predicate<'tcx>>,
143143

144144
/// Maps from an impl/trait def-id to a list of the def-ids of its items
145-
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
145+
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<[DefId]>,
146146

147147
/// Maps from a trait item to the trait item "descriptor"
148148
[] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
@@ -256,7 +256,7 @@ define_maps! { <'tcx>
256256
[] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
257257
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
258258
[] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
259-
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
259+
-> Lrc<[Option<(DefId, &'tcx Substs<'tcx>)>]>,
260260

261261
[] fn trans_fulfill_obligation: fulfill_obligation_dep_node(
262262
(ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
@@ -283,7 +283,7 @@ define_maps! { <'tcx>
283283
ty::layout::LayoutError<'tcx>>,
284284

285285
[] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
286-
-> Lrc<Vec<(CrateNum, LinkagePreference)>>,
286+
-> Lrc<[(CrateNum, LinkagePreference)]>,
287287

288288
[fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
289289
[fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
@@ -298,7 +298,7 @@ define_maps! { <'tcx>
298298
[] fn specializes: specializes_node((DefId, DefId)) -> bool,
299299
[] fn in_scope_traits_map: InScopeTraits(DefIndex)
300300
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
301-
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
301+
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<[Export]>>,
302302
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
303303

304304
[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
@@ -329,9 +329,9 @@ define_maps! { <'tcx>
329329
[] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
330330
-> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,
331331

332-
[] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
332+
[] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<[NativeLibrary]>,
333333

334-
[] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
334+
[] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<[ForeignModule]>,
335335

336336
[] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
337337
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
@@ -341,17 +341,17 @@ define_maps! { <'tcx>
341341
[] fn extra_filename: ExtraFileName(CrateNum) -> String,
342342

343343
[] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
344-
-> Lrc<Vec<DefId>>,
344+
-> Lrc<[DefId]>,
345345
[] fn all_trait_implementations: AllTraitImplementations(CrateNum)
346-
-> Lrc<Vec<DefId>>,
346+
-> Lrc<[DefId]>,
347347

348348
[] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
349349
-> Lrc<FxHashSet<DefId>>,
350350
[] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
351351
[] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
352352
[] fn native_library_kind: NativeLibraryKind(DefId)
353353
-> Option<NativeLibraryKind>,
354-
[] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
354+
[] fn link_args: link_args_node(CrateNum) -> Lrc<[String]>,
355355

356356
// Lifetime resolution. See `middle::resolve_lifetimes`.
357357
[] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
@@ -360,31 +360,31 @@ define_maps! { <'tcx>
360360
[] fn is_late_bound_map: IsLateBound(DefIndex) ->
361361
Option<Lrc<FxHashSet<ItemLocalId>>>,
362362
[] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
363-
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
363+
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<[ObjectLifetimeDefault]>>>>,
364364

365365
[] fn visibility: Visibility(DefId) -> ty::Visibility,
366366
[] fn dep_kind: DepKind(CrateNum) -> DepKind,
367367
[] fn crate_name: CrateName(CrateNum) -> Symbol,
368-
[] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
368+
[] fn item_children: ItemChildren(DefId) -> Lrc<[Export]>,
369369
[] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,
370370

371371
[] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
372-
[] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
373-
[] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
372+
[] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<[(DefId, usize)]>,
373+
[] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<[LangItem]>,
374374
[] fn extern_const_body: ExternConstBody(DefId) -> ExternConstBody<'tcx>,
375375
[] fn visible_parent_map: visible_parent_map_node(CrateNum)
376376
-> Lrc<DefIdMap<DefId>>,
377377
[] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
378378
[] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
379-
[] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
379+
[] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<[CrateNum]>,
380380

381-
[] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
381+
[] fn freevars: Freevars(DefId) -> Option<Lrc<[hir::Freevar]>>,
382382
[] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
383383
[] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
384-
-> Lrc<Vec<(DefId, Span)>>,
384+
-> Lrc<[(DefId, Span)]>,
385385

386386
[] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
387-
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
387+
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<[CrateNum]>,
388388

389389
[] fn exported_symbols: ExportedSymbols(CrateNum)
390390
-> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>>,
@@ -435,9 +435,9 @@ define_maps! { <'tcx>
435435

436436
[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
437437

438-
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<Vec<Clause<'tcx>>>,
438+
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<[Clause<'tcx>]>,
439439

440-
[] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<Vec<DefId>>,
440+
[] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<[DefId]>,
441441
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
442442
-> Lrc<FxHashMap<DefId, String>>,
443443
}

src/librustc/ty/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ pub struct CrateVariancesMap {
337337
/// For each item with generics, maps to a vector of the variance
338338
/// of its generics. If an item has no generics, it will have no
339339
/// entry.
340-
pub variances: FxHashMap<DefId, Lrc<Vec<ty::Variance>>>,
340+
pub variances: FxHashMap<DefId, Lrc<[ty::Variance]>>,
341341

342342
/// An empty vector, useful for cloning.
343-
pub empty_variance: Lrc<Vec<ty::Variance>>,
343+
pub empty_variance: Lrc<[ty::Variance]>,
344344
}
345345

346346
impl Variance {
@@ -2641,7 +2641,7 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26412641

26422642
fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26432643
def_id: DefId)
2644-
-> Lrc<Vec<DefId>> {
2644+
-> Lrc<[DefId]> {
26452645
let id = tcx.hir.as_local_node_id(def_id).unwrap();
26462646
let item = tcx.hir.expect_item(id);
26472647
let vec: Vec<_> = match item.node {
@@ -2660,7 +2660,7 @@ fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26602660
hir::ItemTraitAlias(..) => vec![],
26612661
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
26622662
};
2663-
Lrc::new(vec)
2663+
Lrc::from(vec)
26642664
}
26652665

26662666
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) {
27722772
/// (constructing this map requires touching the entire crate).
27732773
#[derive(Clone, Debug)]
27742774
pub struct CrateInherentImpls {
2775+
// Note: needs to be a Lrc<Vec<DefId>> since get_mut().push() is used
27752776
pub inherent_impls: DefIdMap<Lrc<Vec<DefId>>>,
27762777
}
27772778

src/librustc/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
131131
}
132132

133133
pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
134-
variances: Option<&Vec<ty::Variance>>,
134+
variances: Option<&[ty::Variance]>,
135135
a_subst: &'tcx Substs<'tcx>,
136136
b_subst: &'tcx Substs<'tcx>)
137137
-> RelateResult<'tcx, &'tcx Substs<'tcx>>

0 commit comments

Comments
 (0)