Skip to content

Commit 7100b31

Browse files
committed
Auto merge of #86749 - bjorn3:link_info_refactor_part1, r=petrochenkov
Rename all_crate_nums query to crates and remove useless wrapper Split out of #86105 r? `@petrochenkov`
2 parents ecef52a + c7d2099 commit 7100b31

File tree

21 files changed

+27
-31
lines changed

21 files changed

+27
-31
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ fn upstream_monomorphizations_provider(
277277
tcx: TyCtxt<'_>,
278278
(): (),
279279
) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> {
280-
let cnums = tcx.all_crate_nums(());
280+
let cnums = tcx.crates(());
281281

282282
let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();
283283

compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
994994
}
995995
Lto::Fat | Lto::Thin => {
996996
exported_symbols.insert(LOCAL_CRATE, copy_symbols(LOCAL_CRATE));
997-
for &cnum in tcx.crates().iter() {
997+
for &cnum in tcx.crates(()).iter() {
998998
exported_symbols.insert(cnum, copy_symbols(cnum));
999999
}
10001000
Some(Arc::new(exported_symbols))

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ impl CrateInfo {
789789
};
790790
let lang_items = tcx.lang_items();
791791

792-
let crates = tcx.crates();
792+
let crates = tcx.crates(());
793793

794794
let n_crates = crates.len();
795795
info.native_libraries.reserve(n_crates);

compiler/rustc_metadata/src/dependency_format.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
129129
&& sess.crt_static(Some(ty))
130130
&& !sess.target.crt_static_allows_dylibs)
131131
{
132-
for &cnum in tcx.crates().iter() {
132+
for &cnum in tcx.crates(()).iter() {
133133
if tcx.dep_kind(cnum).macros_only() {
134134
continue;
135135
}
@@ -152,7 +152,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
152152
// Sweep all crates for found dylibs. Add all dylibs, as well as their
153153
// dependencies, ensuring there are no conflicts. The only valid case for a
154154
// dependency to be relied upon twice is for both cases to rely on a dylib.
155-
for &cnum in tcx.crates().iter() {
155+
for &cnum in tcx.crates(()).iter() {
156156
if tcx.dep_kind(cnum).macros_only() {
157157
continue;
158158
}
@@ -170,7 +170,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
170170
}
171171

172172
// Collect what we've got so far in the return vector.
173-
let last_crate = tcx.crates().len();
173+
let last_crate = tcx.crates(()).len();
174174
let mut ret = (1..last_crate + 1)
175175
.map(|cnum| match formats.get(&CrateNum::new(cnum)) {
176176
Some(&RequireDynamic) => Linkage::Dynamic,
@@ -184,7 +184,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
184184
//
185185
// If the crate hasn't been included yet and it's not actually required
186186
// (e.g., it's an allocator) then we skip it here as well.
187-
for &cnum in tcx.crates().iter() {
187+
for &cnum in tcx.crates(()).iter() {
188188
let src = tcx.used_crate_source(cnum);
189189
if src.dylib.is_none()
190190
&& !formats.contains_key(&cnum)
@@ -281,7 +281,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
281281

282282
// All crates are available in an rlib format, so we're just going to link
283283
// everything in explicitly so long as it's actually required.
284-
let last_crate = tcx.crates().len();
284+
let last_crate = tcx.crates(()).len();
285285
let mut ret = (1..last_crate + 1)
286286
.map(|cnum| {
287287
if tcx.dep_kind(CrateNum::new(cnum)) == CrateDepKind::Explicit {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub fn provide(providers: &mut Providers) {
312312
// which is to say, its not deterministic in general. But
313313
// we believe that libstd is consistently assigned crate
314314
// num 1, so it should be enough to resolve #46112.
315-
let mut crates: Vec<CrateNum> = (*tcx.crates()).to_owned();
315+
let mut crates: Vec<CrateNum> = (*tcx.crates(())).to_owned();
316316
crates.sort();
317317

318318
for &cnum in crates.iter() {

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ impl EncodeContext<'a, 'tcx> {
16731673

16741674
fn encode_crate_deps(&mut self) -> Lazy<[CrateDep]> {
16751675
empty_proc_macro!(self);
1676-
let crates = self.tcx.crates();
1676+
let crates = self.tcx.crates(());
16771677

16781678
let mut deps = crates
16791679
.iter()

compiler/rustc_middle/src/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
229229
// positions.
230230
pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> {
231231
let mut libs = tcx
232-
.crates()
232+
.crates(())
233233
.iter()
234234
.cloned()
235235
.filter_map(|cnum| {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ rustc_queries! {
14441444
eval_always
14451445
desc { "calculating the stability index for the local crate" }
14461446
}
1447-
query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
1447+
query crates(_: ()) -> &'tcx [CrateNum] {
14481448
eval_always
14491449
desc { "fetching all foreign CrateNum instances" }
14501450
}

compiler/rustc_middle/src/ty/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,6 @@ impl<'tcx> TyCtxt<'tcx> {
12671267
self.stability_index(())
12681268
}
12691269

1270-
pub fn crates(self) -> &'tcx [CrateNum] {
1271-
self.all_crate_nums(())
1272-
}
1273-
12741270
pub fn features(self) -> &'tcx rustc_feature::Features {
12751271
self.features_query(())
12761272
}
@@ -2827,7 +2823,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
28272823
tcx.stability().local_deprecation_entry(id)
28282824
};
28292825
providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned();
2830-
providers.all_crate_nums = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
2826+
providers.crates = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
28312827
providers.output_filenames = |tcx, ()| tcx.output_filenames.clone();
28322828
providers.features_query = |tcx, ()| tcx.sess.features_untracked();
28332829
providers.is_panic_runtime = |tcx, cnum| {

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
22482248
let queue = &mut Vec::new();
22492249
let mut seen_defs: DefIdSet = Default::default();
22502250

2251-
for &cnum in tcx.crates().iter() {
2251+
for &cnum in tcx.crates(()).iter() {
22522252
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
22532253

22542254
// Ignore crates that are not direct dependencies.

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'sess> OnDiskCache<'sess> {
558558
// maps to None.
559559
fn compute_cnum_map(tcx: TyCtxt<'_>) -> UnhashMap<StableCrateId, CrateNum> {
560560
tcx.dep_graph.with_ignore(|| {
561-
tcx.all_crate_nums(())
561+
tcx.crates(())
562562
.iter()
563563
.chain(std::iter::once(&LOCAL_CRATE))
564564
.map(|&cnum| {

compiler/rustc_middle/src/ty/trait_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
215215
// Traits defined in the current crate can't have impls in upstream
216216
// crates, so we don't bother querying the cstore.
217217
if !trait_id.is_local() {
218-
for &cnum in tcx.crates().iter() {
218+
for &cnum in tcx.crates(()).iter() {
219219
for &(impl_def_id, simplified_self_ty) in
220220
tcx.implementations_of_trait((cnum, trait_id)).iter()
221221
{

compiler/rustc_passes/src/diagnostic_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn all_diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashMap<Symbol, De
121121
let mut collector = FxHashMap::default();
122122

123123
// Collect diagnostic items in other crates.
124-
for &cnum in tcx.crates().iter().chain(std::iter::once(&LOCAL_CRATE)) {
124+
for &cnum in tcx.crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
125125
for (&name, &def_id) in tcx.diagnostic_items(cnum).iter() {
126126
collect_item(tcx, &mut collector, name, def_id);
127127
}

compiler/rustc_passes/src/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
309309
let mut collector = LanguageItemCollector::new(tcx);
310310

311311
// Collect lang items in other crates.
312-
for &cnum in tcx.crates().iter() {
312+
for &cnum in tcx.crates(()).iter() {
313313
for &(def_id, item_index) in tcx.defined_lang_items(cnum).iter() {
314314
collector.collect_item(item_index, def_id);
315315
}

compiler/rustc_passes/src/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
938938
if !remaining_lib_features.is_empty() {
939939
check_features(&mut remaining_lib_features, &local_defined_features);
940940

941-
for &cnum in tcx.crates() {
941+
for &cnum in tcx.crates(()) {
942942
if remaining_lib_features.is_empty() {
943943
break;
944944
}

compiler/rustc_passes/src/weak_lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
5353
}
5454

5555
let mut missing = FxHashSet::default();
56-
for &cnum in tcx.crates().iter() {
56+
for &cnum in tcx.crates(()).iter() {
5757
for &item in tcx.missing_lang_items(cnum).iter() {
5858
missing.insert(item);
5959
}

compiler/rustc_save_analysis/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ impl<'tcx> SaveContext<'tcx> {
109109

110110
// List external crates used by the current crate.
111111
pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
112-
let mut result = Vec::with_capacity(self.tcx.crates().len());
112+
let mut result = Vec::with_capacity(self.tcx.crates(()).len());
113113

114-
for &n in self.tcx.crates().iter() {
114+
for &n in self.tcx.crates(()).iter() {
115115
let span = match self.tcx.extern_crate(n.as_def_id()) {
116116
Some(&ExternCrate { span, .. }) => span,
117117
None => {

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>, (): ()) -> &[DefId] {
15911591
_ => {}
15921592
}
15931593
}
1594-
for &cnum in tcx.crates().iter() {
1594+
for &cnum in tcx.crates(()).iter() {
15951595
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
15961596
handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id));
15971597
}

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
3030
cx.cache.owned_box_did = cx.tcx.lang_items().owned_box();
3131

3232
let mut externs = Vec::new();
33-
for &cnum in cx.tcx.crates().iter() {
33+
for &cnum in cx.tcx.crates(()).iter() {
3434
externs.push((cnum, cnum.clean(cx)));
3535
// Analyze doc-reachability for extern items
3636
LibEmbargoVisitor::new(cx).visit_lib(cnum);

src/librustdoc/passes/collect_trait_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
2929

3030
let mut new_items = Vec::new();
3131

32-
for &cnum in cx.tcx.crates().iter() {
32+
for &cnum in cx.tcx.crates(()).iter() {
3333
for &(did, _) in cx.tcx.all_trait_implementations(cnum).iter() {
3434
cx.tcx.sess.prof.generic_activity("build_extern_trait_impl").run(|| {
3535
inline::build_impl(cx, None, did, None, &mut new_items);
@@ -85,7 +85,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
8585
}
8686
});
8787

88-
// `tcx.crates()` doesn't include the local crate, and `tcx.all_trait_implementations`
88+
// `tcx.crates(())` doesn't include the local crate, and `tcx.all_trait_implementations`
8989
// doesn't work with it anyway, so pull them from the HIR map instead
9090
let mut extra_attrs = Vec::new();
9191
for &trait_did in cx.tcx.all_traits(()).iter() {

src/tools/clippy/clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub fn path_to_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
493493
_ => return Res::Err,
494494
};
495495
let tcx = cx.tcx;
496-
let crates = tcx.crates();
496+
let crates = tcx.crates(());
497497
let krate = try_res!(crates.iter().find(|&&num| tcx.crate_name(num).as_str() == krate));
498498
let first = try_res!(item_child_by_name(tcx, krate.as_def_id(), first));
499499
let last = path

0 commit comments

Comments
 (0)