Skip to content

Commit 437a46d

Browse files
committed
Use () for lang items.
1 parent 9849327 commit 437a46d

File tree

8 files changed

+30
-53
lines changed

8 files changed

+30
-53
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn upstream_monomorphizations_provider(
279279
) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> {
280280
debug_assert!(cnum == LOCAL_CRATE);
281281

282-
let cnums = tcx.all_crate_nums(LOCAL_CRATE);
282+
let cnums = tcx.all_crate_nums(());
283283

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

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ rustc_queries! {
13301330
desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
13311331
}
13321332

1333-
query get_lib_features(_: CrateNum) -> LibFeatures {
1333+
query get_lib_features(_: ()) -> LibFeatures {
13341334
storage(ArenaCacheSelector<'tcx>)
13351335
eval_always
13361336
desc { "calculating the lib features map" }
@@ -1340,16 +1340,14 @@ rustc_queries! {
13401340
desc { "calculating the lib features defined in a crate" }
13411341
}
13421342
/// Returns the lang items defined in another crate by loading it from metadata.
1343-
// FIXME: It is illegal to pass a `CrateNum` other than `LOCAL_CRATE` here, just get rid
1344-
// of that argument?
1345-
query get_lang_items(_: CrateNum) -> LanguageItems {
1343+
query get_lang_items(_: ()) -> LanguageItems {
13461344
storage(ArenaCacheSelector<'tcx>)
13471345
eval_always
13481346
desc { "calculating the lang items map" }
13491347
}
13501348

13511349
/// Returns all diagnostic items defined in all crates.
1352-
query all_diagnostic_items(_: CrateNum) -> FxHashMap<Symbol, DefId> {
1350+
query all_diagnostic_items(_: ()) -> FxHashMap<Symbol, DefId> {
13531351
storage(ArenaCacheSelector<'tcx>)
13541352
eval_always
13551353
desc { "calculating the diagnostic items map" }
@@ -1411,12 +1409,12 @@ rustc_queries! {
14111409
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
14121410
}
14131411

1414-
query stability_index(_: CrateNum) -> stability::Index<'tcx> {
1412+
query stability_index(_: ()) -> stability::Index<'tcx> {
14151413
storage(ArenaCacheSelector<'tcx>)
14161414
eval_always
14171415
desc { "calculating the stability index for the local crate" }
14181416
}
1419-
query all_crate_nums(_: CrateNum) -> &'tcx [CrateNum] {
1417+
query all_crate_nums(_: ()) -> &'tcx [CrateNum] {
14201418
eval_always
14211419
desc { "fetching all foreign CrateNum instances" }
14221420
}
@@ -1644,7 +1642,7 @@ rustc_queries! {
16441642
desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
16451643
}
16461644

1647-
query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
1645+
query features_query(_: ()) -> &'tcx rustc_feature::Features {
16481646
eval_always
16491647
desc { "looking up enabled feature gates" }
16501648
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,18 +1218,18 @@ impl<'tcx> TyCtxt<'tcx> {
12181218
}
12191219

12201220
pub fn lib_features(self) -> &'tcx middle::lib_features::LibFeatures {
1221-
self.get_lib_features(LOCAL_CRATE)
1221+
self.get_lib_features(())
12221222
}
12231223

12241224
/// Obtain all lang items of this crate and all dependencies (recursively)
12251225
pub fn lang_items(self) -> &'tcx rustc_hir::lang_items::LanguageItems {
1226-
self.get_lang_items(LOCAL_CRATE)
1226+
self.get_lang_items(())
12271227
}
12281228

12291229
/// Obtain the given diagnostic item's `DefId`. Use `is_diagnostic_item` if you just want to
12301230
/// compare against another `DefId`, since `is_diagnostic_item` is cheaper.
12311231
pub fn get_diagnostic_item(self, name: Symbol) -> Option<DefId> {
1232-
self.all_diagnostic_items(LOCAL_CRATE).get(&name).copied()
1232+
self.all_diagnostic_items(()).get(&name).copied()
12331233
}
12341234

12351235
/// Check whether the diagnostic item with the given `name` has the given `DefId`.
@@ -1238,19 +1238,19 @@ impl<'tcx> TyCtxt<'tcx> {
12381238
}
12391239

12401240
pub fn stability(self) -> &'tcx stability::Index<'tcx> {
1241-
self.stability_index(LOCAL_CRATE)
1241+
self.stability_index(())
12421242
}
12431243

12441244
pub fn crates(self) -> &'tcx [CrateNum] {
1245-
self.all_crate_nums(LOCAL_CRATE)
1245+
self.all_crate_nums(())
12461246
}
12471247

12481248
pub fn allocator_kind(self) -> Option<AllocatorKind> {
12491249
self.cstore.allocator_kind()
12501250
}
12511251

12521252
pub fn features(self) -> &'tcx rustc_feature::Features {
1253-
self.features_query(LOCAL_CRATE)
1253+
self.features_query(())
12541254
}
12551255

12561256
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
@@ -2815,18 +2815,12 @@ pub fn provide(providers: &mut ty::query::Providers) {
28152815
tcx.stability().local_deprecation_entry(id)
28162816
};
28172817
providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned();
2818-
providers.all_crate_nums = |tcx, cnum| {
2819-
assert_eq!(cnum, LOCAL_CRATE);
2820-
tcx.arena.alloc_slice(&tcx.cstore.crates_untracked())
2821-
};
2818+
providers.all_crate_nums = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
28222819
providers.output_filenames = |tcx, cnum| {
28232820
assert_eq!(cnum, LOCAL_CRATE);
28242821
tcx.output_filenames.clone()
28252822
};
2826-
providers.features_query = |tcx, cnum| {
2827-
assert_eq!(cnum, LOCAL_CRATE);
2828-
tcx.sess.features_untracked()
2829-
};
2823+
providers.features_query = |tcx, ()| tcx.sess.features_untracked();
28302824
providers.is_panic_runtime = |tcx, cnum| {
28312825
assert_eq!(cnum, LOCAL_CRATE);
28322826
tcx.sess.contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ impl<'sess> OnDiskCache<'sess> {
579579
) -> IndexVec<CrateNum, Option<CrateNum>> {
580580
tcx.dep_graph.with_ignore(|| {
581581
let current_cnums = tcx
582-
.all_crate_nums(LOCAL_CRATE)
582+
.all_crate_nums(())
583583
.iter()
584584
.map(|&cnum| {
585585
let crate_name = tcx.original_crate_name(cnum).to_string();

compiler/rustc_passes/src/diagnostic_items.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
1616
use rustc_middle::ty::query::Providers;
1717
use rustc_middle::ty::TyCtxt;
1818
use rustc_session::Session;
19-
use rustc_span::def_id::{DefId, LocalDefId, LOCAL_CRATE};
19+
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
2020
use rustc_span::symbol::{sym, Symbol};
2121

2222
struct DiagnosticItemCollector<'tcx> {
@@ -99,7 +99,9 @@ fn extract(sess: &Session, attrs: &[ast::Attribute]) -> Option<Symbol> {
9999
}
100100

101101
/// Traverse and collect the diagnostic items in the current
102-
fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
102+
fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> FxHashMap<Symbol, DefId> {
103+
assert_eq!(cnum, LOCAL_CRATE);
104+
103105
// Initialize the collector.
104106
let mut collector = DiagnosticItemCollector::new(tcx);
105107

@@ -114,7 +116,7 @@ fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
114116
}
115117

116118
/// Traverse and collect all the diagnostic items in all crates.
117-
fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
119+
fn all_diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashMap<Symbol, DefId> {
118120
// Initialize the collector.
119121
let mut collector = FxHashMap::default();
120122

@@ -129,12 +131,6 @@ fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> FxHashMap<Symbol, DefId> {
129131
}
130132

131133
pub fn provide(providers: &mut Providers) {
132-
providers.diagnostic_items = |tcx, id| {
133-
assert_eq!(id, LOCAL_CRATE);
134-
collect(tcx)
135-
};
136-
providers.all_diagnostic_items = |tcx, id| {
137-
assert_eq!(id, LOCAL_CRATE);
138-
collect_all(tcx)
139-
};
134+
providers.diagnostic_items = diagnostic_items;
135+
providers.all_diagnostic_items = all_diagnostic_items;
140136
}

compiler/rustc_passes/src/lang_items.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::TyCtxt;
1515

1616
use rustc_errors::struct_span_err;
1717
use rustc_hir as hir;
18-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
18+
use rustc_hir::def_id::DefId;
1919
use rustc_hir::itemlikevisit::ItemLikeVisitor;
2020
use rustc_hir::lang_items::{extract, ITEM_REFS};
2121
use rustc_hir::{HirId, LangItem, LanguageItems, Target};
@@ -183,7 +183,7 @@ impl LanguageItemCollector<'tcx> {
183183
}
184184

185185
/// Traverses and collects all the lang items in all crates.
186-
fn collect(tcx: TyCtxt<'_>) -> LanguageItems {
186+
fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
187187
// Initialize the collector.
188188
let mut collector = LanguageItemCollector::new(tcx);
189189

@@ -207,8 +207,5 @@ fn collect(tcx: TyCtxt<'_>) -> LanguageItems {
207207
}
208208

209209
pub fn provide(providers: &mut Providers) {
210-
providers.get_lang_items = |tcx, id| {
211-
assert_eq!(id, LOCAL_CRATE);
212-
collect(tcx)
213-
};
210+
providers.get_lang_items = get_lang_items;
214211
}

compiler/rustc_passes/src/lib_features.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use rustc_ast::{Attribute, MetaItem, MetaItemKind};
88
use rustc_errors::struct_span_err;
9-
use rustc_hir::def_id::LOCAL_CRATE;
109
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1110
use rustc_middle::hir::map::Map;
1211
use rustc_middle::middle::lib_features::LibFeatures;
@@ -127,7 +126,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
127126
}
128127
}
129128

130-
fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
129+
fn get_lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures {
131130
let mut collector = LibFeatureCollector::new(tcx);
132131
let krate = tcx.hir().krate();
133132
for attr in krate.non_exported_macro_attrs {
@@ -138,8 +137,5 @@ fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
138137
}
139138

140139
pub fn provide(providers: &mut Providers) {
141-
providers.get_lib_features = |tcx, id| {
142-
assert_eq!(id, LOCAL_CRATE);
143-
collect(tcx)
144-
};
140+
providers.get_lib_features = get_lib_features;
145141
}

compiler/rustc_passes/src/stability.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
629629
// stable (assuming they have not inherited instability from their parent).
630630
}
631631

632-
fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
632+
fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
633633
let is_staged_api =
634634
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
635635
let mut staged_api = FxHashMap::default();
@@ -704,11 +704,7 @@ fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
704704
}
705705

706706
pub(crate) fn provide(providers: &mut Providers) {
707-
*providers = Providers { check_mod_unstable_api_usage, ..*providers };
708-
providers.stability_index = |tcx, cnum| {
709-
assert_eq!(cnum, LOCAL_CRATE);
710-
new_index(tcx)
711-
};
707+
*providers = Providers { check_mod_unstable_api_usage, stability_index, ..*providers };
712708
}
713709

714710
struct Checker<'tcx> {

0 commit comments

Comments
 (0)